看來ISDIGIT和ISNUMBER在Unicode包不表現不同,至少在我的下面的測試代碼:的差異unicode的圍棋
package main
import "fmt"
import "unicode"
func main() {
r := rune('1')
fmt.Println(unicode.IsDigit(r))
fmt.Println(unicode.IsNumber(r))
//true
//true
}
他們都打印true
。
我試圖從他們的源代碼中瞭解。但是,我仍然不明白它們之間的差異,甚至不知道它們的源代碼。
// IsNumber reports whether the rune is a number (category N).
func IsNumber(r rune) bool {
if uint32(r) <= MaxLatin1 {
return properties[uint8(r)]&pN != 0
}
return isExcludingLatin(Number, r)
}
// IsDigit reports whether the rune is a decimal digit.
func IsDigit(r rune) bool {
if r <= MaxLatin1 {
return '0' <= r && r <= '9'
}
return isExcludingLatin(Digit, r)
}