Skip to content

Commit

Permalink
fix a stupid error in ParsePubDate
Browse files Browse the repository at this point in the history
  • Loading branch information
mawenbao committed Mar 20, 2014
1 parent a81abaa commit d0592bf
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strconv"
"strings"
"time"
"unicode"
)

// return later time
Expand Down Expand Up @@ -190,7 +189,7 @@ func ParsePubDate(formatReg *regexp.Regexp, dateStr string) (time.Time, error) {
return time.Time{}, errors.New("date format regexp is nil")
}

pubdateStr := TrimAllSpaces(dateStr)
pubdateStr := strings.TrimSpace(dateStr)
if "" == pubdateStr {
log.Printf("[ERROR] error parsing pubdate, pubdate string is empty")
return time.Time{}, errors.New("pubdate string is empty")
Expand All @@ -204,7 +203,7 @@ func ParsePubDate(formatReg *regexp.Regexp, dateStr string) (time.Time, error) {
minute := now.Minute()
second := now.Second()

match := formatReg.FindSubmatch([]byte(dateStr))
match := formatReg.FindSubmatch([]byte(pubdateStr))
if nil == match {
log.Printf("[ERROR] error parsing pubdate %s, pattern %s match failed", pubdateStr, formatReg.String())
return time.Time{}, errors.New("failed to match pubdate pattern")
Expand Down Expand Up @@ -324,17 +323,3 @@ func GenPDPRegexStr(pdp string, nonEmpty bool, nonGreedy bool) string {

return regStr + `)`
}

// trim all spaces including normal white-spaces, and full-length space(U+3000)
func TrimAllSpaces(source string) string {
return strings.TrimFunc(source, func(r rune) bool {
if unicode.IsSpace(r) {
return true
}
switch r {
case '\u3000':
return true
}
return false
})
}

0 comments on commit d0592bf

Please sign in to comment.