summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2015-01-04 17:48:04 +0100
committerHiltjo Posthuma <hiltjo@codemadness.org>2015-01-04 17:48:04 +0100
commit921eb9b5db37cb6e8d463b9a0aee085c8c453c50 (patch)
tree50fced308e9aad8194b8f15c522d3827cfd74eea
parent8f319d6a130e78718fe302586e6080d3ca52ba3d (diff)
sfeed: improve time parsing some more (sscanf in particular)
-rw-r--r--sfeed.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/sfeed.c b/sfeed.c
index 2b313ca..790c660 100644
--- 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])