From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository. --- libgo/runtime/go-rune.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 libgo/runtime/go-rune.c (limited to 'libgo/runtime/go-rune.c') diff --git a/libgo/runtime/go-rune.c b/libgo/runtime/go-rune.c new file mode 100644 index 000000000..7e31eb8d6 --- /dev/null +++ b/libgo/runtime/go-rune.c @@ -0,0 +1,77 @@ +/* go-rune.c -- rune functions for Go. + + Copyright 2009, 2010 The Go Authors. All rights reserved. + Use of this source code is governed by a BSD-style + license that can be found in the LICENSE file. */ + +#include + +#include "go-string.h" + +/* Get a character from the UTF-8 string STR, of length LEN. Store + the Unicode character, if any, in *RUNE. Return the number of + characters used from STR. */ + +int +__go_get_rune (const unsigned char *str, size_t len, int *rune) +{ + int c, c1, c2, c3; + + /* Default to the "replacement character". */ + *rune = 0xfffd; + + if (len <= 0) + return 1; + + c = *str; + if (c <= 0x7f) + { + *rune = c; + return 1; + } + + if (len <= 1) + return 1; + + c1 = str[1]; + if ((c & 0xe0) == 0xc0 + && (c1 & 0xc0) == 0x80) + { + *rune = (((c & 0x1f) << 6) + + (c1 & 0x3f)); + return 2; + } + + if (len <= 2) + return 1; + + c2 = str[2]; + if ((c & 0xf0) == 0xe0 + && (c1 & 0xc0) == 0x80 + && (c2 & 0xc0) == 0x80) + { + *rune = (((c & 0xf) << 12) + + ((c1 & 0x3f) << 6) + + (c2 & 0x3f)); + return 3; + } + + if (len <= 3) + return 1; + + c3 = str[3]; + if ((c & 0xf8) == 0xf0 + && (c1 & 0xc0) == 0x80 + && (c2 & 0xc0) == 0x80 + && (c3 & 0xc0) == 0x80) + { + *rune = (((c & 0x7) << 18) + + ((c1 & 0x3f) << 12) + + ((c2 & 0x3f) << 6) + + (c3 & 0x3f)); + return 4; + } + + /* Invalid encoding. Return 1 so that we advance. */ + return 1; +} -- cgit v1.2.3