// Javascript RegEx Wrappers // @Version 1.0 // @Author: Luke Wigley /* wrapper functions to provide global functions for - Replace - Search - Match */ function RegExp_Replace(str, repattern,rep,flags){ // returns a new string return str.replace(RegExp(repattern,flags),rep); } function RegExp_Search(str,repattern, flags){ // returns the index of the regular expression inside the string. // Otherwise, it returns -1 return str.search(RegExp(repattern,flags)); } function RegExp_Match(str, repattern, flags) { // returns VOID if no match, or a JS array (ilk is #jobject) return str.match(RegExp(repattern, flags)); } function RegExp_MatchList(str, repattern, flags) { // returns VOID if no match, or list of matches matches = list(); re = new RegExp(repattern, flags); arr = str.match(re); if (arr != null) { for (i in arr) { matches.append(arr[i]);} } return matches } function RegExp_exec(str, repattern, flags) { // returns VOID if no match, or list of matches matches = propList(); re = RegExp(repattern, flags); arr = re.exec(str); if (arr != null) { for (i in arr) { matches.addProp(i, arr[i]);} } //matches.addProp("leftContext", re.leftContext) //matches.addProp("rightContext", re.rightContext) return matches } function RegExp_Split(str, repattern, flags) { // returns VOID if no match, or a JS array (ilk is #jobject) return str.split(RegExp(repattern, flags)); } function RegExp_SplitIntoList(str, repattern, flags) { // returns VOID if no match, or lingo list matches = list(); arr = str.split(RegExp(repattern, flags)); if (arr != null) { for (i in arr) { matches.append(arr[i]);} } return matches; } // Utility Functions function jsArrayToList (arr) { // convert a JS array into a lingo list rList = list(); if (arr != null) { for (i in arr) { rList.append(arr[i]);} } return rList; } function jsArrayToPropList (arr) { // convert a JS array into a lingo list rList = propList(); if (arr != null) { for (i in arr) { rList.addProp(i, arr[i]);} } return rList; }