1 #include "wikiattrib.h"
2 #include "wikiformat.h"
4 #include "util_check.h"
7 bool WikiAttrib1::readAttrib1 (WikiMotorObjVec* cell, bool& rc) {
12 if (cell->size () == 0) {
13 if (mode == M_ATTRIB || mode == M_ATTRIB_TEXT)
18 if (cell->splitChar_keyword ('=', key, vval)) {
19 if (paramID (key, vval, ferr)) {
20 } else if (paramClass (key, vval, ferr)) {
22 } else if (paramDataPrefix (key, vval, ferr)) {
24 } else if (paramOnClickCheck (key)) {
25 if (! checkScript (vval, onclick, ferr)) {
26 wiki->errorMsg.append (cell->dump ()).append (CharConst (": link script error.\n"));
29 } else if (paramOnFocusCheck (key)) {
30 if (! checkScript (vval, onfocus, ferr)) {
31 wiki->errorMsg.append (cell->dump ()).append (CharConst (": link script error.\n"));
34 } else if (paramOnBlurCheck (key)) {
35 if (! checkScript (vval, onblur, ferr)) {
36 wiki->errorMsg.append (cell->dump ()).append (CharConst (": link script error.\n"));
39 } else if (paramOnChangeCheck (key)) {
40 if (! checkScript (vval, onchange, ferr)) {
41 wiki->errorMsg.append (cell->dump ()).append (CharConst (": link script error.\n"));
44 } else if ((selector & SEL_TARGET) && paramTargetCheck (key)) {
45 paramTargetBody (key, vval.textOut (wiki), target, ferr);
46 } else if (readAttribMore (key, vval, ferr)) {
48 if (mode == M_ATTRIB) {
49 wiki->errorMsg.append (cell->dump ()).append (CharConst (": bad attribute.\n"));
55 if (selector & SEL_CLASS2) {
56 paramClassValue (*cell, classlist, ferr);
57 } else if (selector & SEL_TARGET2) {
58 paramTargetBody (uEmpty, cell->textOut (wiki), target, ferr);
59 } else if ((selector & SEL_ONCLICK2) && checkScript (*cell, onclick, ferr)) {
60 } else if ((selector & SEL_MULTIPLE2) && match (key, CharConst ("multiple"))) {
62 } else if ((selector & SEL_DEFAULT2) && match (key, CharConst ("default"))) {
64 } else if ((selector & SEL_SCRIPT2) && checkScript (*cell, script, ferr)) {
65 } else if (readAttribMore2 (key, *cell, ferr)) {
67 if (mode == M_ATTRIB) {
68 wiki->errorMsg.append (cell->dump ()).append (CharConst (": bad attribute.\n"));
82 bool WikiAttrib1::shiftAttrib (WikiMotorObjVecPtr& vec) {
84 WikiMotorObjVecPtr v2;
86 while (vec->size () > 0) {
89 v2 = WikiMotorObjVecPtr (new WikiMotorObjVec);
90 if (vec->splitChar (':', cell, *v2) || mode == M_ATTRIB || mode == M_ATTRIB_TEXT) {
91 if (! readAttrib1 (&cell, rc))
101 void WikiAttrib1::skipAttrib (WikiMotorObjVecPtr& vec) {
102 WikiMotorObjVecPtr v2;
104 if (vec->size () > 0) {
105 WikiMotorObjVec cell;
107 v2 = WikiMotorObjVecPtr (new WikiMotorObjVec);
108 if (vec->splitChar (':', cell, *v2)) {
114 bool WikiAttrib1::readAttrib (WikiMotorObjVecVec::const_iterator& b, const WikiMotorObjVecVec::const_iterator& e) {
118 WikiMotorObjVec* cell = b->get ();
119 if (! readAttrib1 (cell, rc))
126 bool WikiAttrib1::checkScript (WikiMotorObjVec& vec, ustring& scr, bool& ferr) {
130 for (i = 0; i < vec.size () && vec[i]->type == WikiMotorObj::wiki_funcLink; i ++) {
131 WikiMotorObjFuncLink* fn = WikiMotorObjFuncLink_type (&*vec[i]);
132 u = fn->execDefunArgs (wiki);
133 // XXX: 末尾の空白を除去し,セミコロンを確認する。
143 bool WikiAttrib1::shiftLink (WikiMotorObjVecPtr& vec, ustring& url, bool& fscript) {
146 WikiMotorObjVec cell;
147 WikiMotorObjVecPtr v2 (new WikiMotorObjVec);
149 rc = vec->splitChar (':', cell, *v2);
150 if (checkScript (cell, url, ferr)) {
154 } else if (rc && cell.match (CharConst ("http"), CharConst ("https"))) {
155 ustring proto = cell.dump ();
158 v2 = WikiMotorObjVecPtr (new WikiMotorObjVec);
159 rc = vec->splitChar (':', cell, *v2);
160 if (! cell.splitURL_2 (wiki, proto, url)) {
165 if (vec->size () > 0) {
167 v2 = WikiMotorObjVecPtr (new WikiMotorObjVec);
168 rc = vec->splitChar (':', cell, *v2);
169 if (cell.splitURL_3 (wiki, url, url))
173 } else if (cell.splitURLPath (wiki, url)) {
182 bool WikiAttrib1::readLink (WikiMotorObjVecVec::const_iterator& b, const WikiMotorObjVecVec::const_iterator& e, ustring& url, bool& fscript, bool noscript) {
185 WikiMotorObjVec* cell;
186 static uregex re (CharConst ("^[a-z]{3,6}$"));
192 if (! noscript && checkScript (*cell, url, ferr)) {
196 } else if (rc && cell->regmatch (re)) {
197 ustring proto = cell->dump ();
200 if (! cell->splitURL_2 (wiki, proto, url)) {
207 if (cell->splitURL_3 (wiki, url, url))
211 } else if (cell->splitURLPath (wiki, url)) {
220 bool WikiAttrib1::shiftName (WikiMotorObjVecPtr& vec, ustring& name) {
221 if (vec->size () > 0) {
222 WikiMotorObjVec cell;
223 WikiMotorObjVecPtr v2 (new WikiMotorObjVec);
225 vec->splitChar (':', cell, *v2);
226 name = cell.textOut (wiki);
234 void WikiAttrib1::output (MotorOutput* out) {
235 wiki->outputID (out, id);
236 wiki->outputClass (out, classlist);
238 // std::pair<ustring,ustring>::const_iterator b, e;
239 std::vector<datapre_t>::const_iterator b, e;
240 b = datapre.begin ();
242 for (; b < e; b ++) {
243 wiki->outputName (out, (*b).first.c_str (), (*b).first.size (), (*b).second);
246 wiki->outputSubmitScript (out, CharConst ("onclick"), onclick, scriptcut);
247 wiki->outputSubmitScript (out, CharConst ("onfocus"), onfocus, scriptcut);
248 wiki->outputSubmitScript (out, CharConst ("onblur"), onblur, scriptcut);
249 wiki->outputSubmitScript (out, CharConst ("onchange"), onchange, scriptcut);
250 wiki->outputName (out, CharConst ("target"), target);
251 wiki->outputFlag (out, CharConst ("multiple"), fmultiple);
256 bool WikiAttrib1::paramID (const ustring& key, WikiMotorObjVec& vval, bool& ferr) {
257 if (match (key, CharConst ("id"))) {
258 paramIDValue (key, vval, id, ferr);
265 void WikiAttrib1::paramIDValue (const ustring& key, WikiMotorObjVec& vval, ustring& var, bool& ferr) {
266 ustring value (vval.textOut (wiki));
267 if (checkWikiID (value)) {
271 wiki->errorMsg.append (key).append (uEq).append (value).append (CharConst (": bad value\n"));
276 bool WikiAttrib1::paramClass (const ustring& key, WikiMotorObjVec& vval, bool& ferr) {
277 if (match (key, CharConst ("class"))) {
278 paramClassValue (vval, classlist, ferr);
285 void WikiAttrib1::paramClassValue (WikiMotorObjVec& vval, std::vector<ustring>& var, bool& ferr) {
286 WikiMotorObjVecVec args;
288 vval.splitCharA (',', args);
289 for (int i = 0; i < args.size (); i ++) {
290 ustring value (args[i]->textOut (wiki));
291 if (value.length () > 0) {
292 if (checkWikiID (value)) {
293 var.push_back (value);
295 wiki->errorMsg.append (value).append (CharConst (": bad class name\n"));
302 bool WikiAttrib1::paramWidth (const ustring& key, WikiMotorObjVec& vval, ustring& var, bool& ferr) {
303 if (match (key, CharConst ("width"), CharConst ("w"))) {
304 paramWidthValue (key, vval, var, ferr);
311 bool WikiAttrib1::paramHeight (const ustring& key, WikiMotorObjVec& vval, ustring& var, bool& ferr) {
312 if (match (key, CharConst ("height"), CharConst ("h"))) {
313 paramWidthValue (key, vval, var, ferr);
320 void WikiAttrib1::paramWidthValue (const ustring& key, WikiMotorObjVec& vval, ustring& var, bool& ferr) {
321 ustring value (vval.textOut (wiki));
322 if (checkWidth (value)) {
324 // if (checkNum (value))
325 // var.append (CharConst ("px"));
328 wiki->errorMsg.append (key).append (uEq).append (value).append (CharConst (": bad value\n"));
333 bool WikiAttrib1::paramSize (const char* name, size_t namelen, const ustring& key, WikiMotorObjVec& vval, ustring& var, bool& ferr) {
334 if (match (key, name, namelen)) {
335 ustring value (vval.textOut (wiki));
336 if (checkNum (value)) {
347 void WikiAttrib1::paramUNum (const ustring& value, int& var, const ustring& name) {
348 if (checkNum (value)) {
349 var = strtoul (value);
351 wiki->errorMsg.append (name).append (uEq).append (value).append (uErrorBadValue).append (uLF);
355 void WikiAttrib1::paramColor (const ustring& value, ustring& var, const ustring& name) {
356 if (checkColor (value)) {
359 wiki->errorMsg.append (name).append (uEq).append (value).append (uErrorBadValue).append (uLF);
363 bool WikiAttrib1::paramTargetCheck (const ustring& key) {
364 return match (key, CharConst ("target"));
367 void WikiAttrib1::paramTargetBody (const ustring& key, const ustring& value, ustring& var, bool& ferr) {
368 if (value.length () == 0 || checkWikiID (value)) {
371 if (key.length () > 0)
372 wiki->errorMsg.append (key).append (uEq).append (value).append (CharConst (": bad target name.\n"));
374 wiki->errorMsg.append (value).append (CharConst (": bad target name.\n"));
379 bool WikiAttrib1::paramOnClickCheck (const ustring& name) {
380 return match (name, CharConst ("onclick"));
383 bool WikiAttrib1::paramOnFocusCheck (const ustring& name) {
384 return match (name, CharConst ("onfocus"));
387 bool WikiAttrib1::paramOnBlurCheck (const ustring& name) {
388 return match (name, CharConst ("onblur"));
391 bool WikiAttrib1::paramOnChangeCheck (const ustring& name) {
392 return match (name, CharConst ("onchange"));
396 bool WikiAttrib1::paramDataPrefix (const ustring& key, WikiMotorObjVec& vval, bool& ferr) {
397 // if (match (CharConst ("data-"), key) && checkWikiID (key)) {
398 if (matchHead (key, CharConst ("data-")) && checkWikiID (key)) {
399 ustring value (vval.textOut (wiki));
400 if (checkWikiID (value)) {
401 datapre.push_back (std::pair<ustring,ustring> (key, value));
404 wiki->errorMsg.append (key).append (uEq).append (value).append (CharConst (": bad value\n"));
413 /* ============================================================ */
414 void WikiAttribTable::init () {
419 #ifdef WIKITABLEATTRIB
425 // halign = HAlignNone;
430 while (! classlist.empty ())
431 classlist.pop_back ();
438 void WikiAttribTable::copyFrom (WikiAttribTable& b) {
442 for (i = 0; i < b.classlist.size (); i ++)
443 classlist.push_back (b.classlist[i]);
454 bool WikiAttribTable::readAttribMore (const ustring& key, WikiMotorObjVec& vval, bool& ferr) {
455 if (paramWidth (key, vval, width, ferr)) {
456 } else if (paramHeight (key, vval, height, ferr)) {
457 } else if (match (key, CharConst ("bgcolor"), CharConst ("bg"))) {
458 paramColor (vval.textOut (wiki), bgcolor, key);
462 #ifdef WIKITABLEATTRIB
463 if (match (key, CharConst ("cellspacing"), CharConst ("spc"))) {
464 paramUNum (vval.textOut (wiki), cellspacing, key);
465 } else if (match (key, CharConst ("cellpadding"))) {
466 paramUNum (vval.textOut (wiki), cellpadding, key);
484 bool WikiAttribTable::readAttribMore2 (const ustring& key, WikiMotorObjVec& cell, bool& ferr) {
485 if (match (key, CharConst ("left"), CharConst ("l"))) {
487 } else if (match (key, CharConst ("right"), CharConst ("r"))) {
488 halign = HAlignRight;
489 } else if (match (key, CharConst ("center"), CharConst ("c"))) {
490 halign = HAlignCenter;
494 #ifdef WIKITABLEATTRIB
495 if (match (key, CharConst ("noborder"), CharConst ("nb"))) {
499 if (match (key, CharConst ("padding"), CharConst ("pad"))) {
501 } else if (match (key, CharConst ("expanding"), CharConst ("expand"))) {
503 } else if (match (key, CharConst ("nowhite"), CharConst ("nw"))) {
505 } else if (match (key, CharConst ("turn"))) {
513 if (match (key, CharConst ("header"), CharConst ("h"))) {
515 } else if (match (key, CharConst ("top"), CharConst ("t"))) {
517 } else if (match (key, CharConst ("middle"), CharConst ("m"))) {
518 valign = VAlignMiddle;
519 } else if (match (key, CharConst ("bottom"), CharConst ("b"))) {
520 valign = VAlignBottom;
521 } else if (match (key, CharConst ("nowrap"), CharConst ("nw"))) {
523 } else if (match (key, CharConst ("*"))) {
537 void WikiAttribTable::outputMore (MotorOutput* out) {
540 out->out_raw (CharConst (" align=\"left\""));
543 out->out_raw (CharConst (" align=\"center\""));
546 out->out_raw (CharConst (" align=\"right\""));
549 wiki->outputName (out, CharConst ("width"), width);
550 wiki->outputName (out, CharConst ("height"), height);
551 wiki->outputName (out, CharConst ("bgcolor"), bgcolor);
555 #ifdef WIKITABLEATTRIB
556 wiki->outputName (out, CharConst ("border"), fnoborder ? 0 : 1, false);
557 wiki->outputName (out, CharConst ("cellspacing"), cellspacing, false);
558 wiki->outputName (out, CharConst ("cellpadding"), cellpadding, false);
565 out->out_raw (CharConst (" valign=\"top\""));
568 out->out_raw (CharConst (" valign=\"middle\""));
571 out->out_raw (CharConst (" valign=\"bottom\""));
574 wiki->outputFlag (out, CharConst ("nowrap"), fnowrap);
581 /* ============================================================ */
582 bool WikiAttribImg::readAttribMore (const ustring& key, WikiMotorObjVec& vval, bool& ferr) {
583 if (paramWidth (key, vval, width, ferr)) {
584 } else if (paramHeight (key, vval, height, ferr)) {
585 } else if (match (key, CharConst ("alt"))) {
586 alt = vval.textOut (wiki);
593 void WikiAttribImg::outputMore (MotorOutput* out) {
594 wiki->outputName (out, CharConst ("width"), width);
595 wiki->outputName (out, CharConst ("height"), height);
599 /* ============================================================ */
600 bool WikiAttribInput::readAttribMore (const ustring& key, WikiMotorObjVec& vval, bool& ferr) {
601 if ((selector2 & SEL_INPUT) && paramSize (CharConst ("size"), key, vval, psize, ferr)) {
602 } else if ((selector2 & SEL_ELSIZE) && match (key, CharConst ("size"))) {
603 ustring v = vval.textOut (wiki);
604 if (match (v, CharConst ("*"))) {
606 } else if (checkNum (v)) {
607 elsize = to_int32 (v);
608 if (elsize < 0 || elsize > 999) {
614 } else if (paramWidth (key, vval, pwidth, ferr)) {
615 } else if ((selector2 & SEL_TEXTAREA) && paramSize (CharConst ("cols"), key, vval, pcols, ferr)) {
616 } else if ((selector2 & SEL_TEXTAREA) && paramSize (CharConst ("rows"), key, vval, prows, ferr)) {
617 } else if ((selector2 & SEL_TEXTAREA) && match (key, CharConst ("wrap"))) {
618 ustring value (vval.textOut (wiki));
619 if (match (value, CharConst ("off"))) {
621 } else if (match (value, CharConst ("soft"))) {
623 } else if (match (value, CharConst ("hard"))) {
625 } else if (paramWidth (key, vval, pwidth, ferr)) {
627 wiki->errorMsg.append (key).append (CharConst ("=")).append (vval.dump ()).append (CharConst (": link script error.\n"));
637 bool WikiAttribInput::readAttribMore2 (const ustring& key, WikiMotorObjVec& cell, bool& ferr) {
638 if (key == uDefault) {
640 } else if ((selector2 & SEL_CHECK) && match (key, CharConst ("checked"))) {
642 } else if ((selector2 & SEL_TEXTAREA) && match (key, CharConst ("tab"))) {
650 void WikiAttribInput::outputMore (MotorOutput* out) {
651 wiki->outputName (out, CharConst ("size"), psize);
652 wiki->outputName (out, CharConst ("size"), elsize);
653 if (pwidth.size () > 0) {
654 if (checkNum (pwidth)) {
655 out->out_raw (CharConst (" style=\"width:"))->out_toHTML_noCtrl (pwidth)->out_raw (CharConst ("px;\""));
657 out->out_raw (CharConst (" style=\"width:"))->out_toHTML_noCtrl (pwidth)->out_raw (CharConst (";\""));
660 if (selector2 & SEL_CHECK) {
661 wiki->outputFlag (out, CharConst ("checked"), pchecked);
663 if (selector2 & SEL_TEXTAREA) {
664 wiki->outputName (out, CharConst ("cols"), pcols, false);
665 wiki->outputName (out, CharConst ("rows"), prows);
668 out->out_raw (CharConst (" wrap=\"off\""));
671 out->out_raw (CharConst (" wrap=\"soft\""));
672 // out->out_raw (CharConst (" wrap=\"virtual\""));
675 out->out_raw (CharConst (" wrap=\"hard\""));
676 // out->out_raw (CharConst (" wrap=\"physical\""));
681 ->out_raw (CharConst ("onkeypress"))
682 ->out_raw (CharConst ("=\""))
683 ->out_toHTML (ustring (CharConst ("return insertTab(event,this);")))
686 ->out_raw (CharConst ("onkeydown"))
687 ->out_raw (CharConst ("=\""))
688 ->out_toHTML (ustring (CharConst ("return insertTab(event,this);")))
691 ->out_raw (CharConst ("onkeyup"))
692 ->out_raw (CharConst ("=\""))
693 ->out_toHTML (ustring (CharConst ("return insertTab(event,this);")))
699 /* ============================================================ */
700 bool WikiAttribButton::readAttrib (WikiMotorObjVecVec::const_iterator& b, const WikiMotorObjVecVec::const_iterator& e) {
704 WikiMotorObjVec* cell = b->get ();
708 if (! readAttrib1 (cell, rc)) {
709 name = cell->textOut (wiki);
715 WikiMotorObjVec* cell = b->get ();
716 if (! readAttrib1 (cell, rc))
723 /* ============================================================ */
724 bool WikiAttribItem::readAttribMore (const ustring& key, WikiMotorObjVec& vval, bool& ferr) {
725 if (match (key, CharConst ("ulclass"))) {
726 if (owner && owner->parent && owner->parent->attrib.classlist.size () == 0) {
727 paramClassValue (vval, owner->parent->attrib.classlist, ferr);
729 } else if (match (key, CharConst ("ulid"))) {
730 if (owner && owner->parent && owner->parent->attrib.id.size () == 0) {
731 paramIDValue (key, vval, owner->parent->attrib.id, ferr);
739 /* ============================================================ */