From e3ddfb42a9b80c866f3cd154db018f4e84a39745 Mon Sep 17 00:00:00 2001 From: Aaron Raddon Date: Sun, 15 Jun 2014 12:11:29 -0700 Subject: [PATCH] doc some notes, and fix utf multi byte reads --- parseany.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/parseany.go b/parseany.go index cddd1e2..9ccaf43 100644 --- a/parseany.go +++ b/parseany.go @@ -40,11 +40,17 @@ func ParseAny(datestr string) (time.Time, error) { state := ST_START + // General strategy is to read rune by rune through the date looking for + // certain hints of what type of date we are dealing with. + // Hopefully we only need to read about 5 or 6 bytes before + // we figure it out and then attempt a parse iterRunes: for i := 0; i < len(datestr); i++ { - r, _ := utf8.DecodeRuneInString(datestr[i:]) + r, bytesConsumed := utf8.DecodeRuneInString(datestr[i:]) + if bytesConsumed > 1 { + i += (bytesConsumed - 1) + } - //u.Infof("r=%s st=%d ", string(r), state) switch state { case ST_START: if unicode.IsDigit(r) {