mirror of https://github.com/golang/go.git
IsSpace
R=rsc DELTA=39 (39 added, 0 deleted, 0 changed) OCL=34153 CL=34167
This commit is contained in:
parent
fe8ff955e9
commit
f9e4f398b6
|
|
@ -117,6 +117,18 @@ func IsLetter(rune int) bool {
|
|||
return Is(Letter, rune);
|
||||
}
|
||||
|
||||
// IsSpace reports whether the rune is a white space character.
|
||||
func IsSpace(rune int) bool {
|
||||
if rune <= 0xFF { // quick Latin-1 check
|
||||
switch rune {
|
||||
case '\t', '\n', '\v', '\f', '\r', ' ', 0x85, 0xA0:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return Is(White_Space, rune);
|
||||
}
|
||||
|
||||
// To maps the rune to the specified case: UpperCase, LowerCase, or TitleCase
|
||||
func To(_case int, rune int) int {
|
||||
if _case < 0 || MaxCase <= _case {
|
||||
|
|
|
|||
|
|
@ -92,6 +92,20 @@ var notletterTest = []int{
|
|||
0x10ffff,
|
||||
}
|
||||
|
||||
// Contains all the special cased Latin-1 chars.
|
||||
var spaceTest = []int{
|
||||
0x09,
|
||||
0x0a,
|
||||
0x0b,
|
||||
0x0c,
|
||||
0x0d,
|
||||
0x20,
|
||||
0x85,
|
||||
0xA0,
|
||||
0x2000,
|
||||
0x3000,
|
||||
}
|
||||
|
||||
type caseT struct {
|
||||
cas, in, out int
|
||||
}
|
||||
|
|
@ -291,3 +305,16 @@ func TestToTitleCase(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsSpace(t *testing.T) {
|
||||
for _, c := range spaceTest {
|
||||
if !IsSpace(c) {
|
||||
t.Errorf("IsSpace(U+%04X) = false; want true", c);
|
||||
}
|
||||
}
|
||||
for _, c := range letterTest {
|
||||
if IsSpace(c) {
|
||||
t.Errorf("IsSpace(U+%04X) = true; want false", c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue