似乎unicode包中的IsDigit和IsNumber的行为不同,至少在我的下面的测试代码中:
package main
import "fmt"
import "unicode"
func main() {
r := rune('1')
fmt.Println(unicode.IsDigit(r))
fmt.Println(unicode.IsNumber(r))
//true
//true
}
Run Code Online (Sandbox Code Playgroud)
他们都打印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)
}
Run Code Online (Sandbox Code Playgroud)
pet*_*rSO 18
一般类别是数字,子类别是十进制数字.
4.5一般类别
Run Code Online (Sandbox Code Playgroud)Nd = Number, decimal digit Nl = Number, letter No = Number, other4.6数值
Numeric_Value和Numeric_Type是表示数字的字符的标准属性.
十进制数字.
通常理解的十进制数字是用于形成十进制数字的数字.
例如,
package main
import (
"fmt"
"unicode"
)
func main() {
digit := rune('1')
fmt.Println(unicode.IsDigit(digit))
fmt.Println(unicode.IsNumber(digit))
letter := rune('?')
fmt.Println(unicode.IsDigit(letter))
fmt.Println(unicode.IsNumber(letter))
other := rune('½')
fmt.Println(unicode.IsDigit(other))
fmt.Println(unicode.IsNumber(other))
}
Run Code Online (Sandbox Code Playgroud)
输出:
true
true
false
true
false
true
Run Code Online (Sandbox Code Playgroud)
据我所知IsDigit()是您的子集,IsNumber()所以您得到的结果很好,因为两者都应求和true。的IsNumber是使用以确定它是否是任何数值Unicode类别和IsDigit()检查它是否是一个基数为10位数..
| 归档时间: |
|
| 查看次数: |
5162 次 |
| 最近记录: |