From 33361167a5d9850edfdfaf17b76b1271768a309b Mon Sep 17 00:00:00 2001 From: visor Date: Wed, 16 Dec 2009 00:16:25 +0900 Subject: [PATCH] escape-wiki function. fix date inline command of wiki. --- modules/ml-bool.cc | 15 +++++++++++++++ modules/ml-bool.h | 1 + modules/ml-encode.cc | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ modules/ml-encode.h | 1 + wiki/wikiline.cc | 20 ++++++++++++-------- wiki/wikimotor.cc | 2 +- 6 files changed, 78 insertions(+), 9 deletions(-) diff --git a/modules/ml-bool.cc b/modules/ml-bool.cc index d32ff9b..c7ed756 100644 --- a/modules/ml-bool.cc +++ b/modules/ml-bool.cc @@ -40,6 +40,21 @@ MNode* ml_nullp (MNode* cell, MlEnv* mlenv) { } /*DOC: +===not-null=== + (not-null VALUE) -> 1 or NIL + (not-nullp VALUE) -> 1 or NIL + +*/ +//#AWFUNC not-null ml_not_nullp +//#AWFUNC not-nullp ml_not_nullp +MNode* ml_not_nullp (MNode* cell, MlEnv* mlenv) { + MNodePtr obj; + + objType (cell, mlenv, obj); + return newMNode_bool (obj () != NULL && ! obj ()->isNil ()); +} + +/*DOC: ===consp=== (consp VALUE) diff --git a/modules/ml-bool.h b/modules/ml-bool.h index a62f484..fa6abe8 100644 --- a/modules/ml-bool.h +++ b/modules/ml-bool.h @@ -5,6 +5,7 @@ class MNode; class MlEnv; MNode* ml_nullp (MNode* cell, MlEnv* mlenv); +MNode* ml_not_nullp (MNode* cell, MlEnv* mlenv); MNode* ml_consp (MNode* cell, MlEnv* mlenv); MNode* ml_stringp (MNode* cell, MlEnv* mlenv); MNode* ml_symbolp (MNode* cell, MlEnv* mlenv); diff --git a/modules/ml-encode.cc b/modules/ml-encode.cc index e09d5cd..41aebcb 100644 --- a/modules/ml-encode.cc +++ b/modules/ml-encode.cc @@ -96,3 +96,51 @@ MNode* ml_decode_control_char (MNode* cell, MlEnv* mlenv) { return newMNode_str (new ustring (slashDecode (str))); } + + +/*DOC: +===escape-wiki=== + (escape-wiki STRING ...) -> STRING + +*/ +//#AFUNC escape-wiki ml_escape_wiki +//#WIKIFUNC escape-wiki ml_escape_wiki +MNode* ml_escape_wiki (MNode* cell, MlEnv* mlenv) { + MNode* arg = cell->cdr (); + ustring text; + ustring ans; + uiterator b, e; + umatch m; + static uregex re ("(\\[)|(&)|(
)|('')|(\\|)|(\n)"); + + while (arg) { + text.append (eval_str (arg->car (), mlenv)); + nextNode (arg); + } + b = text.begin (); + e = text.end (); + while (b < e && usearch (b, e, m, re)) { + if (b < m[0].first) + ans.append (b, m[0].first); + if (m[1].matched) { + ans.append (CharConst ("&[;")); + } else if (m[2].matched) { + ans.append (CharConst ("&&;")); + } else if (m[3].matched) { + ans.append (CharConst ("&<;br>")); + } else if (m[4].matched) { + ans.append (CharConst ("'&';")); + } else if (m[5].matched) { + ans.append (CharConst ("&|;")); + } else if (m[6].matched) { + ans.append (CharConst (" ")); + } else { + assert (0); + } + b = m[0].second; + } + if (b < e) + ans.append (b, e); + + return newMNode_str (new ustring (ans)); +} diff --git a/modules/ml-encode.h b/modules/ml-encode.h index 4e686dc..dbfb0a6 100644 --- a/modules/ml-encode.h +++ b/modules/ml-encode.h @@ -8,5 +8,6 @@ MNode* ml_js (MNode* cell, MlEnv* mlenv); MNode* ml_escape_regexp (MNode* cell, MlEnv* mlenv); MNode* ml_encode_control_char (MNode* cell, MlEnv* mlenv); MNode* ml_decode_control_char (MNode* cell, MlEnv* mlenv); +MNode* ml_escape_wiki (MNode* cell, MlEnv* mlenv); #endif /* ML_ENCODE_H */ diff --git a/wiki/wikiline.cc b/wiki/wikiline.cc index 0d364f6..d97b42d 100644 --- a/wiki/wikiline.cc +++ b/wiki/wikiline.cc @@ -667,19 +667,23 @@ bool wl_pad0 (WikiMotorObjVecVec* args, MotorOutput* out, WikiFormat* wiki) { bool wl_date (WikiMotorObjVecVec* args, WikiMotorObjVec* arg2, MotorOutput* out, WikiFormat* wiki) { WikiMotorObjVecVec::const_iterator b = args->begin (); WikiMotorObjVecVec::const_iterator e = args->end (); + ustring val; time_t tm; ustring format; boost::ptr_vector par; if (b < e) { - tm = strtol ((*b)->textOut (wiki)); - if (arg2->size () > 0) - format = arg2->textOut (wiki); - else - format = uTimeFormat; - - datetime_list (par, tm); - out->out_HTML (formatDateString (format, par)); + val = (*b)->textOut (wiki); + if (val.length () > 0) { + tm = strtol (val); + if (arg2->size () > 0) + format = arg2->textOut (wiki); + else + format = uTimeFormat; + + datetime_list (par, tm); + out->out_HTML (formatDateString (format, par)); + } return true; } diff --git a/wiki/wikimotor.cc b/wiki/wikimotor.cc index 6677754..a6212aa 100644 --- a/wiki/wikimotor.cc +++ b/wiki/wikimotor.cc @@ -54,7 +54,7 @@ uregex re_wiki1 ( void WikiMotorObjVec::out (MotorOutputString& o, WikiFormat* wiki) { const_iterator b = begin (); const_iterator e = end (); -// for (int i = 0; i < size (); i ++) { + for (; b < e; b ++) { o.out ((*b)->textOut (wiki)); } -- 2.11.0