diff options
| author | Rob Pike <r@golang.org> | 2009-08-26 16:53:07 -0700 |
|---|---|---|
| committer | Rob Pike <r@golang.org> | 2009-08-26 16:53:07 -0700 |
| commit | 71b2e367112fd4333577e29b96cc981e26890808 (patch) | |
| tree | 3f79f279b03e6db136894a23d3939136b7d89d96 /src | |
| parent | 152c80ae1bbae5a906bd67608e01025f8fb61662 (diff) | |
| download | golang-71b2e367112fd4333577e29b96cc981e26890808.tar.gz | |
change IsDecimalDigit to IsDigit because Decimal is redundant
R=rsc
DELTA=792 (398 added, 383 deleted, 11 changed)
OCL=33919
CL=33921
Diffstat (limited to 'src')
| -rw-r--r-- | src/pkg/go/scanner/scanner.go | 2 | ||||
| -rw-r--r-- | src/pkg/unicode/Makefile | 2 | ||||
| -rw-r--r-- | src/pkg/unicode/decimaldigit.go | 10 | ||||
| -rw-r--r-- | src/pkg/unicode/digit.go | 13 | ||||
| -rw-r--r-- | src/pkg/unicode/digit_test.go (renamed from src/pkg/unicode/decimaldigit_test.go) | 14 | ||||
| -rw-r--r-- | src/pkg/unicode/digittables.go | 8 | ||||
| -rw-r--r-- | src/pkg/unicode/letter.go | 16 | ||||
| -rw-r--r-- | src/pkg/unicode/maketables.go | 8 |
8 files changed, 44 insertions, 29 deletions
diff --git a/src/pkg/go/scanner/scanner.go b/src/pkg/go/scanner/scanner.go index 9a040aa6c..c4a5ad838 100644 --- a/src/pkg/go/scanner/scanner.go +++ b/src/pkg/go/scanner/scanner.go @@ -188,7 +188,7 @@ func isLetter(ch int) bool { func isDigit(ch int) bool { return '0' <= ch && ch <= '9' || - ch >= 0x80 && unicode.IsDecimalDigit(ch); + ch >= 0x80 && unicode.IsDigit(ch); } diff --git a/src/pkg/unicode/Makefile b/src/pkg/unicode/Makefile index da3183039..717af36af 100644 --- a/src/pkg/unicode/Makefile +++ b/src/pkg/unicode/Makefile @@ -6,7 +6,7 @@ include $(GOROOT)/src/Make.$(GOARCH) TARG=unicode GOFILES=\ - decimaldigit.go\ + digit.go\ digittables.go\ letter.go\ lettertables.go\ diff --git a/src/pkg/unicode/decimaldigit.go b/src/pkg/unicode/decimaldigit.go deleted file mode 100644 index b6b438812..000000000 --- a/src/pkg/unicode/decimaldigit.go +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package unicode - -// IsDecimalDigit reports whether the rune is a decimal digit. -func IsDecimalDigit(rune int) bool { - return Is(DecimalDigit, rune); -} diff --git a/src/pkg/unicode/digit.go b/src/pkg/unicode/digit.go new file mode 100644 index 000000000..b12ada2d6 --- /dev/null +++ b/src/pkg/unicode/digit.go @@ -0,0 +1,13 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package unicode + +// IsDigit reports whether the rune is a decimal digit. +func IsDigit(rune int) bool { + if rune < 0x100 { // quick ASCII (Latin-1, really) check + return '0' <= rune && rune <= '9' + } + return Is(Digit, rune); +} diff --git a/src/pkg/unicode/decimaldigit_test.go b/src/pkg/unicode/digit_test.go index 05d75b4b2..02d063746 100644 --- a/src/pkg/unicode/decimaldigit_test.go +++ b/src/pkg/unicode/digit_test.go @@ -10,7 +10,7 @@ import "testing" // grep '^....;[^;]*;Nd;' UnicodeData.txt // To generate this table: // ,s/([^;]+).+/ 0x\1, \/\/ &/g -var testDecimal = []int{ +var testDigit = []int{ 0x0030, // 0030;DIGIT ZERO;Nd;0;EN;;0;0;0;N;;;;; 0x0031, // 0031;DIGIT ONE;Nd;0;EN;;1;1;1;N;;;;; 0x0032, // 0032;DIGIT TWO;Nd;0;EN;;2;2;2;N;;;;; @@ -358,15 +358,15 @@ var testLetter = []int{ 0x2fa1d, } -func TestIsDecimalDigit(t *testing.T) { - for i, r := range testDecimal { - if !IsDecimalDigit(r) { - t.Errorf("IsDecimalDigit(%#x) = false, want true\n", r); +func TestDigit(t *testing.T) { + for i, r := range testDigit { + if !IsDigit(r) { + t.Errorf("IsDigit(%#x) = false, want true\n", r); } } for i, r := range testLetter { - if IsDecimalDigit(r) { - t.Errorf("IsDecimalDigit(%#x) = true, want false\n", r); + if IsDigit(r) { + t.Errorf("IsDigit(%#x) = true, want false\n", r); } } } diff --git a/src/pkg/unicode/digittables.go b/src/pkg/unicode/digittables.go index f0b11a5b6..eaea4253a 100644 --- a/src/pkg/unicode/digittables.go +++ b/src/pkg/unicode/digittables.go @@ -1,12 +1,12 @@ // Generated by running -// tables --digits=true --url=http://www.unicode.org/Public/5.1.0/ucd/UnicodeData.txt +// maketables --digits=true --url=http://www.unicode.org/Public/5.1.0/ucd/UnicodeData.txt // DO NOT EDIT package unicode -// DecimalDigit is the set of Unicode characters with the "decimal digit" property. -var DecimalDigit = decimalDigit -var decimalDigit = []Range { +// Digit is the set of Unicode characters with the "decimal digit" (Nd) property. +var Digit = digit +var digit = []Range { Range{0x0030, 0x0039, 1}, Range{0x0660, 0x0669, 1}, Range{0x06f0, 0x06f9, 1}, diff --git a/src/pkg/unicode/letter.go b/src/pkg/unicode/letter.go index f0e9db2ae..c625e9068 100644 --- a/src/pkg/unicode/letter.go +++ b/src/pkg/unicode/letter.go @@ -18,8 +18,7 @@ type Range struct { func Is(ranges []Range, rune int) bool { // common case: rune is ASCII or Latin-1 if rune < 0x100 { - for i := 0; i < len(ranges); i++ { - r := ranges[i]; + for i, r := range ranges { if rune > r.Hi { continue; } @@ -51,20 +50,33 @@ func Is(ranges []Range, rune int) bool { // IsUpper reports whether the rune is an upper case letter. func IsUpper(rune int) bool { + if rune < 0x80 { // quick ASCII check + return 'A' <= rune && rune <= 'Z'; + } return Is(Upper, rune); } // IsLower reports whether the rune is a lower case letter. func IsLower(rune int) bool { + if rune < 0x80 { // quick ASCII check + return 'a' <= rune && rune <= 'z'; + } return Is(Lower, rune); } // IsTitle reports whether the rune is a title case letter. func IsTitle(rune int) bool { + if rune < 0x80 { // quick ASCII check + return false; + } return Is(Title, rune); } // IsLetter reports whether the rune is a letter. func IsLetter(rune int) bool { + if rune < 0x80 { // quick ASCII check + rune &^= ' '; + return 'A' <= rune && rune <= 'Z'; + } return Is(Letter, rune); } diff --git a/src/pkg/unicode/maketables.go b/src/pkg/unicode/maketables.go index 466813611..6a7ac3d32 100644 --- a/src/pkg/unicode/maketables.go +++ b/src/pkg/unicode/maketables.go @@ -172,7 +172,7 @@ func main() { resp.Body.Close(); fmt.Printf( "// Generated by running\n" - "// tables --digits=%t --url=%s\n" + "// maketables --digits=%t --url=%s\n" "// DO NOT EDIT\n\n" "package unicode\n", *digits, @@ -183,9 +183,9 @@ func main() { // available to clients. if *digits { dumpRange( - "\n// DecimalDigit is the set of Unicode characters with the \"decimal digit\" property.\n" - "var DecimalDigit = decimalDigit\n" - "var decimalDigit = []Range {\n", + "\n// Digit is the set of Unicode characters with the \"decimal digit\" (Nd) property.\n" + "var Digit = digit\n" + "var digit = []Range {\n", func(code int) bool { return chars[code].category == "Nd" }, "}\n" ); |
