mirror of
https://github.com/golang/go.git
synced 2025-05-29 19:35:42 +00:00
change IsDecimalDigit to IsDigit because Decimal is redundant
R=rsc DELTA=792 (398 added, 383 deleted, 11 changed) OCL=33919 CL=33921
This commit is contained in:
parent
79606b9952
commit
24dfb749c4
@ -188,7 +188,7 @@ func isLetter(ch int) bool {
|
|||||||
func isDigit(ch int) bool {
|
func isDigit(ch int) bool {
|
||||||
return
|
return
|
||||||
'0' <= ch && ch <= '9' ||
|
'0' <= ch && ch <= '9' ||
|
||||||
ch >= 0x80 && unicode.IsDecimalDigit(ch);
|
ch >= 0x80 && unicode.IsDigit(ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ include $(GOROOT)/src/Make.$(GOARCH)
|
|||||||
|
|
||||||
TARG=unicode
|
TARG=unicode
|
||||||
GOFILES=\
|
GOFILES=\
|
||||||
decimaldigit.go\
|
digit.go\
|
||||||
digittables.go\
|
digittables.go\
|
||||||
letter.go\
|
letter.go\
|
||||||
lettertables.go\
|
lettertables.go\
|
||||||
|
@ -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);
|
|
||||||
}
|
|
13
src/pkg/unicode/digit.go
Normal file
13
src/pkg/unicode/digit.go
Normal file
@ -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);
|
||||||
|
}
|
@ -10,7 +10,7 @@ import "testing"
|
|||||||
// grep '^....;[^;]*;Nd;' UnicodeData.txt
|
// grep '^....;[^;]*;Nd;' UnicodeData.txt
|
||||||
// To generate this table:
|
// To generate this table:
|
||||||
// ,s/([^;]+).+/ 0x\1, \/\/ &/g
|
// ,s/([^;]+).+/ 0x\1, \/\/ &/g
|
||||||
var testDecimal = []int{
|
var testDigit = []int{
|
||||||
0x0030, // 0030;DIGIT ZERO;Nd;0;EN;;0;0;0;N;;;;;
|
0x0030, // 0030;DIGIT ZERO;Nd;0;EN;;0;0;0;N;;;;;
|
||||||
0x0031, // 0031;DIGIT ONE;Nd;0;EN;;1;1;1;N;;;;;
|
0x0031, // 0031;DIGIT ONE;Nd;0;EN;;1;1;1;N;;;;;
|
||||||
0x0032, // 0032;DIGIT TWO;Nd;0;EN;;2;2;2;N;;;;;
|
0x0032, // 0032;DIGIT TWO;Nd;0;EN;;2;2;2;N;;;;;
|
||||||
@ -358,15 +358,15 @@ var testLetter = []int{
|
|||||||
0x2fa1d,
|
0x2fa1d,
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIsDecimalDigit(t *testing.T) {
|
func TestDigit(t *testing.T) {
|
||||||
for i, r := range testDecimal {
|
for i, r := range testDigit {
|
||||||
if !IsDecimalDigit(r) {
|
if !IsDigit(r) {
|
||||||
t.Errorf("IsDecimalDigit(%#x) = false, want true\n", r);
|
t.Errorf("IsDigit(%#x) = false, want true\n", r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i, r := range testLetter {
|
for i, r := range testLetter {
|
||||||
if IsDecimalDigit(r) {
|
if IsDigit(r) {
|
||||||
t.Errorf("IsDecimalDigit(%#x) = true, want false\n", r);
|
t.Errorf("IsDigit(%#x) = true, want false\n", r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,12 +1,12 @@
|
|||||||
// Generated by running
|
// 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
|
// DO NOT EDIT
|
||||||
|
|
||||||
package unicode
|
package unicode
|
||||||
|
|
||||||
// DecimalDigit is the set of Unicode characters with the "decimal digit" property.
|
// Digit is the set of Unicode characters with the "decimal digit" (Nd) property.
|
||||||
var DecimalDigit = decimalDigit
|
var Digit = digit
|
||||||
var decimalDigit = []Range {
|
var digit = []Range {
|
||||||
Range{0x0030, 0x0039, 1},
|
Range{0x0030, 0x0039, 1},
|
||||||
Range{0x0660, 0x0669, 1},
|
Range{0x0660, 0x0669, 1},
|
||||||
Range{0x06f0, 0x06f9, 1},
|
Range{0x06f0, 0x06f9, 1},
|
||||||
|
@ -18,8 +18,7 @@ type Range struct {
|
|||||||
func Is(ranges []Range, rune int) bool {
|
func Is(ranges []Range, rune int) bool {
|
||||||
// common case: rune is ASCII or Latin-1
|
// common case: rune is ASCII or Latin-1
|
||||||
if rune < 0x100 {
|
if rune < 0x100 {
|
||||||
for i := 0; i < len(ranges); i++ {
|
for i, r := range ranges {
|
||||||
r := ranges[i];
|
|
||||||
if rune > r.Hi {
|
if rune > r.Hi {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -51,20 +50,33 @@ func Is(ranges []Range, rune int) bool {
|
|||||||
|
|
||||||
// IsUpper reports whether the rune is an upper case letter.
|
// IsUpper reports whether the rune is an upper case letter.
|
||||||
func IsUpper(rune int) bool {
|
func IsUpper(rune int) bool {
|
||||||
|
if rune < 0x80 { // quick ASCII check
|
||||||
|
return 'A' <= rune && rune <= 'Z';
|
||||||
|
}
|
||||||
return Is(Upper, rune);
|
return Is(Upper, rune);
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsLower reports whether the rune is a lower case letter.
|
// IsLower reports whether the rune is a lower case letter.
|
||||||
func IsLower(rune int) bool {
|
func IsLower(rune int) bool {
|
||||||
|
if rune < 0x80 { // quick ASCII check
|
||||||
|
return 'a' <= rune && rune <= 'z';
|
||||||
|
}
|
||||||
return Is(Lower, rune);
|
return Is(Lower, rune);
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsTitle reports whether the rune is a title case letter.
|
// IsTitle reports whether the rune is a title case letter.
|
||||||
func IsTitle(rune int) bool {
|
func IsTitle(rune int) bool {
|
||||||
|
if rune < 0x80 { // quick ASCII check
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return Is(Title, rune);
|
return Is(Title, rune);
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsLetter reports whether the rune is a letter.
|
// IsLetter reports whether the rune is a letter.
|
||||||
func IsLetter(rune int) bool {
|
func IsLetter(rune int) bool {
|
||||||
|
if rune < 0x80 { // quick ASCII check
|
||||||
|
rune &^= ' ';
|
||||||
|
return 'A' <= rune && rune <= 'Z';
|
||||||
|
}
|
||||||
return Is(Letter, rune);
|
return Is(Letter, rune);
|
||||||
}
|
}
|
||||||
|
@ -172,7 +172,7 @@ func main() {
|
|||||||
resp.Body.Close();
|
resp.Body.Close();
|
||||||
fmt.Printf(
|
fmt.Printf(
|
||||||
"// Generated by running\n"
|
"// Generated by running\n"
|
||||||
"// tables --digits=%t --url=%s\n"
|
"// maketables --digits=%t --url=%s\n"
|
||||||
"// DO NOT EDIT\n\n"
|
"// DO NOT EDIT\n\n"
|
||||||
"package unicode\n",
|
"package unicode\n",
|
||||||
*digits,
|
*digits,
|
||||||
@ -183,9 +183,9 @@ func main() {
|
|||||||
// available to clients.
|
// available to clients.
|
||||||
if *digits {
|
if *digits {
|
||||||
dumpRange(
|
dumpRange(
|
||||||
"\n// DecimalDigit is the set of Unicode characters with the \"decimal digit\" property.\n"
|
"\n// Digit is the set of Unicode characters with the \"decimal digit\" (Nd) property.\n"
|
||||||
"var DecimalDigit = decimalDigit\n"
|
"var Digit = digit\n"
|
||||||
"var decimalDigit = []Range {\n",
|
"var digit = []Range {\n",
|
||||||
func(code int) bool { return chars[code].category == "Nd" },
|
func(code int) bool { return chars[code].category == "Nd" },
|
||||||
"}\n"
|
"}\n"
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user