small fix.
}
}
+bool to_bool (const ustring& v) {
+ return ! (v.length () == 0 || (v.length () == 1 && v[0] == '0'));
+}
+
bool MNode::to_bool () {
+ // 空文字列,文字列の"0",数値の0,nilはfalse
switch (type) {
case MNode::MC_NIL:
return false;
case MNode::MC_STR:
return ::to_bool (*str);
case MNode::MC_SYM:
- if (sym->length () > 0) {
+ if (sym->length () > 0) { // nilというシンボルはnilではない
return true;
} else {
return false;
}
}
-ustring MNode::to_string (bool c, bool listdump) {
+ustring MNode::cons_to_sexp (bool fcdr) {
+ // fcdr: cdr部の出力
+ ustring ans;
+
+ assert (type == MC_CONS);
+ if (! fcdr
+ && cons.car && cons.car->type == MC_SYM && cons.car->str->compare ("quote") == 0
+ && cons.cdr && cons.cdr->type == MC_CONS
+ && ::isNil (cons.cdr->cons.cdr)) {
+ ans.append (CharConst ("'"));
+ if (::isNil (cons.cdr->cons.car))
+ ans.append (uNil2);
+ else
+ ans.append (cons.cdr->cons.car->to_sexp ());
+ } else {
+ if (! fcdr)
+ ans.append (CharConst ("("));
+ if (::isNil (cons.car))
+ ans.append (uNil2);
+ else
+ ans.append (cons.car->to_sexp ());
+ if (::isNil (cons.cdr)) {
+ ans.append (CharConst (")"));
+ } else {
+ switch (cons.cdr->type) {
+ case MC_CONS:
+ ans.append (uSPC);
+ ans.append (cons.cdr->cons_to_sexp (true));
+ break;
+ default:
+ ans.append (CharConst (" . "));
+ ans.append (cons.cdr->to_sexp ());
+ ans.append (CharConst (")"));
+ }
+ }
+ }
+ return ans;
+}
+
+ustring MNode::to_sexp () {
switch (type) {
case MNode::MC_NIL:
- return uEmpty;
+ return uNil2;
case MNode::MC_CONS:
- {
- ustring ans;
- if (! c && cons.car && cons.car->type == MC_SYM && cons.car->str->compare ("quote") == 0 && cons.cdr && cons.cdr->type == MC_CONS) {
- ans.append (CharConst ("'"));
- if (! cons.cdr->cons.car)
- ans.append (uNil2);
- else
- ans.append (cons.cdr->cons.car->to_string (false, true));
- } else {
- if (! c)
- ans.append (CharConst ("("));
- if (cons.car)
- ans.append (cons.car->to_string (false, true));
- else
- ans.append (uNil2);
- if (cons.cdr) {
- switch (cons.cdr->type) {
- case MC_NIL:
- ans.append (CharConst (")"));
- break;
- case MC_CONS:
- ans.append (uSPC);
- ans.append (cons.cdr->to_string (true, true));
- break;
- default:
- ans.append (CharConst (" . "));
- ans.append (cons.cdr->to_string (true, true));
- ans.append (CharConst (")"));
- }
- } else {
- ans.append (CharConst (")"));
- }
- }
- return ans;
- }
+ return cons_to_sexp ();
case MNode::MC_STR:
- if (listdump) {
- return uQ2 + slashEncode (*str) + uQ2;
- } else {
- return ustring (*str);
-// return *str;
- }
+ return uQ2 + slashEncode (*str) + uQ2;
case MNode::MC_SYM:
- return ustring (*sym);
-// return *sym;
+ return *sym;
case MNode::MC_DOUBLE:
return to_ustring (real);
default:
}
}
-void MNode::dump (std::ostream& o, bool c) {
+ustring MNode::to_string () {
switch (type) {
- case MC_NIL:
-// o << uNil;
- o << uNil2;
- break;
- case MC_SYM:
- o << logText (*sym);
- break;
- case MC_STR:
- o << uQ2 << logText (*str) << uQ2;
- break;
- case MC_CONS:
- if (! c && car () && car ()->type == MC_SYM && car ()->str->compare ("quote") == 0 && cdr () && cdr ()->type == MC_CONS) {
- o << "'";
- if (! cdr ()->car ())
- o << uNil2;
- else
- cdr ()->car ()->dump (o);
- } else {
- if (! c)
- o << "(";
- if (car ())
- car ()->dump (o);
- else
- o << uNil2;
- if (cdr ()) {
- switch (cdr ()->type) {
- case MC_NIL:
- o << ")";
- break;
- case MC_CONS:
- o << " ";
- cdr ()->dump (o, true);
- break;
- default:
- o << " . ";
- cdr ()->dump (o, true);
- o << ")";
- }
- } else {
- o << ")";
- }
- }
- break;
- case MC_DOUBLE:
- o << to_ustring (real);
- break;
+ case MNode::MC_NIL:
+ return uEmpty;
+ case MNode::MC_CONS:
+ return cons_to_sexp ();
+ case MNode::MC_STR:
+ return *str;
+ case MNode::MC_SYM:
+ return *sym;
+ case MNode::MC_DOUBLE:
+ return to_ustring (real);
default:
assert (0);
}
}
+void MNode::dump (std::ostream& o, bool c) {
+ o << logText (to_sexp ());
+}
+
ustring MNode::dump_string (bool c) {
- switch (type) {
- case MC_NIL:
-// return uNil;
- return uNil2;
- case MC_CONS:
- {
- ustring ans;
- if (! c && car () && car ()->type == MC_SYM && car ()->str->compare ("quote") == 0 && cdr () && cdr ()->type == MC_CONS) {
- ans.append (CharConst ("'"));
- if (! cdr ()->car ())
- ans.append (uNil2);
- else
- ans.append (cdr ()->car ()->dump_string ());
- } else {
- if (! c)
- ans.append (CharConst ("("));
- if (car ())
- ans.append (car ()->dump_string ());
- else
- ans.append (uNil2);
- if (cdr ()) {
- switch (cdr ()->type) {
- case MC_NIL:
- ans.append (CharConst (")"));
- break;
- case MC_CONS:
- ans.append (uSPC);
- ans.append (cdr ()->dump_string (true));
- break;
- default:
- ans.append (CharConst (" . "));
- ans.append (cdr ()->dump_string (true));
- ans.append (CharConst (")"));
- }
- } else {
- ans.append (CharConst (")"));
- }
- }
- return ans;
- }
- case MC_STR:
- return uQ2 + logText (*str) + uQ2;
- case MC_SYM:
- return logText (*sym);
- case MC_DOUBLE:
- return to_ustring (real);
- default:
- if (type == MC_DELETED)
- std::cerr << "type:DELETED\n";
- else
- std::cerr << "type:" << type << "\n";
- assert (0);
- }
+ return logText (to_sexp ());
}
ustring MNode::dump_string_short () {
if (! arg)
throw (uErrorWrongNumber);
}
-
return (int)to_double ();
};
bool to_bool ();
- ustring to_string (bool c = false, bool listdump = false);
+ ustring cons_to_sexp (bool fcdr = false);
+ ustring to_sexp ();
+ ustring to_string ();
void dump (std::ostream& o, bool c = false);
ustring dump_string (bool c = false);
ustring dump_string_short ();
return (int)to_double (c);
}
+bool to_bool (const ustring& v);
inline bool to_bool (MNode* c) {
if (c)
return c->to_bool ();
return uEmpty;
}
+inline ustring dump_to_sexp (MNode* c) {
+ if (c)
+ return c->to_sexp ();
+ else
+ return uNil2;
+}
+
inline MNode* newMNode_sym (ustring* v) {
MNode* ans = new MNode;
ans->set_sym (v);
return omitPattern (str, re);
}
-bool to_bool (const ustring& v) {
- if (v.length () == 0 || (v.length () == 1 && v[0] == '0')) {
- return false;
- } else {
- return true;
- }
-}
-
-#if 0
-static ustring percentEncode (const ustring& text, uregex& re) {
- /* $1 -> _
- $2 -> %HEX
- */
- umatch m;
- uiterator b, e;
- ustring ans;
-
- b = text.begin ();
- e = text.end ();
- if (b != e && usearch (b, e, m, re)) {
- if (b != m[0].first) {
- ans.append (ustring (b, m[0].first));
- }
- if (m[1].matched) {
- ans.append (uUScore);
- } else if (m[2].matched) {
- ans.append (percentHex (*m[2].first));
- } else {
- assert (0);
- }
- b = m[0].second;
- while (b != e && usearch (b, e, m, re)) {
- if (b != m[0].first) {
- ans.append (ustring (b, m[0].first));
- }
- if (m[1].matched) {
- ans.append (uUScore);
- } else if (m[2].matched) {
- ans.append (percentHex (*m[2].first));
- } else {
- assert (0);
- }
- b = m[0].second;
- }
- if (b != e) {
- ans.append (ustring (b, e));
- }
- return ans;
- } else {
- return text;
- }
-}
-#endif
-
static ustring percentEncode (uiterator b, uiterator e, const uregex& re) {
// $1 -> _
// $2 -> %HEX
return ans;
}
-#if 0
-ustring urlencode (const ustring& url) {
- static uregex re ("(\\x00)|([^a-zA-Z0-9_.,/\x80-\xff-])");
-
- return percentEncode (url, re);
-}
-#endif
-
ustring percentEncode (uiterator b, uiterator e) {
static uregex re ("(\\x00)|([^A-Za-z0-9_.~-])");
return ans;
}
-#if 0
-ustring dirPart (char* path) {
- char* e = rindex (path, '/');
-
- if (e && e != path) {
- return ustring (path, e - path);
- } else {
- return uSlash;
- }
-}
-#endif
-
ustring dirPart (const ustring& path) {
ustring::size_type s = path.rfind ('/', path.size ());
}
}
-#if 0
-void toLower (ustring::iterator* b, ustring::iterator* e) {
- transform (*b, *e, *b, toLower_ustring_value);
-}
-#endif
-
ustring toLower (uiterator b, uiterator e) {
ustring::iterator i;
ustring ans;
ustring omitNL (const ustring& str);
ustring omitNonAscii (const ustring& str);
ustring omitNonAsciiWord (const ustring& str);
-bool to_bool (const ustring& v);
ustring percentEncode (uiterator b, uiterator e);
ustring percentEncode (const ustring& str);
ustring percentEncode_path (uiterator b, uiterator e);
ustring cookieencode (const ustring& text);
ustring cookiedecode (const ustring& text);
ustring clipColon (const ustring& text);
-//ustring dirPart (char* path);
ustring dirPart (const ustring& path);
ustring filePart_osSafe (const ustring& path);
void split (uiterator b, uiterator e, uregex& re, std::vector<ustring>& ans);
class MNodePtr;
ustring formatString (const ustring& format, boost::ptr_vector<MNodePtr>& par);
-//ustring formatDateString (const ustring& format, time_t tm);
ustring formatDateString (const ustring& format, struct tm& v);
ustring toLower (const ustring& str);
ustring toUpper (const ustring& str);
nextNode (arg);
if (text.length () > 0)
text.append (CharConst (" "));
- if (isNil (e ())) {
- text.append (uNil2);
- } else if (e ()->isStr ()) {
- text.append (uQ2).append (slashEncode (*e ()->str)).append (uQ2);
- } else {
- text.append (e ()->to_string ());
- }
+ text.append (dump_to_sexp (e ()));
}
return newMNode_str (new ustring (text));
}
return mlenv->getAry_string (name, i);
};
virtual size_t getArySize (const ustring& name) {
- return getArySize (name);
+ return mlenv->getArySize (name);
};
virtual MNode* buildArgs (WikiMotorObjVecVec::const_iterator b, WikiMotorObjVecVec::const_iterator e, bool dumpmode = false);
virtual void logLispFunctionError (const ustring& msg, const ustring& cmd);
[[variable/]]
[[variable~]]
[[variable,]]
+// [[@array]]
*/
/*DOC:
return true;
}
+/*DOC:
+===配列展開===
+ [[getarray:NAME]]
+
+*/
+//#WIKILINE getarray wl_getarray
+bool wl_getarray (WikiMotorObjVecVec* args, WikiMotorObjVec& out, WikiFormat* wiki) {
+ MotorOutputWiki o (out);
+ ustring var;
+ ustring val;
+ size_t i, n;
+ MNodeList e;
+
+ if (args->size () == 0 || args->size () > 1)
+ return false;
+ var = (*args)[0]->textOut (wiki);
+ n = wiki->mlenv->getArySize (var);
+ for (i = 1; i <= n; i ++) {
+ e.append (wiki->mlenv->getAry (var, i));
+ }
+ val = fixUTF8 (dump_to_sexp (e ()));
+ o.outamp (val);
+
+ return true;
+}
+
/* ============================================================ */
/*DOC:
===強調===
class WikiMotorObjVecVec;
bool wl_getvar (WikiMotorObjVecVec* args, WikiMotorObjVec& out, WikiFormat* wiki);
+bool wl_getarray (WikiMotorObjVecVec* args, WikiMotorObjVec& out, WikiFormat* wiki);
bool wl_italic (WikiMotorObjVec* arg2, WikiMotorObjVec& out, WikiFormat* wiki);
bool wl_bold (WikiMotorObjVec* arg2, WikiMotorObjVec& out, WikiFormat* wiki);
bool wl_bolditalic (WikiMotorObjVec* arg2, WikiMotorObjVec& out, WikiFormat* wiki);