diff options
author | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-12-02 19:34:41 +0000 |
---|---|---|
committer | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-12-02 19:34:41 +0000 |
commit | 0ba415ab214ea7bc9c0b5a31e809998686d8b511 (patch) | |
tree | fe0344f264049738dca876a6dd2f69e96621ca17 /libgo/go/unicode | |
parent | b2c1d8d78d1a819c3cbadc61dea50b856a4f0607 (diff) | |
download | gcc-0ba415ab214ea7bc9c0b5a31e809998686d8b511.tar.gz |
libgo: Update to weekly.2011-11-01.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@181938 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/unicode')
-rw-r--r-- | libgo/go/unicode/digit.go | 8 | ||||
-rw-r--r-- | libgo/go/unicode/digit_test.go | 6 | ||||
-rw-r--r-- | libgo/go/unicode/graphic.go | 70 | ||||
-rw-r--r-- | libgo/go/unicode/graphic_test.go | 20 | ||||
-rw-r--r-- | libgo/go/unicode/letter.go | 156 | ||||
-rw-r--r-- | libgo/go/unicode/letter_test.go | 29 | ||||
-rw-r--r-- | libgo/go/unicode/script_test.go | 2 |
7 files changed, 146 insertions, 145 deletions
diff --git a/libgo/go/unicode/digit.go b/libgo/go/unicode/digit.go index 6793fd7e5f8..4800bd6ea8e 100644 --- a/libgo/go/unicode/digit.go +++ b/libgo/go/unicode/digit.go @@ -5,9 +5,9 @@ package unicode // IsDigit reports whether the rune is a decimal digit. -func IsDigit(rune int) bool { - if rune <= MaxLatin1 { - return '0' <= rune && rune <= '9' +func IsDigit(r rune) bool { + if r <= MaxLatin1 { + return '0' <= r && r <= '9' } - return Is(Digit, rune) + return Is(Digit, r) } diff --git a/libgo/go/unicode/digit_test.go b/libgo/go/unicode/digit_test.go index ae3c0ece93f..551c42a24ee 100644 --- a/libgo/go/unicode/digit_test.go +++ b/libgo/go/unicode/digit_test.go @@ -9,7 +9,7 @@ import ( . "unicode" ) -var testDigit = []int{ +var testDigit = []rune{ 0x0030, 0x0039, 0x0661, @@ -68,7 +68,7 @@ var testDigit = []int{ 0x1D7CE, } -var testLetter = []int{ +var testLetter = []rune{ 0x0041, 0x0061, 0x00AA, @@ -118,7 +118,7 @@ func TestDigit(t *testing.T) { // Test that the special case in IsDigit agrees with the table func TestDigitOptimization(t *testing.T) { - for i := 0; i <= MaxLatin1; i++ { + for i := rune(0); i <= MaxLatin1; i++ { if Is(Digit, i) != IsDigit(i) { t.Errorf("IsDigit(U+%04X) disagrees with Is(Digit)", i) } diff --git a/libgo/go/unicode/graphic.go b/libgo/go/unicode/graphic.go index d482aace26e..9343bc9b0a9 100644 --- a/libgo/go/unicode/graphic.go +++ b/libgo/go/unicode/graphic.go @@ -31,13 +31,13 @@ var PrintRanges = []*RangeTable{ // IsGraphic reports whether the rune is defined as a Graphic by Unicode. // Such characters include letters, marks, numbers, punctuation, symbols, and // spaces, from categories L, M, N, P, S, Zs. -func IsGraphic(rune int) bool { +func IsGraphic(r rune) bool { // We cast to uint32 to avoid the extra test for negative, // and in the index we cast to uint8 to avoid the range check. - if uint32(rune) <= MaxLatin1 { - return properties[uint8(rune)]&pg != 0 + if uint32(r) <= MaxLatin1 { + return properties[uint8(r)]&pg != 0 } - return IsOneOf(GraphicRanges, rune) + return IsOneOf(GraphicRanges, r) } // IsPrint reports whether the rune is defined as printable by Go. Such @@ -45,18 +45,18 @@ func IsGraphic(rune int) bool { // ASCII space character, from categories L, M, N, P, S and the ASCII space // character. This categorization is the same as IsGraphic except that the // only spacing character is ASCII space, U+0020. -func IsPrint(rune int) bool { - if uint32(rune) <= MaxLatin1 { - return properties[uint8(rune)]&pp != 0 +func IsPrint(r rune) bool { + if uint32(r) <= MaxLatin1 { + return properties[uint8(r)]&pp != 0 } - return IsOneOf(PrintRanges, rune) + return IsOneOf(PrintRanges, r) } // IsOneOf reports whether the rune is a member of one of the ranges. // The rune is known to be above Latin-1. -func IsOneOf(set []*RangeTable, rune int) bool { +func IsOneOf(set []*RangeTable, r rune) bool { for _, inside := range set { - if Is(inside, rune) { + if Is(inside, r) { return true } } @@ -66,43 +66,43 @@ func IsOneOf(set []*RangeTable, rune int) bool { // IsControl reports whether the rune is a control character. // The C (Other) Unicode category includes more code points // such as surrogates; use Is(C, rune) to test for them. -func IsControl(rune int) bool { - if uint32(rune) <= MaxLatin1 { - return properties[uint8(rune)]&pC != 0 +func IsControl(r rune) bool { + if uint32(r) <= MaxLatin1 { + return properties[uint8(r)]&pC != 0 } // All control characters are < Latin1Max. return false } // IsLetter reports whether the rune is a letter (category L). -func IsLetter(rune int) bool { - if uint32(rune) <= MaxLatin1 { - return properties[uint8(rune)]&(pLu|pLl) != 0 +func IsLetter(r rune) bool { + if uint32(r) <= MaxLatin1 { + return properties[uint8(r)]&(pLu|pLl) != 0 } - return Is(Letter, rune) + return Is(Letter, r) } // IsMark reports whether the rune is a mark character (category M). -func IsMark(rune int) bool { +func IsMark(r rune) bool { // There are no mark characters in Latin-1. - return Is(Mark, rune) + return Is(Mark, r) } // IsNumber reports whether the rune is a number (category N). -func IsNumber(rune int) bool { - if uint32(rune) <= MaxLatin1 { - return properties[uint8(rune)]&pN != 0 +func IsNumber(r rune) bool { + if uint32(r) <= MaxLatin1 { + return properties[uint8(r)]&pN != 0 } - return Is(Number, rune) + return Is(Number, r) } // IsPunct reports whether the rune is a Unicode punctuation character // (category P). -func IsPunct(rune int) bool { - if uint32(rune) <= MaxLatin1 { - return properties[uint8(rune)]&pP != 0 +func IsPunct(r rune) bool { + if uint32(r) <= MaxLatin1 { + return properties[uint8(r)]&pP != 0 } - return Is(Punct, rune) + return Is(Punct, r) } // IsSpace reports whether the rune is a space character as defined @@ -111,22 +111,22 @@ func IsPunct(rune int) bool { // '\t', '\n', '\v', '\f', '\r', ' ', U+0085 (NEL), U+00A0 (NBSP). // Other definitions of spacing characters are set by category // Z and property Pattern_White_Space. -func IsSpace(rune int) bool { +func IsSpace(r rune) bool { // This property isn't the same as Z; special-case it. - if uint32(rune) <= MaxLatin1 { - switch rune { + if uint32(r) <= MaxLatin1 { + switch r { case '\t', '\n', '\v', '\f', '\r', ' ', 0x85, 0xA0: return true } return false } - return Is(White_Space, rune) + return Is(White_Space, r) } // IsSymbol reports whether the rune is a symbolic character. -func IsSymbol(rune int) bool { - if uint32(rune) <= MaxLatin1 { - return properties[uint8(rune)]&pS != 0 +func IsSymbol(r rune) bool { + if uint32(r) <= MaxLatin1 { + return properties[uint8(r)]&pS != 0 } - return Is(Symbol, rune) + return Is(Symbol, r) } diff --git a/libgo/go/unicode/graphic_test.go b/libgo/go/unicode/graphic_test.go index 77c679f7ce0..7b1f6209e80 100644 --- a/libgo/go/unicode/graphic_test.go +++ b/libgo/go/unicode/graphic_test.go @@ -13,7 +13,7 @@ import ( // in the Latin-1 range through the property table. func TestIsControlLatin1(t *testing.T) { - for i := 0; i <= MaxLatin1; i++ { + for i := rune(0); i <= MaxLatin1; i++ { got := IsControl(i) want := false switch { @@ -29,7 +29,7 @@ func TestIsControlLatin1(t *testing.T) { } func TestIsLetterLatin1(t *testing.T) { - for i := 0; i <= MaxLatin1; i++ { + for i := rune(0); i <= MaxLatin1; i++ { got := IsLetter(i) want := Is(Letter, i) if got != want { @@ -39,7 +39,7 @@ func TestIsLetterLatin1(t *testing.T) { } func TestIsUpperLatin1(t *testing.T) { - for i := 0; i <= MaxLatin1; i++ { + for i := rune(0); i <= MaxLatin1; i++ { got := IsUpper(i) want := Is(Upper, i) if got != want { @@ -49,7 +49,7 @@ func TestIsUpperLatin1(t *testing.T) { } func TestIsLowerLatin1(t *testing.T) { - for i := 0; i <= MaxLatin1; i++ { + for i := rune(0); i <= MaxLatin1; i++ { got := IsLower(i) want := Is(Lower, i) if got != want { @@ -59,7 +59,7 @@ func TestIsLowerLatin1(t *testing.T) { } func TestNumberLatin1(t *testing.T) { - for i := 0; i <= MaxLatin1; i++ { + for i := rune(0); i <= MaxLatin1; i++ { got := IsNumber(i) want := Is(Number, i) if got != want { @@ -69,7 +69,7 @@ func TestNumberLatin1(t *testing.T) { } func TestIsPrintLatin1(t *testing.T) { - for i := 0; i <= MaxLatin1; i++ { + for i := rune(0); i <= MaxLatin1; i++ { got := IsPrint(i) want := IsOneOf(PrintRanges, i) if i == ' ' { @@ -82,7 +82,7 @@ func TestIsPrintLatin1(t *testing.T) { } func TestIsGraphicLatin1(t *testing.T) { - for i := 0; i <= MaxLatin1; i++ { + for i := rune(0); i <= MaxLatin1; i++ { got := IsGraphic(i) want := IsOneOf(GraphicRanges, i) if got != want { @@ -92,7 +92,7 @@ func TestIsGraphicLatin1(t *testing.T) { } func TestIsPunctLatin1(t *testing.T) { - for i := 0; i <= MaxLatin1; i++ { + for i := rune(0); i <= MaxLatin1; i++ { got := IsPunct(i) want := Is(Punct, i) if got != want { @@ -102,7 +102,7 @@ func TestIsPunctLatin1(t *testing.T) { } func TestIsSpaceLatin1(t *testing.T) { - for i := 0; i <= MaxLatin1; i++ { + for i := rune(0); i <= MaxLatin1; i++ { got := IsSpace(i) want := Is(White_Space, i) if got != want { @@ -112,7 +112,7 @@ func TestIsSpaceLatin1(t *testing.T) { } func TestIsSymbolLatin1(t *testing.T) { - for i := 0; i <= MaxLatin1; i++ { + for i := rune(0); i <= MaxLatin1; i++ { got := IsSymbol(i) want := Is(Symbol, i) if got != want { diff --git a/libgo/go/unicode/letter.go b/libgo/go/unicode/letter.go index 38a11c42bf6..01c485b6931 100644 --- a/libgo/go/unicode/letter.go +++ b/libgo/go/unicode/letter.go @@ -71,7 +71,7 @@ const ( MaxCase ) -type d [MaxCase]int32 // to make the CaseRanges text shorter +type d [MaxCase]rune // to make the CaseRanges text shorter // If the Delta field of a CaseRange is UpperLower or LowerUpper, it means // this CaseRange represents a sequence of the form (say) @@ -81,17 +81,17 @@ const ( ) // is16 uses binary search to test whether rune is in the specified slice of 16-bit ranges. -func is16(ranges []Range16, rune uint16) bool { +func is16(ranges []Range16, r uint16) bool { // binary search over ranges lo := 0 hi := len(ranges) for lo < hi { m := lo + (hi-lo)/2 - r := ranges[m] - if r.Lo <= rune && rune <= r.Hi { - return (rune-r.Lo)%r.Stride == 0 + range_ := ranges[m] + if range_.Lo <= r && r <= range_.Hi { + return (r-range_.Lo)%range_.Stride == 0 } - if rune < r.Lo { + if r < range_.Lo { hi = m } else { lo = m + 1 @@ -101,17 +101,17 @@ func is16(ranges []Range16, rune uint16) bool { } // is32 uses binary search to test whether rune is in the specified slice of 32-bit ranges. -func is32(ranges []Range32, rune uint32) bool { +func is32(ranges []Range32, r uint32) bool { // binary search over ranges lo := 0 hi := len(ranges) for lo < hi { m := lo + (hi-lo)/2 - r := ranges[m] - if r.Lo <= rune && rune <= r.Hi { - return (rune-r.Lo)%r.Stride == 0 + range_ := ranges[m] + if range_.Lo <= r && r <= range_.Hi { + return (r-range_.Lo)%range_.Stride == 0 } - if rune < r.Lo { + if r < range_.Lo { hi = m } else { lo = m + 1 @@ -121,11 +121,11 @@ func is32(ranges []Range32, rune uint32) bool { } // Is tests whether rune is in the specified table of ranges. -func Is(rangeTab *RangeTable, rune int) bool { +func Is(rangeTab *RangeTable, r rune) bool { // common case: rune is ASCII or Latin-1. - if uint32(rune) <= MaxLatin1 { + if uint32(r) <= MaxLatin1 { // Only need to check R16, since R32 is always >= 1<<16. - r16 := uint16(rune) + r16 := uint16(r) for _, r := range rangeTab.R16 { if r16 > r.Hi { continue @@ -138,44 +138,44 @@ func Is(rangeTab *RangeTable, rune int) bool { return false } r16 := rangeTab.R16 - if len(r16) > 0 && rune <= int(r16[len(r16)-1].Hi) { - return is16(r16, uint16(rune)) + if len(r16) > 0 && r <= rune(r16[len(r16)-1].Hi) { + return is16(r16, uint16(r)) } r32 := rangeTab.R32 - if len(r32) > 0 && rune >= int(r32[0].Lo) { - return is32(r32, uint32(rune)) + if len(r32) > 0 && r >= rune(r32[0].Lo) { + return is32(r32, uint32(r)) } return false } // IsUpper reports whether the rune is an upper case letter. -func IsUpper(rune int) bool { +func IsUpper(r rune) bool { // See comment in IsGraphic. - if uint32(rune) <= MaxLatin1 { - return properties[uint8(rune)]&pLu != 0 + if uint32(r) <= MaxLatin1 { + return properties[uint8(r)]&pLu != 0 } - return Is(Upper, rune) + return Is(Upper, r) } // IsLower reports whether the rune is a lower case letter. -func IsLower(rune int) bool { +func IsLower(r rune) bool { // See comment in IsGraphic. - if uint32(rune) <= MaxLatin1 { - return properties[uint8(rune)]&pLl != 0 + if uint32(r) <= MaxLatin1 { + return properties[uint8(r)]&pLl != 0 } - return Is(Lower, rune) + return Is(Lower, r) } // IsTitle reports whether the rune is a title case letter. -func IsTitle(rune int) bool { - if rune <= MaxLatin1 { +func IsTitle(r rune) bool { + if r <= MaxLatin1 { return false } - return Is(Title, rune) + return Is(Title, r) } // to maps the rune using the specified case mapping. -func to(_case int, rune int, caseRange []CaseRange) int { +func to(_case int, r rune, caseRange []CaseRange) rune { if _case < 0 || MaxCase <= _case { return ReplacementChar // as reasonable an error as any } @@ -184,9 +184,9 @@ func to(_case int, rune int, caseRange []CaseRange) int { hi := len(caseRange) for lo < hi { m := lo + (hi-lo)/2 - r := caseRange[m] - if int(r.Lo) <= rune && rune <= int(r.Hi) { - delta := int(r.Delta[_case]) + cr := caseRange[m] + if rune(cr.Lo) <= r && r <= rune(cr.Hi) { + delta := rune(cr.Delta[_case]) if delta > MaxRune { // In an Upper-Lower sequence, which always starts with // an UpperCase letter, the real deltas always look like: @@ -198,82 +198,82 @@ func to(_case int, rune int, caseRange []CaseRange) int { // bit in the sequence offset. // The constants UpperCase and TitleCase are even while LowerCase // is odd so we take the low bit from _case. - return int(r.Lo) + ((rune-int(r.Lo))&^1 | _case&1) + return rune(cr.Lo) + ((r-rune(cr.Lo))&^1 | rune(_case&1)) } - return rune + delta + return r + delta } - if rune < int(r.Lo) { + if r < rune(cr.Lo) { hi = m } else { lo = m + 1 } } - return rune + return r } // To maps the rune to the specified case: UpperCase, LowerCase, or TitleCase. -func To(_case int, rune int) int { - return to(_case, rune, CaseRanges) +func To(_case int, r rune) rune { + return to(_case, r, CaseRanges) } // ToUpper maps the rune to upper case. -func ToUpper(rune int) int { - if rune <= MaxASCII { - if 'a' <= rune && rune <= 'z' { - rune -= 'a' - 'A' +func ToUpper(r rune) rune { + if r <= MaxASCII { + if 'a' <= r && r <= 'z' { + r -= 'a' - 'A' } - return rune + return r } - return To(UpperCase, rune) + return To(UpperCase, r) } // ToLower maps the rune to lower case. -func ToLower(rune int) int { - if rune <= MaxASCII { - if 'A' <= rune && rune <= 'Z' { - rune += 'a' - 'A' +func ToLower(r rune) rune { + if r <= MaxASCII { + if 'A' <= r && r <= 'Z' { + r += 'a' - 'A' } - return rune + return r } - return To(LowerCase, rune) + return To(LowerCase, r) } // ToTitle maps the rune to title case. -func ToTitle(rune int) int { - if rune <= MaxASCII { - if 'a' <= rune && rune <= 'z' { // title case is upper case for ASCII - rune -= 'a' - 'A' +func ToTitle(r rune) rune { + if r <= MaxASCII { + if 'a' <= r && r <= 'z' { // title case is upper case for ASCII + r -= 'a' - 'A' } - return rune + return r } - return To(TitleCase, rune) + return To(TitleCase, r) } // ToUpper maps the rune to upper case giving priority to the special mapping. -func (special SpecialCase) ToUpper(rune int) int { - r := to(UpperCase, rune, []CaseRange(special)) - if r == rune { - r = ToUpper(rune) +func (special SpecialCase) ToUpper(r rune) rune { + r1 := to(UpperCase, r, []CaseRange(special)) + if r1 == r { + r1 = ToUpper(r) } - return r + return r1 } // ToTitle maps the rune to title case giving priority to the special mapping. -func (special SpecialCase) ToTitle(rune int) int { - r := to(TitleCase, rune, []CaseRange(special)) - if r == rune { - r = ToTitle(rune) +func (special SpecialCase) ToTitle(r rune) rune { + r1 := to(TitleCase, r, []CaseRange(special)) + if r1 == r { + r1 = ToTitle(r) } - return r + return r1 } // ToLower maps the rune to lower case giving priority to the special mapping. -func (special SpecialCase) ToLower(rune int) int { - r := to(LowerCase, rune, []CaseRange(special)) - if r == rune { - r = ToLower(rune) +func (special SpecialCase) ToLower(r rune) rune { + r1 := to(LowerCase, r, []CaseRange(special)) + if r1 == r { + r1 = ToLower(r) } - return r + return r1 } // caseOrbit is defined in tables.go as []foldPair. Right now all the @@ -300,27 +300,27 @@ type foldPair struct { // // SimpleFold('1') = '1' // -func SimpleFold(rune int) int { +func SimpleFold(r rune) rune { // Consult caseOrbit table for special cases. lo := 0 hi := len(caseOrbit) for lo < hi { m := lo + (hi-lo)/2 - if int(caseOrbit[m].From) < rune { + if rune(caseOrbit[m].From) < r { lo = m + 1 } else { hi = m } } - if lo < len(caseOrbit) && int(caseOrbit[lo].From) == rune { - return int(caseOrbit[lo].To) + if lo < len(caseOrbit) && rune(caseOrbit[lo].From) == r { + return rune(caseOrbit[lo].To) } // No folding specified. This is a one- or two-element // equivalence class containing rune and ToLower(rune) // and ToUpper(rune) if they are different from rune. - if l := ToLower(rune); l != rune { + if l := ToLower(r); l != r { return l } - return ToUpper(rune) + return ToUpper(r) } diff --git a/libgo/go/unicode/letter_test.go b/libgo/go/unicode/letter_test.go index 8d2665a44fc..2d80562182c 100644 --- a/libgo/go/unicode/letter_test.go +++ b/libgo/go/unicode/letter_test.go @@ -9,7 +9,7 @@ import ( . "unicode" ) -var upperTest = []int{ +var upperTest = []rune{ 0x41, 0xc0, 0xd8, @@ -33,7 +33,7 @@ var upperTest = []int{ 0x1d7ca, } -var notupperTest = []int{ +var notupperTest = []rune{ 0x40, 0x5b, 0x61, @@ -46,7 +46,7 @@ var notupperTest = []int{ 0x10000, } -var letterTest = []int{ +var letterTest = []rune{ 0x41, 0x61, 0xaa, @@ -82,7 +82,7 @@ var letterTest = []int{ 0x2fa1d, } -var notletterTest = []int{ +var notletterTest = []rune{ 0x20, 0x35, 0x375, @@ -94,7 +94,7 @@ var notletterTest = []int{ } // Contains all the special cased Latin-1 chars. -var spaceTest = []int{ +var spaceTest = []rune{ 0x09, 0x0a, 0x0b, @@ -108,7 +108,8 @@ var spaceTest = []int{ } type caseT struct { - cas, in, out int + cas int + in, out rune } var caseTest = []caseT{ @@ -327,7 +328,7 @@ func TestIsSpace(t *testing.T) { // Check that the optimizations for IsLetter etc. agree with the tables. // We only need to check the Latin-1 range. func TestLetterOptimizations(t *testing.T) { - for i := 0; i <= MaxLatin1; i++ { + for i := rune(0); i <= MaxLatin1; i++ { if Is(Letter, i) != IsLetter(i) { t.Errorf("IsLetter(U+%04X) disagrees with Is(Letter)", i) } @@ -356,8 +357,8 @@ func TestLetterOptimizations(t *testing.T) { } func TestTurkishCase(t *testing.T) { - lower := []int("abcçdefgğhıijklmnoöprsştuüvyz") - upper := []int("ABCÇDEFGĞHIİJKLMNOÖPRSŞTUÜVYZ") + lower := []rune("abcçdefgğhıijklmnoöprsştuüvyz") + upper := []rune("ABCÇDEFGĞHIİJKLMNOÖPRSŞTUÜVYZ") for i, l := range lower { u := upper[i] if TurkishCase.ToLower(l) != l { @@ -416,13 +417,13 @@ var simpleFoldTests = []string{ func TestSimpleFold(t *testing.T) { for _, tt := range simpleFoldTests { - cycle := []int(tt) - rune := cycle[len(cycle)-1] + cycle := []rune(tt) + r := cycle[len(cycle)-1] for _, out := range cycle { - if r := SimpleFold(rune); r != out { - t.Errorf("SimpleFold(%#U) = %#U, want %#U", rune, r, out) + if r := SimpleFold(r); r != out { + t.Errorf("SimpleFold(%#U) = %#U, want %#U", r, r, out) } - rune = out + r = out } } } diff --git a/libgo/go/unicode/script_test.go b/libgo/go/unicode/script_test.go index dfd636d8399..1c5b801426f 100644 --- a/libgo/go/unicode/script_test.go +++ b/libgo/go/unicode/script_test.go @@ -10,7 +10,7 @@ import ( ) type T struct { - rune int + rune rune script string } |