sfeed

simple feed reader - forked from git.codemadness.org/sfeed
git clone git://src.gearsix.net/sfeed
Log | Files | Refs | Atom | README | LICENSE

commit 921eb9b5db37cb6e8d463b9a0aee085c8c453c50
parent 8f319d6a130e78718fe302586e6080d3ca52ba3d
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun,  4 Jan 2015 17:48:04 +0100

sfeed: improve time parsing some more (sscanf in particular)

Diffstat:
Msfeed.c | 29+++++++++++++++++++++--------
1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/sfeed.c b/sfeed.c @@ -303,24 +303,37 @@ string_append(String *s, const char *data, size_t len) static int gettimetz(const char *s, char *buf, size_t bufsiz, int *tzoffset) { - const char *p; char tzname[16] = ""; int tzhour = 0, tzmin = 0, r; char c = '+'; + size_t i; s = trimstart(s); - /* look until some common timezone delimiters are found */ - if(!(p = strpbrk(s, "+-Zz"))) - goto time_ok; - if(*p == 'Z' || *p == 'z') + if(!*s || *s == 'Z' || *s == 'z') goto time_ok; - if((sscanf(p, "%c%02d:%02d", &c, &tzhour, &tzmin)) > 0) + /* look until some common timezone delimiters are found */ + for(i = 0; s[i] && isalpha((int)s[i]); i++) ; - else if(sscanf(p, "%c%02d%02d", &c, &tzhour, &tzmin) > 0) + /* copy tz name */ + if(i >= sizeof(tzname)) + i = sizeof(tzname) - 1; + if(i > 0) + memcpy(tzname, s, i); + tzname[i] = '\0'; + + if((sscanf(s, "%c%02d:%02d", &c, &tzhour, &tzmin)) == 3) { ; - else if(sscanf(p, "%c%d", &c, &tzhour) > 0) + } else if(sscanf(s, "%c%02d%02d", &c, &tzhour, &tzmin) == 3) { + ; + } else if(sscanf(s, "%c%d", &c, &tzhour) == 2) { + tzmin = 0; + } else { + c = '+'; + tzhour = 0; tzmin = 0; + } + time_ok: /* timezone not defined, assume GMT */ if(!tzname[0])