Commit 7a92287a authored by Rob Pike's avatar Rob Pike

unicode: for consistency with MaxRune, s/Latin1Max/MaxLatin1/ and

s/ASCIIMax/MaxASCII/

R=golang-dev, r, gri
CC=golang-dev
https://golang.org/cl/4539109
parent 8d64e73f
......@@ -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)
......
......@@ -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)
}
......
......@@ -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)
......
......@@ -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 {
......
......@@ -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'
}
......
......@@ -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)
}
......
......@@ -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.
......
......@@ -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'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment