]> Cypherpunks repositories - gostls13.git/commitdiff
unicode: for consistency with MaxRune, s/Latin1Max/MaxLatin1/ and
authorRob Pike <r@golang.org>
Fri, 3 Jun 2011 23:28:27 +0000 (09:28 +1000)
committerRob Pike <r@golang.org>
Fri, 3 Jun 2011 23:28:27 +0000 (09:28 +1000)
s/ASCIIMax/MaxASCII/

R=golang-dev, r, gri
CC=golang-dev
https://golang.org/cl/4539109

src/pkg/unicode/digit.go
src/pkg/unicode/digit_test.go
src/pkg/unicode/graphic.go
src/pkg/unicode/graphic_test.go
src/pkg/unicode/letter.go
src/pkg/unicode/letter_test.go
src/pkg/unicode/maketables.go
src/pkg/unicode/tables.go

index c0866ea27db723eecad89635d7bc055078a6dfb4..6793fd7e5f8148dcaa4b7946d7e61a05c4e97817 100644 (file)
@@ -6,7 +6,7 @@ package unicode
 
 // IsDigit reports whether the rune is a decimal digit.
 func IsDigit(rune int) bool {
-       if rune < Latin1Max {
+       if rune <= MaxLatin1 {
                return '0' <= rune && rune <= '9'
        }
        return Is(Digit, rune)
index 3cafbb1fde39e71776af3938a5c308c4f500c1c5..ae3c0ece93f116dd1924001415cf064773875896 100644 (file)
@@ -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 < Latin1Max; i++ {
+       for i := 0; i <= MaxLatin1; i++ {
                if Is(Digit, i) != IsDigit(i) {
                        t.Errorf("IsDigit(U+%04X) disagrees with Is(Digit)", i)
                }
index 3feda7bd36b7647e2f4b1a76605f69c93c80c613..d482aace26e944d4ebd113479e30c4de91496537 100644 (file)
@@ -34,7 +34,7 @@ var PrintRanges = []*RangeTable{
 func IsGraphic(rune int) 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) < Latin1Max {
+       if uint32(rune) <= MaxLatin1 {
                return properties[uint8(rune)]&pg != 0
        }
        return IsOneOf(GraphicRanges, rune)
@@ -46,7 +46,7 @@ func IsGraphic(rune int) bool {
 // 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) < Latin1Max {
+       if uint32(rune) <= MaxLatin1 {
                return properties[uint8(rune)]&pp != 0
        }
        return IsOneOf(PrintRanges, rune)
@@ -67,7 +67,7 @@ func IsOneOf(set []*RangeTable, rune int) bool {
 // 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) < Latin1Max {
+       if uint32(rune) <= MaxLatin1 {
                return properties[uint8(rune)]&pC != 0
        }
        // All control characters are < Latin1Max.
@@ -76,7 +76,7 @@ func IsControl(rune int) bool {
 
 // IsLetter reports whether the rune is a letter (category L).
 func IsLetter(rune int) bool {
-       if uint32(rune) < Latin1Max {
+       if uint32(rune) <= MaxLatin1 {
                return properties[uint8(rune)]&(pLu|pLl) != 0
        }
        return Is(Letter, rune)
@@ -90,7 +90,7 @@ func IsMark(rune int) bool {
 
 // IsNumber reports whether the rune is a number (category N).
 func IsNumber(rune int) bool {
-       if uint32(rune) < Latin1Max {
+       if uint32(rune) <= MaxLatin1 {
                return properties[uint8(rune)]&pN != 0
        }
        return Is(Number, rune)
@@ -99,7 +99,7 @@ func IsNumber(rune int) bool {
 // IsPunct reports whether the rune is a Unicode punctuation character
 // (category P).
 func IsPunct(rune int) bool {
-       if uint32(rune) < Latin1Max {
+       if uint32(rune) <= MaxLatin1 {
                return properties[uint8(rune)]&pP != 0
        }
        return Is(Punct, rune)
@@ -113,7 +113,7 @@ func IsPunct(rune int) bool {
 // Z and property Pattern_White_Space.
 func IsSpace(rune int) bool {
        // This property isn't the same as Z; special-case it.
-       if uint32(rune) < Latin1Max {
+       if uint32(rune) <= MaxLatin1 {
                switch rune {
                case '\t', '\n', '\v', '\f', '\r', ' ', 0x85, 0xA0:
                        return true
@@ -125,7 +125,7 @@ func IsSpace(rune int) bool {
 
 // IsSymbol reports whether the rune is a symbolic character.
 func IsSymbol(rune int) bool {
-       if uint32(rune) < Latin1Max {
+       if uint32(rune) <= MaxLatin1 {
                return properties[uint8(rune)]&pS != 0
        }
        return Is(Symbol, rune)
index b15b9747be496bc62ddf26fe16a0438f8408ee9f..77c679f7ce08ff5acb0928cd318a59b0431c2392 100644 (file)
@@ -13,7 +13,7 @@ import (
 // in the Latin-1 range through the property table.
 
 func TestIsControlLatin1(t *testing.T) {
-       for i := 0; i < Latin1Max; i++ {
+       for i := 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 < Latin1Max; i++ {
+       for i := 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 < Latin1Max; i++ {
+       for i := 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 < Latin1Max; i++ {
+       for i := 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 < Latin1Max; i++ {
+       for i := 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 < Latin1Max; i++ {
+       for i := 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 < Latin1Max; i++ {
+       for i := 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 < Latin1Max; i++ {
+       for i := 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 < Latin1Max; i++ {
+       for i := 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 < Latin1Max; i++ {
+       for i := 0; i <= MaxLatin1; i++ {
                got := IsSymbol(i)
                want := Is(Symbol, i)
                if got != want {
index 54df7770392c070f74b5fb405330cdb5b561685f..a0c55bbf78b0f2b69754ffd41ff8d0717129b3be 100644 (file)
@@ -9,8 +9,8 @@ package unicode
 const (
        MaxRune         = 0x10FFFF // Maximum valid Unicode code point.
        ReplacementChar = 0xFFFD   // Represents invalid code points.
-       ASCIIMax        = 0x80     // (1 beyond) maximum ASCII value.
-       Latin1Max       = 0x100    // (1 beyond) maximum Latin-1 value.
+       MaxASCII        = 0x7F     // maximum ASCII value.
+       MaxLatin1       = 0xFF     // maximum Latin-1 value.
 )
 
 // RangeTable defines a set of Unicode code points by listing the ranges of
@@ -123,7 +123,7 @@ 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 {
        // common case: rune is ASCII or Latin-1.
-       if uint32(rune) < Latin1Max {
+       if uint32(rune) <= MaxLatin1 {
                // Only need to check R16, since R32 is always >= 1<<16.
                r16 := uint16(rune)
                for _, r := range rangeTab.R16 {
@@ -151,7 +151,7 @@ func Is(rangeTab *RangeTable, rune int) bool {
 // IsUpper reports whether the rune is an upper case letter.
 func IsUpper(rune int) bool {
        // See comment in IsGraphic.
-       if uint32(rune) < Latin1Max {
+       if uint32(rune) <= MaxLatin1 {
                return properties[uint8(rune)]&pLu != 0
        }
        return Is(Upper, rune)
@@ -160,7 +160,7 @@ func IsUpper(rune int) bool {
 // IsLower reports whether the rune is a lower case letter.
 func IsLower(rune int) bool {
        // See comment in IsGraphic.
-       if uint32(rune) < Latin1Max {
+       if uint32(rune) <= MaxLatin1 {
                return properties[uint8(rune)]&pLl != 0
        }
        return Is(Lower, rune)
@@ -168,7 +168,7 @@ func IsLower(rune int) bool {
 
 // IsTitle reports whether the rune is a title case letter.
 func IsTitle(rune int) bool {
-       if rune < Latin1Max {
+       if rune <= MaxLatin1 {
                return false
        }
        return Is(Title, rune)
@@ -218,7 +218,7 @@ func To(_case int, rune int) int {
 
 // ToUpper maps the rune to upper case.
 func ToUpper(rune int) int {
-       if rune < ASCIIMax {
+       if rune <= MaxASCII {
                if 'a' <= rune && rune <= 'z' {
                        rune -= 'a' - 'A'
                }
@@ -229,7 +229,7 @@ func ToUpper(rune int) int {
 
 // ToLower maps the rune to lower case.
 func ToLower(rune int) int {
-       if rune < ASCIIMax {
+       if rune <= MaxASCII {
                if 'A' <= rune && rune <= 'Z' {
                        rune += 'a' - 'A'
                }
@@ -240,7 +240,7 @@ func ToLower(rune int) int {
 
 // ToTitle maps the rune to title case.
 func ToTitle(rune int) int {
-       if rune < ASCIIMax {
+       if rune <= MaxASCII {
                if 'a' <= rune && rune <= 'z' { // title case is upper case for ASCII
                        rune -= 'a' - 'A'
                }
index 989f9cf9ad8ea56f52b5bec6f508158212e617a0..4c24ffc516fae32a173c1072b75ec9509030bf8c 100644 (file)
@@ -323,7 +323,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 < Latin1Max; i++ {
+       for i := 0; i <= MaxLatin1; i++ {
                if Is(Letter, i) != IsLetter(i) {
                        t.Errorf("IsLetter(U+%04X) disagrees with Is(Letter)", i)
                }
index dd6da4174eb15235c97053c5faad6693b6b91d35..655fe46e427a2e189964842f0a6e35adadab8362 100644 (file)
@@ -919,8 +919,8 @@ func printLatinProperties() {
        if *test {
                return
        }
-       fmt.Println("var properties = [Latin1Max]uint8{")
-       for code := 0; code < unicode.Latin1Max; code++ {
+       fmt.Println("var properties = [MaxLatin1+1]uint8{")
+       for code := 0; code <= unicode.MaxLatin1; code++ {
                var property string
                switch chars[code].category {
                case "Cc", "": // NUL has no category.
index 87c734c8cd7bed2961cacdff64095f38e23a12dd..32681a8c019c82a0f8f5a6c8e55e622040e3e51e 100644 (file)
@@ -5411,7 +5411,7 @@ var _CaseRanges = []CaseRange{
        {0x10400, 0x10427, d{0, 40, 0}},
        {0x10428, 0x1044F, d{-40, 0, -40}},
 }
-var properties = [Latin1Max]uint8{
+var properties = [MaxLatin1 + 1]uint8{
        0x00: pC,       // '\x00'
        0x01: pC,       // '\x01'
        0x02: pC,       // '\x02'