X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=blobdiff_plain;f=Pman.SearchTokenizer.js;h=8db0be1b8579dbfad2a4dac29c7e41c7d518e78a;hp=ad663e9ef4bfe3d53ddeed37099e01375d0acd49;hb=refs%2Fheads%2Fwip_alan_T5884_add_photo_to_report;hpb=edd63355cd2dccc239059db92915341416c8a175 diff --git a/Pman.SearchTokenizer.js b/Pman.SearchTokenizer.js index ad663e9e..8db0be1b 100644 --- a/Pman.SearchTokenizer.js +++ b/Pman.SearchTokenizer.js @@ -14,8 +14,8 @@ Pman.SearchTokenizer = function(s) { - this.str = s; - this.strlen = s.length; + this.str = typeof(s) == 'string' ? s : ''; + this.strlen = typeof(s) == 'string' ? s.length : 0; this.i = 0; this.tokens = []; //print_r(this); @@ -49,6 +49,10 @@ Pman.SearchTokenizer.prototype = { } } + // sort tokens longest first.. + + + // should not get here... return this.tokens; }, @@ -105,35 +109,39 @@ Pman.SearchTokenizer.prototype = { addStr : function (s,q) { //q == quoted.. q = q || false; - s = q ? s : String.trim(s); - if (!strlen(s)) { + s = q ? s : Roo.util.Format.trim(s); + if (!s.length) { return; } + if (!q) { - - if ((strtoupper(s) == 'AND') || (strtoupper(s) == 'OR')) { - this.tokens[] = new Text_SearchParser_Token_Op(strtoupper(s)); + if ((s.toUpperCase() == 'AND') || (s.toUpperCase() == 'OR')) { + this.tokens.push( { type: s.toUpperCase() }); return; } } - this.tokens[] = new Text_SearchParser_Token_String(s); - } + this.tokens.push( { type : 's' , v : s, q: q }); + }, - function getChar() + getChar : function () { + if (this.i >= this.strlen) { return false; } c = this.str[this.i]; this.i++; return c; - } - function ungetChar() + }, + ungetChar : function () { this.i--; } - - - + +}; + +Pman.SearchTokenizer.parse = function(v) { + var x = new Pman.SearchTokenizer(v); + return x.parse(); } \ No newline at end of file