diff options
Diffstat (limited to 'src/runtime/rune.c')
-rw-r--r-- | src/runtime/rune.c | 133 |
1 files changed, 0 insertions, 133 deletions
diff --git a/src/runtime/rune.c b/src/runtime/rune.c index 5738ca364..9e731ad21 100644 --- a/src/runtime/rune.c +++ b/src/runtime/rune.c @@ -52,120 +52,6 @@ enum Runemax = 0x10FFFF, /* maximum rune value */ }; -/* - * Modified by Wei-Hwa Huang, Google Inc., on 2004-09-24 - * This is a slower but "safe" version of the old chartorune - * that works on strings that are not necessarily null-terminated. - * - * If you know for sure that your string is null-terminated, - * chartorune will be a bit faster. - * - * It is guaranteed not to attempt to access "length" - * past the incoming pointer. This is to avoid - * possible access violations. If the string appears to be - * well-formed but incomplete (i.e., to get the whole Rune - * we'd need to read past str+length) then we'll set the Rune - * to Bad and return 0. - * - * Note that if we have decoding problems for other - * reasons, we return 1 instead of 0. - */ -int32 -charntorune(int32 *rune, byte *str, int32 length) -{ - int32 c, c1, c2, c3; - int32 l; - - /* When we're not allowed to read anything */ - if(length <= 0) { - goto badlen; - } - - /* - * one character sequence (7-bit value) - * 00000-0007F => T1 - */ - c = *(byte*)str; /* cast not necessary, but kept for safety */ - if(c < Tx) { - *rune = c; - return 1; - } - - // If we can't read more than one character we must stop - if(length <= 1) { - goto badlen; - } - - /* - * two character sequence (11-bit value) - * 0080-07FF => T2 Tx - */ - c1 = *(byte*)(str+1) ^ Tx; - if(c1 & Testx) - goto bad; - if(c < T3) { - if(c < T2) - goto bad; - l = ((c << Bitx) | c1) & Rune2; - if(l <= Rune1) - goto bad; - *rune = l; - return 2; - } - - // If we can't read more than two characters we must stop - if(length <= 2) { - goto badlen; - } - - /* - * three character sequence (16-bit value) - * 0800-FFFF => T3 Tx Tx - */ - c2 = *(byte*)(str+2) ^ Tx; - if(c2 & Testx) - goto bad; - if(c < T4) { - l = ((((c << Bitx) | c1) << Bitx) | c2) & Rune3; - if(l <= Rune2) - goto bad; - *rune = l; - return 3; - } - - if (length <= 3) - goto badlen; - - /* - * four character sequence (21-bit value) - * 10000-1FFFFF => T4 Tx Tx Tx - */ - c3 = *(byte*)(str+3) ^ Tx; - if (c3 & Testx) - goto bad; - if (c < T5) { - l = ((((((c << Bitx) | c1) << Bitx) | c2) << Bitx) | c3) & Rune4; - if (l <= Rune3) - goto bad; - *rune = l; - return 4; - } - - // Support for 5-byte or longer UTF-8 would go here, but - // since we don't have that, we'll just fall through to bad. - - /* - * bad decoding - */ -bad: - *rune = Bad; - return 1; -badlen: - *rune = Bad; - return 0; - -} - int32 runetochar(byte *str, int32 rune) /* note: in original, arg2 was pointer */ { @@ -222,22 +108,3 @@ runetochar(byte *str, int32 rune) /* note: in original, arg2 was pointer */ str[3] = Tx | (c & Maskx); return 4; } - -/* - * Wrappers for calling from go - */ -void -sys·bytestorune(byte *str, int32 off, int32 length, int32 outrune, int32 outcount) -{ - outcount = charntorune(&outrune, str + off, length); - FLUSH(&outrune); - FLUSH(&outcount); -} - -void -sys·stringtorune(string str, int32 off, int32 outrune, int32 outcount) -{ - outcount = charntorune(&outrune, str->str + off, str->len - off); - FLUSH(&outrune); - FLUSH(&outcount); -} |