diff options
Diffstat (limited to 'template.c')
-rw-r--r-- | template.c | 48 |
1 files changed, 41 insertions, 7 deletions
@@ -407,6 +407,7 @@ static void doOptions(unsigned char **pp, struct templateEntry *pTpe) register unsigned char *p; unsigned char Buf[64]; size_t i; + size_t parenlevel = 0; assert(pp != NULL); assert(*pp != NULL); @@ -414,14 +415,29 @@ static void doOptions(unsigned char **pp, struct templateEntry *pTpe) p = *pp; - while(*p && *p != '%') { + while(*p && (parenlevel > 0 || *p != '%')) { /* outer loop - until end of options */ i = 0; while((i < sizeof(Buf) / sizeof(char)) && - *p && *p != '%' && *p != ',') { + *p && (parenlevel > 0 || *p != '%') && *p != ',') + { + char ch = *p++; /* inner loop - until end of ONE option */ - Buf[i++] = tolower((int)*p); - ++p; + + switch (ch) { + case '(': + parenlevel++; + break; + case ')': + parenlevel--; + break; + default: + if (parenlevel == 0) + ch = tolower(ch); + break; + } + + Buf[i++] = ch; } Buf[i] = '\0'; /* terminate */ /* check if we need to skip oversize option */ @@ -442,6 +458,11 @@ static void doOptions(unsigned char **pp, struct templateEntry *pTpe) pTpe->data.field.eDateFormat = tplFmtRFC3339Date; } else if(!strcmp((char*)Buf, "date-subseconds")) { pTpe->data.field.eDateFormat = tplFmtSecFrac; + } else if(!strncmp((char*)Buf, "date-strftime(", 14)) { + char *sft = strdup((char *) Buf + 14); pTpe->data.field.eDateFormat = tplFmtSecFrac; + sft[strcspn(sft, ")")] = 0; + pTpe->data.field.eDateFormat = tplFmtStrftime; + pTpe->data.field.strftime_fmt = sft; } else if(!strcmp((char*)Buf, "lowercase")) { pTpe->data.field.eCaseConv = tplCaseConvLower; } else if(!strcmp((char*)Buf, "uppercase")) { @@ -480,6 +501,7 @@ static int do_Parameter(unsigned char **pp, struct template *pTpl) struct templateEntry *pTpe; int iNum; /* to compute numbers */ rsRetVal iRetLocal; + int parenlevel = 0; #ifdef FEATURE_REGEXP /* APR: variables for regex */ @@ -504,9 +526,21 @@ static int do_Parameter(unsigned char **pp, struct template *pTpl) } pTpe->eEntryType = FIELD; - while(*p && *p != '%' && *p != ':') { - rsCStrAppendChar(pStrB, tolower(*p)); - ++p; /* do NOT do this in tolower()! */ + while(*p && (parenlevel > 0 || (*p != '%' && *p != ':'))) { + char ch = *p++; + switch (ch) { + case '(': + parenlevel++; + break; + case ')': + parenlevel--; + break; + default: + if (parenlevel == 0) + ch = tolower(ch); + break; + } + rsCStrAppendChar(pStrB, ch); } /* got the name*/ |