From: Wilfried Goesgens Date: Mon, 3 Sep 2012 21:24:59 +0000 (+0200) Subject: SUBST: add a way to post plain char* strings into template strings in a formated way X-Git-Tag: v8.20~233 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=82f8cebefd325c7eb8b98c6025bd43633fa9cd90 SUBST: add a way to post plain char* strings into template strings in a formated way --- diff --git a/webcit/subst.c b/webcit/subst.c index 7443515e7..1370ca5b5 100644 --- a/webcit/subst.c +++ b/webcit/subst.c @@ -694,6 +694,55 @@ void StrBufAppendTemplate(StrBuf *Target, } } +/* + * puts string into the template and computes which escape methon we should use + * Source = the string we should put into the template + * FormatTypeIndex = where should we look for escape types if? + */ +void StrBufAppendTemplateStr(StrBuf *Target, + WCTemplputParams *TP, + const char *Source, int FormatTypeIndex) +{ + const char *pFmt = NULL; + char EscapeAs = ' '; + + if ((FormatTypeIndex < TP->Tokens->nParameters) && + (TP->Tokens->Params[FormatTypeIndex]->Type == TYPE_STR) && + (TP->Tokens->Params[FormatTypeIndex]->len >= 1)) { + pFmt = TP->Tokens->Params[FormatTypeIndex]->Start; + EscapeAs = *pFmt; + } + + switch(EscapeAs) + { + case 'H': + StrEscAppend(Target, NULL, Source, 0, 2); + break; + case 'X': + StrEscAppend(Target, NULL, Source, 0, 0); + break; + case 'J': + StrECMAEscAppend(Target, NULL, Source); + break; + case 'K': + StrHtmlEcmaEscAppend(Target, NULL, Source, 0, 0); + break; + case 'U': + StrBufUrlescAppend(Target, NULL, Source); + break; +/* + case 'F': + if (pFmt != NULL) pFmt++; + else pFmt = "JUSTIFY"; + if (*pFmt == '\0') pFmt = "JUSTIFY"; + FmOut(Target, pFmt, Source); + break; +*/ + default: + StrBufAppendBufPlain(Target, Source, 0, 0); + } +} + void PutNewToken(WCTemplate *Template, WCTemplateToken *NewToken) { diff --git a/webcit/subst.h b/webcit/subst.h index 56b5d1947..86b76d690 100644 --- a/webcit/subst.h +++ b/webcit/subst.h @@ -268,6 +268,11 @@ void StrBufAppendTemplate(StrBuf *Target, const StrBuf *Source, int FormatTypeIndex); +void StrBufAppendTemplateStr(StrBuf *Target, + WCTemplputParams *TP, + const char *Source, + int FormatTypeIndex); + #define RegisterNamespace(a, b, c, d, e, f) RegisterNS(a, sizeof(a)-1, b, c, d, e, f) /**