summaryrefslogtreecommitdiff
path: root/libgo/runtime/go-rune.c
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2010-12-03 04:34:57 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2010-12-03 04:34:57 +0000
commite440a3286bc89368b8d3a8fd6accd47191790bf2 (patch)
tree38fe54a4f38ede5d949c915d66191f24a6fe5153 /libgo/runtime/go-rune.c
parenta641ee368e2614349084a9a7bda2ec2b0b2bc1cf (diff)
downloadgcc-e440a3286bc89368b8d3a8fd6accd47191790bf2.tar.gz
Add Go frontend, libgo library, and Go testsuite.
gcc/: * gcc.c (default_compilers): Add entry for ".go". * common.opt: Add -static-libgo as a driver option. * doc/install.texi (Configuration): Mention libgo as an option for --enable-shared. Mention go as an option for --enable-languages. * doc/invoke.texi (Overall Options): Mention .go as a file name suffix. Mention go as a -x option. * doc/frontends.texi (G++ and GCC): Mention Go as a supported language. * doc/sourcebuild.texi (Top Level): Mention libgo. * doc/standards.texi (Standards): Add section on Go language. Move references for other languages into their own section. * doc/contrib.texi (Contributors): Mention that I contributed the Go frontend. gcc/testsuite/: * lib/go.exp: New file. * lib/go-dg.exp: New file. * lib/go-torture.exp: New file. * lib/target-supports.exp (check_compile): Match // Go. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@167407 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/runtime/go-rune.c')
-rw-r--r--libgo/runtime/go-rune.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/libgo/runtime/go-rune.c b/libgo/runtime/go-rune.c
new file mode 100644
index 00000000000..7e31eb8d622
--- /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 <stddef.h>
+
+#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;
+}