/** * * Class Searcher - a simple class for search in flash content * @autor Osiris LMS http://login.osirislms.com * @version 1.1 * */ class utils.Searcher { private var stExactValue, stValue, stValueLow; private var index, indexAll, rsValue, rsValueAll, allCoincidence; private var matchCase, diffEx, diffUC, txValue; function Searcher(txValue:Object, diffUC:Boolean, diffEx:Boolean, allCoincidence:Boolean) { index = 0; this.txValue = txValue; this.diffUC = diffUC; this.diffEx = diffEx; this.allCoincidence = allCoincidence; } public function getCoincidence(keyword) { if (keyword != "") { stValue = txValue.text; stValueLow = txValue.text.toLowerCase(); do { if (diffUC == true) { rsValue = stValue.indexOf(keyword, index); } else if (diffUC == false) { rsValue = stValueLow.indexOf(keyword.toLowerCase(), index); } if (diffEx == true) { stExactValue = stValue.substr(stValue.indexOf(keyword, index)-1, keyword.length+2); matchCase = getExactCoincidence(stExactValue); } else if (diffEx == false) { matchCase = false; } if (rsValue == -1) { index = 0; matchCase = true; } else if (rsValue != -1 && matchCase == true && diffEx == true) { index = rsValue+keyword.length; break; } else if (rsValue != -1 && matchCase == false && diffEx == true) { index = rsValue+keyword.length; matchCase = true; } else if (rsValue != -1 && diffEx == false) { index = rsValue+keyword.length; } } while (rsValue != -1 && matchCase == true); setSelection(keyword); return (allCoincidence)?getTotalCoincidence(keyword):0; } } public function setSelection(keyword) { if (rsValue != -1) { Selection.setFocus(txValue); Selection.setSelection(rsValue, rsValue+keyword.length); } } public function getTotalCoincidence(keyword:String) { var totalCoincidence = 0; var indexAll = 0; do { if (diffUC == true) { rsValueAll = stValue.indexOf(keyword, indexAll); } else if (diffUC == false) { rsValueAll = stValueLow.indexOf(keyword.toLowerCase(), indexAll); } if (diffEx == true) { stExactValue = stValue.substr(stValue.indexOf(keyword, indexAll)-1, keyword.length+2); matchCase = getExactCoincidence(stExactValue); } else if (diffEx == false) { matchCase = true; } if (rsValueAll == -1) { indexAll = 0; } else if (rsValueAll != -1 && matchCase == true) { totalCoincidence++; indexAll = rsValueAll+keyword.length; } else if (rsValueAll != -1 && matchCase == false) { indexAll = rsValueAll+keyword.length; } } while (rsValueAll != -1); return totalCoincidence; } private function getExactCoincidence() { var exValue = true; var fsValue = true; var lsValue = true; var frst = stExactValue.substr(0, 1); var lst = stExactValue.substr(stExactValue.length-1, 1); if ((frst.charCodeAt(0)>=65 && frst.charCodeAt(0)<=90) || (frst.charCodeAt(0)>=97 && frst.charCodeAt(0)<=122)) { fsValue = false; } if ((lst.charCodeAt(0)>=65 && lst.charCodeAt(0)<=90) || (lst.charCodeAt(0)>=97 && lst.charCodeAt(0)<=122)) { lsValue = false; } if (fsValue == true && lsValue == true) { exValue = true; } else { exValue = false; } return exValue; } }