
Originally Posted by
Woulf
$L.match=evaluate(parse("toupper("+1 in $L.acntr in definitions in $L.aafile+" in $script)"+$L.aoper+str(3 in $L.acntr in definitions in $L.aafile), 4))=true
The result is:
$L.match=cateogry in $script={"HW", "SW", "TELE"}=true (for the first one)
$L.match=subcateogry in $script#{"ABC", "DEF", "GHI"}=true (for the second one)
Hi there, this sounds like an easy job for RegExp.
PHP Code:
/*
@txt {String} - text to compare
@arrIn {Array} - an array of strings to compare to
@equal {Boolean} - "is exactly" - true, "starts with" - false
*/
regTest = function(txt,arrIn,equal) {
/*
* "starts with" is ^
* join the array with | chars, the | is 'or'
*/
arrInJoin = '^'+arrIn.join('|');
/* if "needs to be equal"
* the string has to match from the start '^' to finish '$'
*/
if(equal) arrInJoin+='$';
return RegExp(arrInJoin,'ig').test(txt);
}
Of course, this is not a full solution as you have the data in an structured array. Well, let's try ...
PHP Code:
/* simulate the SCFile array of structure */
function CatDefs() {
this.definitions = [];
this.cats = [];
this.subcats = [];
this.regTest = function(txt,arrIn,equal) {
arrInJoin = '^'+arrIn.join('|');
if(equal) arrInJoin+='$';
return RegExp(arrInJoin,'ig').test(txt);
}
/* fill the "definitions" field */
this.init = function() {
for(i=0;i<4;i++) {
this.definitions.push(['cat'+i,'empty','subcat'+i]);
}
/* here's the trick, iterate through definitions
* get the correct data out to "array of char" type
* you can always put that in a "reusable", thread array
* so that it happens only once */
for(a in this.definitions) {
this.cats.push(this.definitions[a][0]);
this.subcats.push(this.definitions[a][2]);
}
}
}
var cDefs=new CatDefs();
cDefs.init();
print( cDefs.regTest('cat1',cDefs.cats,true) )
print( cDefs.regTest('subcat1',cDefs.subcats,false) )
Hope this helps a bit. RegExp is fun!
Bookmarks