diff options
author | Russ Cox <rsc@golang.org> | 2009-10-08 15:14:54 -0700 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2009-10-08 15:14:54 -0700 |
commit | 79244ca7360f32db37710ab74c72214146397edf (patch) | |
tree | 0f7c5551b95f4e5dd567a4ac3233afeb0da61e99 /src/pkg/utf8 | |
parent | 71b9ef8c235f052495a1fb29bd3945f7094998a9 (diff) | |
download | golang-79244ca7360f32db37710ab74c72214146397edf.tar.gz |
more lgtm files from gofmt
R=gri
OCL=35485
CL=35488
Diffstat (limited to 'src/pkg/utf8')
-rw-r--r-- | src/pkg/utf8/utf8.go | 112 | ||||
-rw-r--r-- | src/pkg/utf8/utf8_test.go | 2 |
2 files changed, 57 insertions, 57 deletions
diff --git a/src/pkg/utf8/utf8.go b/src/pkg/utf8/utf8.go index c8dc61304..18ae7cf58 100644 --- a/src/pkg/utf8/utf8.go +++ b/src/pkg/utf8/utf8.go @@ -10,28 +10,28 @@ import "unicode" // only needed for a couple of constants // Numbers fundamental to the encoding. const ( - RuneError = unicode.ReplacementChar; // the "error" Rune or "replacement character". - RuneSelf = 0x80; // characters below Runeself are represented as themselves in a single byte. - UTFMax = 4; // maximum number of bytes of a UTF-8 encoded Unicode character. + RuneError = unicode.ReplacementChar; // the "error" Rune or "replacement character". + RuneSelf = 0x80; // characters below Runeself are represented as themselves in a single byte. + UTFMax = 4; // maximum number of bytes of a UTF-8 encoded Unicode character. ) const ( - _T1 = 0x00; // 0000 0000 - _Tx = 0x80; // 1000 0000 - _T2 = 0xC0; // 1100 0000 - _T3 = 0xE0; // 1110 0000 - _T4 = 0xF0; // 1111 0000 - _T5 = 0xF8; // 1111 1000 - - _Maskx = 0x3F; // 0011 1111 - _Mask2 = 0x1F; // 0001 1111 - _Mask3 = 0x0F; // 0000 1111 - _Mask4 = 0x07; // 0000 0111 - - _Rune1Max = 1<<7 - 1; - _Rune2Max = 1<<11 - 1; - _Rune3Max = 1<<16 - 1; - _Rune4Max = 1<<21 - 1; + _T1 = 0x00; // 0000 0000 + _Tx = 0x80; // 1000 0000 + _T2 = 0xC0; // 1100 0000 + _T3 = 0xE0; // 1110 0000 + _T4 = 0xF0; // 1111 0000 + _T5 = 0xF8; // 1111 1000 + + _Maskx = 0x3F; // 0011 1111 + _Mask2 = 0x1F; // 0001 1111 + _Mask3 = 0x0F; // 0000 1111 + _Mask4 = 0x07; // 0000 0111 + + _Rune1Max = 1<<7 - 1; + _Rune2Max = 1<<11 - 1; + _Rune3Max = 1<<16 - 1; + _Rune4Max = 1<<21 - 1; ) func decodeRuneInternal(p []byte) (rune, size int, short bool) { @@ -43,70 +43,70 @@ func decodeRuneInternal(p []byte) (rune, size int, short bool) { // 1-byte, 7-bit sequence? if c0 < _Tx { - return int(c0), 1, false + return int(c0), 1, false; } // unexpected continuation byte? if c0 < _T2 { - return RuneError, 1, false + return RuneError, 1, false; } // need first continuation byte if n < 2 { - return RuneError, 1, true + return RuneError, 1, true; } c1 := p[1]; if c1 < _Tx || _T2 <= c1 { - return RuneError, 1, false + return RuneError, 1, false; } // 2-byte, 11-bit sequence? if c0 < _T3 { rune = int(c0&_Mask2)<<6 | int(c1&_Maskx); if rune <= _Rune1Max { - return RuneError, 1, false + return RuneError, 1, false; } - return rune, 2, false + return rune, 2, false; } // need second continuation byte if n < 3 { - return RuneError, 1, true + return RuneError, 1, true; } c2 := p[2]; if c2 < _Tx || _T2 <= c2 { - return RuneError, 1, false + return RuneError, 1, false; } // 3-byte, 16-bit sequence? if c0 < _T4 { rune = int(c0&_Mask3)<<12 | int(c1&_Maskx)<<6 | int(c2&_Maskx); if rune <= _Rune2Max { - return RuneError, 1, false + return RuneError, 1, false; } - return rune, 3, false + return rune, 3, false; } // need third continuation byte if n < 4 { - return RuneError, 1, true + return RuneError, 1, true; } c3 := p[3]; if c3 < _Tx || _T2 <= c3 { - return RuneError, 1, false + return RuneError, 1, false; } // 4-byte, 21-bit sequence? if c0 < _T5 { rune = int(c0&_Mask4)<<18 | int(c1&_Maskx)<<12 | int(c2&_Maskx)<<6 | int(c3&_Maskx); if rune <= _Rune3Max { - return RuneError, 1, false + return RuneError, 1, false; } - return rune, 4, false + return rune, 4, false; } // error - return RuneError, 1, false + return RuneError, 1, false; } func decodeRuneInStringInternal(s string) (rune, size int, short bool) { @@ -118,83 +118,83 @@ func decodeRuneInStringInternal(s string) (rune, size int, short bool) { // 1-byte, 7-bit sequence? if c0 < _Tx { - return int(c0), 1, false + return int(c0), 1, false; } // unexpected continuation byte? if c0 < _T2 { - return RuneError, 1, false + return RuneError, 1, false; } // need first continuation byte if n < 2 { - return RuneError, 1, true + return RuneError, 1, true; } c1 := s[1]; if c1 < _Tx || _T2 <= c1 { - return RuneError, 1, false + return RuneError, 1, false; } // 2-byte, 11-bit sequence? if c0 < _T3 { rune = int(c0&_Mask2)<<6 | int(c1&_Maskx); if rune <= _Rune1Max { - return RuneError, 1, false + return RuneError, 1, false; } - return rune, 2, false + return rune, 2, false; } // need second continuation byte if n < 3 { - return RuneError, 1, true + return RuneError, 1, true; } c2 := s[2]; if c2 < _Tx || _T2 <= c2 { - return RuneError, 1, false + return RuneError, 1, false; } // 3-byte, 16-bit sequence? if c0 < _T4 { rune = int(c0&_Mask3)<<12 | int(c1&_Maskx)<<6 | int(c2&_Maskx); if rune <= _Rune2Max { - return RuneError, 1, false + return RuneError, 1, false; } - return rune, 3, false + return rune, 3, false; } // need third continuation byte if n < 4 { - return RuneError, 1, true + return RuneError, 1, true; } c3 := s[3]; if c3 < _Tx || _T2 <= c3 { - return RuneError, 1, false + return RuneError, 1, false; } // 4-byte, 21-bit sequence? if c0 < _T5 { rune = int(c0&_Mask4)<<18 | int(c1&_Maskx)<<12 | int(c2&_Maskx)<<6 | int(c3&_Maskx); if rune <= _Rune3Max { - return RuneError, 1, false + return RuneError, 1, false; } - return rune, 4, false + return rune, 4, false; } // error - return RuneError, 1, false + return RuneError, 1, false; } // FullRune reports whether the bytes in p begin with a full UTF-8 encoding of a rune. // An invalid encoding is considered a full Rune since it will convert as a width-1 error rune. func FullRune(p []byte) bool { _, _, short := decodeRuneInternal(p); - return !short + return !short; } // FullRuneInString is like FullRune but its input is a string. func FullRuneInString(s string) bool { _, _, short := decodeRuneInStringInternal(s); - return !short + return !short; } // DecodeRune unpacks the first UTF-8 encoding in p and returns the rune and its width in bytes. @@ -233,23 +233,23 @@ func EncodeRune(rune int, p []byte) int { } if rune <= _Rune2Max { - p[0] = _T2 | byte(rune>>6); + p[0] = _T2|byte(rune>>6); p[1] = _Tx | byte(rune)&_Maskx; return 2; } if rune > unicode.MaxRune { - rune = RuneError + rune = RuneError; } if rune <= _Rune3Max { - p[0] = _T3 | byte(rune>>12); + p[0] = _T3|byte(rune>>12); p[1] = _Tx | byte(rune>>6)&_Maskx; p[2] = _Tx | byte(rune)&_Maskx; return 3; } - p[0] = _T4 | byte(rune>>18); + p[0] = _T4|byte(rune>>18); p[1] = _Tx | byte(rune>>12)&_Maskx; p[2] = _Tx | byte(rune>>6)&_Maskx; p[3] = _Tx | byte(rune)&_Maskx; @@ -292,5 +292,5 @@ func RuneCountInString(s string) int { // an encoded rune. Second and subsequent bytes always have the top // two bits set to 10. func RuneStart(b byte) bool { - return b & 0xC0 != 0x80 + return b&0xC0 != 0x80; } diff --git a/src/pkg/utf8/utf8_test.go b/src/pkg/utf8/utf8_test.go index 9151ad9e0..f18eff8d6 100644 --- a/src/pkg/utf8/utf8_test.go +++ b/src/pkg/utf8/utf8_test.go @@ -120,7 +120,7 @@ func TestDecodeRune(t *testing.T) { if rune != RuneError || size != wantsize { t.Errorf("DecodeRune(%q) = 0x%04x, %d want 0x%04x, %d", b[0 : len(b)-1], rune, size, RuneError, wantsize); } - s = m.str[0 : len(m.str) - 1]; + s = m.str[0 : len(m.str)-1]; rune, size = DecodeRuneInString(s); if rune != RuneError || size != wantsize { t.Errorf("DecodeRuneInString(%q) = 0x%04x, %d want 0x%04x, %d", s, rune, size, RuneError, wantsize); |