1 /* go-rune.c -- rune functions for Go.
3 Copyright 2009, 2010 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
11 /* Get a character from the UTF-8 string STR, of length LEN. Store
12 the Unicode character, if any, in *RUNE. Return the number of
13 characters used from STR. */
16 __go_get_rune (const unsigned char *str
, size_t len
, int *rune
)
20 /* Default to the "replacement character". */
37 if ((c
& 0xe0) == 0xc0
38 && (c1
& 0xc0) == 0x80)
40 *rune
= (((c
& 0x1f) << 6)
49 if ((c
& 0xf0) == 0xe0
50 && (c1
& 0xc0) == 0x80
51 && (c2
& 0xc0) == 0x80)
53 *rune
= (((c
& 0xf) << 12)
63 if ((c
& 0xf8) == 0xf0
64 && (c1
& 0xc0) == 0x80
65 && (c2
& 0xc0) == 0x80
66 && (c3
& 0xc0) == 0x80)
68 *rune
= (((c
& 0x7) << 18)
75 /* Invalid encoding. Return 1 so that we advance. */