1
0
mirror of https://github.com/golang/go synced 2024-11-21 23:44:39 -07:00

time: make month/day name comparisons case insenstive

Fixes #2324.

R=r, r
CC=golang-dev
https://golang.org/cl/5180044
This commit is contained in:
Paul Borman 2011-10-04 12:52:30 -07:00 committed by Rob Pike
parent e2d326b878
commit 93b8438e59
2 changed files with 22 additions and 1 deletions

View File

@ -232,9 +232,27 @@ var longMonthNames = []string{
"December",
}
// match returns true if s1 and s2 match ignoring case.
// It is assumed s1 and s2 are the same length.
func match(s1, s2 string) bool {
for i := 0; i < len(s1); i++ {
c1 := s1[i]
c2 := s2[i]
if c1 != c2 {
// Switch to lower-case; 'a'-'A' is known to be a single bit.
c1 |= 'a' - 'A'
c2 |= 'a' - 'A'
if c1 != c2 || c1 < 'a' || c1 > 'z' {
return false
}
}
}
return true
}
func lookup(tab []string, val string) (int, string, os.Error) {
for i, v := range tab {
if len(val) >= len(v) && val[0:len(v)] == v {
if len(val) >= len(v) && match(val[0:len(v)], v) {
return i, val[len(v):], nil
}
}

View File

@ -252,6 +252,9 @@ var parseTests = []ParseTest{
// Amount of white space should not matter.
{"ANSIC", ANSIC, "Thu Feb 4 21:00:57 2010", false, true, 1, 0},
{"ANSIC", ANSIC, "Thu Feb 4 21:00:57 2010", false, true, 1, 0},
// Case should not matter
{"ANSIC", ANSIC, "THU FEB 4 21:00:57 2010", false, true, 1, 0},
{"ANSIC", ANSIC, "thu feb 4 21:00:57 2010", false, true, 1, 0},
// Fractional seconds.
{"millisecond", "Mon Jan _2 15:04:05.000 2006", "Thu Feb 4 21:00:57.012 2010", false, true, 1, 3},
{"microsecond", "Mon Jan _2 15:04:05.000000 2006", "Thu Feb 4 21:00:57.012345 2010", false, true, 1, 6},