7afa13544e20818cd127a15c7f98e7925125146a
[roobuilder] / src / JsRender / NodeToVala.vala
1 /**
2  * 
3  * Code to convert node tree to Vala...
4  * 
5  * usage : x = (new JsRender.NodeToVala(node)).munge();
6  * 
7  * 
8  * 
9  * 
10  * 
11 */
12
13
14
15
16 public class JsRender.NodeToVala : Object {
17
18         Node node;
19
20         int depth;
21         string inpad;
22         string pad;
23         string ipad;
24         string cls;
25         string xcls;
26         
27         string ret;
28         
29         int cur_line;
30
31         Gee.ArrayList<string> ignoreList;
32         Gee.ArrayList<string> ignoreWrappedList; 
33         Gee.ArrayList<string> myvars;
34         Gee.ArrayList<Node> vitems; // top level items
35         NodeToVala top;
36         JsRender file;
37         
38         /* 
39          * ctor - just initializes things
40          * - wraps a render node 
41          */
42         public NodeToVala( JsRender file,  Node node,  int depth, NodeToVala? parent) 
43         {
44
45                 
46                 this.node = node;
47                 this.depth = depth;
48                 this.inpad = string.nfill(depth > 0 ? 4 : 0, ' ');
49                 this.pad = this.inpad + "    ";
50                 this.ipad = this.inpad + "        ";
51                 this.cls = node.xvala_cls;
52                 this.xcls = node.xvala_xcls;
53                 this.ret = "";
54                 this.cur_line = parent == null ? 0 : parent.cur_line;
55                 
56                 
57                 this.top = parent == null ? this : parent.top;
58                 this.ignoreList = new Gee.ArrayList<string>();
59                 this.ignoreWrappedList  = new Gee.ArrayList<string>();
60                 this.myvars = new Gee.ArrayList<string>();
61                 this.vitems = new Gee.ArrayList<Node>();
62                 this.file = file;
63                 
64                 // initialize line data..
65                 node.line_start = this.cur_line;
66                 node.line_end  = this.cur_line;
67                 node.lines = new Gee.ArrayList<int>();
68                 node.line_map = new Gee.HashMap<int,string>();
69                 if (parent == null) {
70                         node.node_lines = new Gee.ArrayList<int>();
71                         node.node_lines_map = new Gee.HashMap<int,Node>();
72                  }
73                 
74         }
75
76         public int vcnt = 0;
77         string toValaNS(Node item)
78         {
79                 var ns = item.get("xns") ;
80                 if (ns == "GtkSource") {
81                         return "Gtk.Source";
82                 }
83                 return ns + ".";
84         }
85         public void  toValaName(Node item, int depth =0) 
86         {
87                 this.vcnt++;
88
89                 var ns =  this.toValaNS(item) ;
90                 var cls = ns + item.get("xtype");
91                 
92                 
93                 item.xvala_cls = cls;
94                 
95                 
96                 string id = item.get("id").length > 0 ?
97                         item.get("id") :  "%s%d".printf(item.get("xtype"), this.vcnt);
98
99                 
100                 
101                 
102                 if (id[0] == '*' || id[0] == '+') {
103                         item.xvala_xcls = "Xcls_" + id.substring(1);
104                 } else {
105                         item.xvala_xcls = "Xcls_" + id;
106                 }
107                         
108                 
109                 item.xvala_id =  id;
110                 if (depth > 0) {                        
111                         this.vitems.add(item);
112                 } else if (!item.props.has_key("id")) {
113                         // use the file name..
114                         item.xvala_xcls =  this.file.name;
115                         // is id used?
116                         item.xvala_id = this.file.name;
117
118                 }
119                 // loop children..
120                                                                                                                            
121                 if (item.items.size < 1) {
122                         return;
123                 }
124                 for(var i =0;i<item.items.size;i++) {
125                         this.toValaName(item.items.get(i), depth+1);
126                 }
127                                           
128         }
129         /**
130          *  Main entry point to convert a file into a string..
131          */
132         public static string mungeFile(JsRender file) 
133         {
134                 if (file.tree == null) {
135                         return "";
136                 }
137
138                 var n = new NodeToVala(file, file.tree, 0, null);
139                 n.file = file;
140                 n.vcnt = 0;
141                 
142                 n.toValaName(file.tree);
143                 
144                 
145                 GLib.debug("top cls %s / xlcs %s\n ",file.tree.xvala_cls,file.tree.xvala_cls); 
146                 n.cls = file.tree.xvala_cls;
147                 n.xcls = file.tree.xvala_xcls;
148                 return n.munge();
149                 
150
151         }
152         
153         public string munge ( )
154         {
155                 //return this.mungeToString(this.node);
156
157                 this.ignore("pack");
158                 this.ignore("init");
159                 this.ignore("xns");
160                 this.ignore("xtype");
161                 this.ignore("id");
162                 
163                 this.globalVars();
164                 this.classHeader();
165                 this.addSingleton();
166                 this.addTopProperties();
167                 this.addMyVars();
168                 this.addPlusProperties();
169                 this.addValaCtor();
170                 this.addUnderThis();
171                 this.addWrappedCtor();
172
173                 this.addInitMyVars();
174                 this.addWrappedProperties();
175                 this.addChildren();
176                 this.addInit();
177                 this.addListeners();
178                 this.addEndCtor();
179                 this.addUserMethods();
180                 this.iterChildren();
181                 
182                 return this.ret;
183                  
184                          
185         } 
186         public string mungeChild(  Node cnode)
187         {
188                 var x = new  NodeToVala(this.file, cnode,  this.depth+1, this);
189                 return x.munge();
190         }
191         public void addLine(string str= "")
192         {
193                 this.cur_line++;
194                 //this.ret += "/*%d*/ ".printf(this.cur_line-1) + str + "\n";
195                 this.ret += str + "\n";
196         }
197         public void addMultiLine(string str= "")
198         {
199                  
200                 this.cur_line += str.split("\n").length;
201                 //this.ret +=  "/*%d*/ ".printf(l) + str + "\n";
202                 this.ret +=   str + "\n";
203         }
204          
205         
206         public void globalVars()
207         {
208                 if (this.depth > 0) {
209                         return;
210                 }
211                 // Global Vars..??? when did this get removed..?
212                 //this.ret += this.inpad + "public static " + this.xcls + "  " + this.node.xvala_id+ ";\n\n";
213
214                 this.addLine(this.inpad + "static " + this.xcls + "  _" + this.node.xvala_id+ ";");
215                 this.addLine();
216                    
217         }
218
219         void classHeader()
220         {
221                            
222                 // class header..
223                 // class xxx {   WrappedGtk  el; }
224                 this.node.line_start = this.cur_line;
225                 
226                 this.top.node.setNodeLine(this.cur_line, this.node);
227                 
228                 this.addLine(inpad + "public class " + this.xcls + " : Object");
229                 this.addLine(this.inpad + "{");
230                 
231                  
232                 this.addLine(this.pad + "public " + this.cls + " el;");
233  
234                 this.addLine(this.pad + "private " + this.top.xcls + "  _this;");
235                 this.addLine();
236                         
237                         
238                         
239                         // singleton
240         }
241         void addSingleton() 
242         {
243                 if (depth > 0) {
244                         return;
245                 }
246                 this.addLine(pad + "public static " + xcls + " singleton()");
247                 this.addLine(this.pad + "{");
248                 this.addLine(this.ipad +    "if (_" + this.node.xvala_id  + " == null) {");
249                 this.addLine(this.ipad +    "    _" + this.node.xvala_id + "= new "+ this.xcls + "();");  // what about args?
250                 this.addLine(this.ipad +    "}");
251                 this.addLine(this.ipad +    "return _" + this.node.xvala_id +";");
252                 this.addLine(this.pad + "}");
253         }
254                         
255         /**
256          * when ID is used... on an element, it registeres a property on the top level...
257          * so that _this.ID always works..
258          * 
259          */
260         void addTopProperties()
261         {
262                 if (this.depth > 0) {
263                         return;
264                 }
265                 // properties - global..??
266
267                 var iter = this.vitems.list_iterator();
268                 while(iter.next()) {
269                         var n = iter.get();
270
271                          
272                         if (!n.props.has_key("id") || n.xvala_id.length < 0) {
273                                 continue;
274                                 
275                         }
276                         if (n.xvala_id[0] == '*') {
277                                 continue;
278                         }
279                         if (n.xvala_id[0] == '+') {
280                                 continue;
281                         }
282                         this.addLine(this.pad + "public " + n.xvala_xcls + " " + n.xvala_id + ";");
283                         
284                 }
285                                 
286         }
287         /**
288          * create properties that are not 'part of the wrapped element.
289          * 
290          * 
291          */
292         
293         void addMyVars()
294         {
295                 this.addLine();
296                 this.addLine(this.ipad + "// my vars (def)");
297                         
298
299  
300                 var cls = Palete.Gir.factoryFqn((Project.Gtk) this.file.project, this.node.fqn());
301                    
302                 if (cls == null) {
303                         return;
304                 }
305           
306                 
307                         // Key = TYPE:name
308                 var iter = this.node.props.map_iterator();
309                 while (iter.next()) {
310                         var k = iter.get_key();
311                         if (this.shouldIgnore(k)) {
312                                 continue;
313                         }
314                         var vv = k.strip().split(" ");
315                         // user defined method
316                         if (vv[0] == "|") {
317                                 continue;
318                         }
319                         if (vv[0] == "*") {
320                                 continue;
321                         }
322                                 
323                         if (vv[0] == "@") {
324                                 this.node.setLine(this.cur_line, "p", k);
325                                 this.addLine(this.pad + "public signal" + k.substring(1)  + " "  + iter.get_value() + ";");
326                                 
327                                 this.ignore(k);
328                                 continue;
329                         }
330                         var min = (vv[0] == "$" || vv[0] == "#") ? 3 : 2; 
331                         if (vv.length < min) {
332                                 // skip 'old js style properties without a type'
333                                 continue;
334                         }
335                         
336                         var kname = vv[vv.length-1];
337
338                         if (this.shouldIgnore(kname)) {
339                                 continue;
340                         }
341                         
342                         // is it a class property...
343                         if (cls.props.has_key(kname) && vv[0] != "#") {
344                                 continue;
345                         }
346                         
347                         this.myvars.add(k);
348                         this.node.setLine(this.cur_line, "p", k);
349                         
350                         this.addLine(this.pad + "public " + 
351                                 (k[0] == '$' || k[0] == '#' ? k.substring(2) : k ) + ";");
352                                 
353                         this.ignore(k);
354                         
355                                 
356                 }
357         }
358         
359         // if id of child is '+' then it's a property of this..
360         void addPlusProperties()
361         {
362                 if (this.node.items.size < 1) {
363                         return;
364                 }
365                 var iter = this.node.items.list_iterator();
366                 while (iter.next()) {
367                         var ci = iter.get();
368                                 
369                         if (ci.xvala_id[0] != '+') {
370                                 continue; // skip generation of children?
371                                 
372                         }
373                          
374                         this.addLine(this.pad + "public " + ci.xvala_xcls + " " + ci.xvala_id.substring(1) + ";");
375                                            
376                         
377                 }
378         }
379         /**
380          * add the constructor definition..
381          */
382         void addValaCtor()
383         {
384                         
385                 
386                 // .vala props.. 
387                 
388                 string[] cargs = {};
389                 var cargs_str = "";
390                 // ctor..
391                 this.addLine();
392                 this.addLine(this.pad + "// ctor");
393                 
394                 if (this.node.has("* args")) {
395                         // not sure what this is supposed to be ding..
396                 
397                         cargs_str = ", " + this.node.get("* args");
398                         //var ar = this.node.get("* args");.split(",");
399                         //for (var ari =0; ari < ar.length; ari++) {
400                                 //      cargs +=  (ar[ari].trim().split(" ").pop();
401                                   // }
402                         }
403         
404                 if (this.depth < 1) {
405                  
406                         // top level - does not pass the top level element..
407                         this.addLine(this.pad + "public " + this.xcls + "(" +  cargs_str +")");
408                         this.addLine(this.pad + "{");
409                 } else {
410                                 
411                         // for sub classes = we passs the top level as _owner
412                         this.addLine(this.pad + "public " + this.xcls + "(" +  this.top.xcls + " _owner " + cargs_str + ")");
413                         this.addLine(this.pad + "{");
414                 }
415                 
416
417         }
418         /**
419          *  make sure _this is defined..
420          */
421         void addUnderThis() 
422         {
423                 // public static?
424                 if (depth < 1) {
425                         this.addLine( this.ipad + "_this = this;");
426                         return;
427                 }
428                 // for non top level = _this point to owner, and _this.ID is set
429                 
430                 this.addLine( this.ipad + "_this = _owner;");
431
432                 if (this.node.props.has_key("id")
433                         &&
434                         this.node.xvala_id != "" 
435                         && 
436                         this.node.xvala_id[0] != '*' 
437                         && 
438                         this.node.xvala_id[0] != '+' 
439                         ) {
440                                 this.addLine( this.ipad + "_this." + node.xvala_id  + " = this;");
441                    
442                 }
443                          
444         }
445         /**
446          * Initialize this.el to point to the wrapped element.
447          * 
448          * 
449          */
450
451         void addWrappedCtor()
452         {
453                 // wrapped ctor..
454                 // this may need to look up properties to fill in the arguments..
455                 // introspection does not workk..... - as things like gtkmessagedialog
456                 /*
457                 if (cls == 'Gtk.Table') {
458
459                 var methods = this.palete.getPropertiesFor(cls, 'methods');
460
461                 print(JSON.stringify(this.palete.proplist[cls], null,4));
462                 Seed.quit();
463                 }
464                 */
465                 if (this.node.has("* ctor")) {
466                         this.node.setLine(this.cur_line, "p", "* ctor");
467                         this.addLine(this.ipad + "this.el = " + this.node.get("* ctor")+ ";");
468                         return;
469                 }
470                  
471                 var  default_ctor = Palete.Gir.factoryFqn((Project.Gtk) this.file.project, this.node.fqn() + ".new");
472
473                  
474                 if (default_ctor != null && default_ctor.paramset != null && default_ctor.paramset.params.size > 0) {
475                         string[] args  = {};
476                         var iter = default_ctor.paramset.params.list_iterator();
477                         while (iter.next()) {
478                                 var n = iter.get().name;
479                             GLib.debug("building CTOR ARGS: %s, %s", n, iter.get().is_varargs ? "VARARGS": "");
480                                  
481                                 
482                                 if (!this.node.has(n)) {
483                                         if (n == "___") { // for some reason our varargs are converted to '___' ...
484                                                 continue;
485                                         }
486                                                 
487                                         
488                                         if (iter.get().type.contains("int")) {
489                                                 args += "0";
490                                                 continue;
491                                         }
492                                         if (iter.get().type.contains("float")) {
493                                                 args += "0f";
494                                                 continue;
495                                         }
496                                         if (iter.get().type.contains("bool")) {
497                                                 args += "true"; // always default to true?
498                                                 continue;
499                                         }
500                                         // any other types???
501                                         
502                                         args += "null";
503                                         continue;
504                                 }
505                                 this.ignoreWrapped(n);
506                                 this.ignore(n);
507                                 
508                                 var v = this.node.get(n);
509
510                                 if (iter.get().type == "string") {
511                                         v = "\"" +  v.escape("") + "\"";
512                                 }
513                                 if (v == "TRUE" || v == "FALSE") {
514                                         v = v.down();
515                                 }
516
517                                 
518                                 args += v;
519
520                         }
521                         this.node.setLine(this.cur_line, "p", "* xtype");
522                         
523                         this.addLine(this.ipad + "this.el = new " + cls + "( "+ string.joinv(", ",args) + " );") ;
524                         return;
525                         
526                 }
527                 this.node.setLine(this.cur_line, "p", "* xtype");;
528                 
529                 this.addLine(this.ipad + "this.el = new " + this.cls + "();");
530
531                         
532         }
533
534         void addInitMyVars()
535         {
536                         //var meths = this.palete.getPropertiesFor(item['|xns'] + '.' + item.xtype, 'methods');
537                         //print(JSON.stringify(meths,null,4));Seed.quit();
538                         
539                         
540                         
541                         // initialize.. my vars..
542                 this.addLine();
543                 this.addLine( this.ipad + "// my vars (dec)");
544                 
545                 var iter = this.myvars.list_iterator();
546                 while(iter.next()) {
547                         
548                         var k = iter.get();
549                         
550                         var ar  = k.strip().split(" ");
551                         var kname = ar[ar.length-1];
552                         
553                         var v = this.node.props.get(k);
554                         // ignore signals.. 
555                         if (v.length < 1) {
556                                 continue; 
557                         }
558                         if (v == "FALSE" || v == "TRUE") {
559                                 v = v.down();
560                         }
561                         //FIXME -- check for raw string.. "string XXXX"
562                         
563                         // if it's a string...
564                         
565                         
566                         this.addLine(this.ipad + "this." + kname + " = " +   v +";");
567                 }
568         }
569
570         
571
572
573         
574         void addWrappedProperties()
575         {
576                 var cls = Palete.Gir.factoryFqn((Project.Gtk) this.file.project, this.node.fqn());
577                 if (cls == null) {
578                         return;
579                 }
580                         // what are the properties of this class???
581                 this.addLine();
582                 this.addLine(this.ipad + "// set gobject values");
583                 
584
585                 var iter = cls.props.map_iterator();
586                 while (iter.next()) {
587                         var p = iter.get_key();
588                         //print("Check Write %s\n", p);
589                         if (!this.node.has(p)) {
590                                 continue;
591                         }
592                         if (this.shouldIgnoreWrapped(p)) {
593                                 continue;
594                         }
595                         
596                                 this.ignore(p);
597                         var v = this.node.get(p);
598
599                         var nodekey = this.node.get_key(p);
600
601                         // user defined properties.
602                         if (nodekey[0] == '#') {
603                                 continue;
604                         }
605                                 
606
607                         
608                         var is_raw = nodekey[0] == '$';
609                         
610                         // what's the type.. - if it's a string.. then we quote it..
611                         if (iter.get_value().type == "string" && !is_raw) {
612                                  v = "\"" +  v.escape("") + "\"";
613                         }
614                         if (v == "TRUE" || v == "FALSE") {
615                                 v = v.down();
616                         }
617                         if (iter.get_value().type == "float" && v[v.length-1] != 'f') {
618                                 v += "f";
619                         }
620                         
621                         
622                         this.addLine("%sthis.el.%s = %s;".printf(ipad,p,v)); // // %s,  iter.get_value().type);
623                                         
624                            // got a property..
625                            
626
627                 }
628                 
629         }
630         /**
631          *  pack the children into the parent.
632          * 
633          * if the child's id starts with '*' then it is not packed...
634          * - this allows you to define children and add them manually..
635          */
636
637         void addChildren()
638         {
639                                 //code
640                 if (this.node.items.size < 1) {
641                         return;
642                 }
643                          
644                 var iter = this.node.items.list_iterator();
645                 var i = -1;
646                 while (iter.next()) {
647                         i++;
648                                 
649                         var ci = iter.get();
650
651                         if (ci.xvala_id[0] == '*') {
652                                 continue; // skip generation of children?
653                         }
654                                         
655                         var xargs = "";
656                         if (ci.has("* args")) {
657                                 
658                                 var ar = ci.get("* args").split(",");
659                                 for (var ari = 0 ; ari < ar.length; ari++ ) {
660                                         var arg = ar[ari].split(" ");
661                                         xargs += "," + arg[arg.length -1];
662                                 }
663                         }
664                         // create the element..
665                         this.addLine(this.ipad + "var child_" + "%d".printf(i) + " = new " + ci.xvala_xcls +
666                                         "( _this " + xargs + ");" );
667                         
668                         // this is only needed if it does not have an ID???
669                         this.addLine(this.ipad + "child_" + "%d".printf(i) +".ref();"); // we need to reference increase unnamed children...
670                         
671                         if (ci.has("* prop")) {
672                                 this.addLine(ipad + "this.el." + ci.get("* prop") + " = child_" + "%d".printf(i) + ".el;");
673                                 continue;
674                         } 
675                                 
676
677         // not sure why we have 'true' in pack?!?
678                         if (!ci.has("pack") || ci.get("pack").down() == "false" || ci.get("pack").down() == "true") {
679                                 continue;
680                         }
681                         
682                         string[]  packing =  { "add" };
683                         if (ci.has("pack")) {
684                                 packing = ci.get("pack").split(",");
685                         }
686                         
687                         var pack = packing[0];
688                         this.addLine(this.ipad + "this.el." + pack.strip() + " (  child_" + "%d".printf(i) + ".el " +
689                                    (packing.length > 1 ? 
690                                                 (", " + string.joinv(",", packing).substring(pack.length+1))
691                                         :
692                                                         ""
693                                                 ) + " );");
694         
695                                           
696                         if (ci.xvala_id[0] != '+') {
697                                 continue; // skip generation of children?
698                                                 
699                         }
700                         // this.{id - without the '+'} = the element...
701                         this.addLine(this.ipad + "this." + ci.xvala_id.substring(1) + " =  child_" + "%d".printf(i) +  ";");
702                                   
703                 }
704         }
705
706         void addInit()
707         {
708
709                 
710                 if (!this.node.has("init")) {
711                                 return;
712                 }
713                 this.addLine();
714                 this.addLine(ipad + "// init method");
715                 this.addLine();
716                 this.node.setLine(this.cur_line, "p", "init");
717                 
718                 this.addMultiLine(ipad + this.padMultiline(ipad, this.node.get("init")) );
719
720          }
721          void addListeners()
722          {
723                 if (this.node.listeners.size < 1) {
724                         return;
725                 }
726                                 
727                 this.addLine();
728                 this.addLine(ipad + "//listeners");
729                         
730                          
731
732                 var iter = this.node.listeners.map_iterator();
733                 while (iter.next()) {
734                         var k = iter.get_key();
735                         var v = iter.get_value();
736                         
737                         this.node.setLine(this.cur_line, "l", k);
738                         this.addMultiLine(this.ipad + "this.el." + k + ".connect( " + 
739                                         this.padMultiline(this.ipad,v) +");"); 
740                                 
741                 }
742         }    
743         void addEndCtor()
744         {
745                          
746                         // end ctor..
747                         this.addLine(this.pad + "}");
748         }
749
750
751         /*
752  * Standardize this crap...
753  * 
754  * standard properties (use to set)
755  *          If they are long values show the dialog..
756  *
757  * someprop : ....
758  * bool is_xxx  :: can show a pulldown.. (true/false)
759  * string html  
760  * $ string html  = string with value interpolated eg. baseURL + ".." 
761  *  Clutter.ActorAlign x_align  (typed)  -- shows pulldowns if type is ENUM? 
762  * $ untypedvalue = javascript untyped value...  
763  * _ string html ... = translatable..
764
765  * 
766  * object properties (not part of the GOjbect being wrapped?
767  * # Gee.ArrayList<Xcls_fileitem> fileitems
768  * 
769  * signals
770  * @ void open 
771  * 
772  * methods -- always text editor..
773  * | void clearFiles
774  * | someJSmethod
775  * 
776  * specials
777  * * prop -- string
778  * * args  -- string
779  * * ctor -- string
780  * * init -- big string?
781  * 
782  * event handlers (listeners)
783  *   just shown 
784  * 
785  * -----------------
786  * special ID values
787  *  +XXXX -- indicates it's a instance property / not glob...
788  *  *XXXX -- skip writing glob property (used as classes that can be created...)
789  * 
790  * 
791  */
792          
793         void addUserMethods()
794         {
795                 this.addLine();
796                 this.addLine(this.pad + "// user defined functions");
797                         
798                         // user defined functions...
799                 var iter = this.node.props.map_iterator();
800                 while(iter.next()) {
801                         var k = iter.get_key();
802                         if (this.shouldIgnore(k)) {
803                                 continue;
804                         }
805                         // HOW TO DETERIME if its a method?            
806                         if (k[0] != '|') {
807                                         //strbuilder("\n" + pad + "// skip " + k + " - not pipe \n"); 
808                                         continue;
809                         }
810                         
811                         // function in the format of {type} (args) { .... }
812                         var kk = k.substring(2);
813                         var vv = iter.get_value();
814                         this.node.setLine(this.cur_line, "p", k);
815                         this.addMultiLine(this.pad + "public " + kk + " " + this.padMultiline(this.pad, vv));;
816                         
817                                 
818                 }
819         }
820
821         void iterChildren()
822         {
823                 this.node.line_end = this.cur_line;
824                 this.node.sortLines();
825                 
826                         
827                 if (this.depth > 0) {
828                         this.addLine(this.inpad + "}");
829                 }
830                 
831                 var iter = this.node.items.list_iterator();
832                  
833                 while (iter.next()) {
834                         this.addMultiLine(this.mungeChild(iter.get()));
835                 }
836                          
837                 if (this.depth < 1) {
838                         this.addLine(this.inpad + "}");
839                 }
840                         
841         }
842
843         string padMultiline(string pad, string str)
844         {
845                 var ar = str.strip().split("\n");
846                 return string.joinv("\n" + pad , ar);
847         }
848         
849         void ignore(string i) {
850                 this.ignoreList.add(i);
851                 
852         }
853         void ignoreWrapped(string i) {
854                 this.ignoreWrappedList.add(i);
855                 
856         }
857         bool shouldIgnore(string i)
858         {
859                 return ignoreList.contains(i);
860         }
861         bool shouldIgnoreWrapped(string i)
862         {
863                 return ignoreWrappedList.contains(i);
864         }
865         
866 }
867         
868          
869         
870         
871
872