//-------------------------------------------------------------------------\r
\r
// All the regex function accept a set of flags, this can be one or more of:\r
-// g = Perform match against each substring rather than just the first (greedy)\r
-// n = Perform newline-sensitive matching\r
-// i = Perform cases insensitive matching\r
+// g = Perform match against each substring rather than just the first (greedy)\r
+// n = Perform newline-sensitive matching\r
+// i = Perform cases insensitive matching\r
\r
//Purely check if a regex expression produces match in the input string\r
// Returns 1 on match, 0 on no match\r
-// E.g\r
+// E.g\r
// move (regexp_match('the quick brown fox jumps over the lazy dog.', 'fox', 'g'))\r
function regexp_match global string str string pattern string flags returns integer\r
- local integer l_iReturn\r
- local pointer l_pStr l_pPattern l_pFlags\r
- \r
- getaddress of str to l_pStr\r
- getaddress of pattern to l_pPattern\r
- getaddress of flags to l_pFlags\r
- \r
- move (RegexpMatch(l_pStr, l_pPattern, l_pFlags, ERRORS_TO_STDERR)) to l_iReturn\r
- \r
- function_return l_iReturn\r
+ local integer l_iReturn\r
+ local pointer l_pStr l_pPattern l_pFlags\r
+ \r
+ getaddress of str to l_pStr\r
+ getaddress of pattern to l_pPattern\r
+ getaddress of flags to l_pFlags\r
+ \r
+ move (RegexpMatch(l_pStr, l_pPattern, l_pFlags, ERRORS_TO_STDERR)) to l_iReturn\r
+ \r
+ function_return l_iReturn\r
end_function \r
\r
//Return a string containing all regex matches in the input string\r
// E.g\r
// move (regexp_matches('the quick brown fox jumps over the la\{zy d"og.', 'fox|(the)|brown|(la\\\{zy)|(d"og)', 'g')) to myString\r
function regexp_matches global string str string pattern string flags returns string\r
- local integer l_iReturn\r
- local pointer l_pStr l_pPattern l_pFlags l_pOut\r
- local string l_sOut l_sReturn\r
- \r
- move "" to l_sReturn\r
- getaddress of str to l_pStr\r
- getaddress of pattern to l_pPattern\r
- getaddress of flags to l_pFlags\r
- zerostring MAX_DFREGEX_BUFFER to l_sOut\r
- getaddress of l_sOut to l_pOut\r
- \r
- move (RegexpMatches(l_pStr, l_pPattern, l_pFlags, l_pOut, MAX_DFREGEX_BUFFER, ERRORS_TO_STDERR)) to l_iReturn\r
- \r
- if (l_iReturn = 0);\r
- move (cstring(l_sOut)) To l_sReturn\r
- else begin\r
- if (l_iReturn = -1);\r
- custom_error ERROR_CODE_REGEX_BUFFER_OVERFLOW$ ERROR_MSG_REGEX_BUFFER_OVERFLOW MAX_DFREGEX_BUFFER \r
- if (l_iReturn = -2);\r
+ local integer l_iReturn\r
+ local pointer l_pStr l_pPattern l_pFlags l_pOut\r
+ local string l_sOut l_sReturn\r
+ \r
+ move "" to l_sReturn\r
+ getaddress of str to l_pStr\r
+ getaddress of pattern to l_pPattern\r
+ getaddress of flags to l_pFlags\r
+ zerostring MAX_DFREGEX_BUFFER to l_sOut\r
+ getaddress of l_sOut to l_pOut\r
+ \r
+ move (RegexpMatches(l_pStr, l_pPattern, l_pFlags, l_pOut, MAX_DFREGEX_BUFFER, ERRORS_TO_STDERR)) to l_iReturn\r
+ \r
+ if (l_iReturn = 0);\r
+ move (cstring(l_sOut)) To l_sReturn\r
+ else begin\r
+ if (l_iReturn = -1);\r
+ custom_error ERROR_CODE_REGEX_BUFFER_OVERFLOW$ ERROR_MSG_REGEX_BUFFER_OVERFLOW MAX_DFREGEX_BUFFER \r
+ if (l_iReturn = -2);\r
custom_error ERROR_CODE_REGEX_COMPILE_FAILURE$ ERROR_MSG_REGEX_COMPILE_FAILURE\r
- move "" to l_sReturn\r
- end\r
- \r
- function_return l_sReturn\r
+ move "" to l_sReturn\r
+ end\r
+ \r
+ function_return l_sReturn\r
end_function \r
\r
//Perform a replacement on the input string all matches with the given pattern\r
// E.g.\r
// move (regexp_replace('22 quick brown foxes jump over the 44 lazy dogs.', '([0-9]*).* (foxes) .* ([0-9]*) .* (dogs).*', 'SELECT build_data(\1,\2), build_data(\3,\4);', 'g')) to myString\r
function regexp_replace global string str string pattern string replacement string flags returns string\r
- local integer l_iReturn\r
- local pointer l_pStr l_pPattern l_pFlags l_pReplacement l_pOut\r
- local string l_sOut l_sReturn\r
- \r
- move "" to l_sReturn\r
- getaddress of str to l_pStr\r
- getaddress of pattern to l_pPattern\r
- getaddress of flags to l_pFlags\r
- getaddress of replacement to l_pReplacement\r
- zerostring MAX_DFREGEX_BUFFER to l_sOut\r
- getaddress of l_sOut to l_pOut\r
- \r
- move (RegexpReplace(l_pStr, l_pPattern, l_pReplacement, l_pFlags, l_pOut, MAX_DFREGEX_BUFFER, ERRORS_TO_STDERR)) to l_iReturn\r
- \r
- if (l_iReturn = 0);\r
- move (cstring(l_sOut)) To l_sReturn\r
- else begin\r
- if (l_iReturn = -1);\r
- custom_error ERROR_CODE_REGEX_BUFFER_OVERFLOW$ ERROR_MSG_REGEX_BUFFER_OVERFLOW MAX_DFREGEX_BUFFER \r
- if (l_iReturn = -2);\r
+ local integer l_iReturn\r
+ local pointer l_pStr l_pPattern l_pFlags l_pReplacement l_pOut\r
+ local string l_sOut l_sReturn\r
+ \r
+ move "" to l_sReturn\r
+ getaddress of str to l_pStr\r
+ getaddress of pattern to l_pPattern\r
+ getaddress of flags to l_pFlags\r
+ getaddress of replacement to l_pReplacement\r
+ zerostring MAX_DFREGEX_BUFFER to l_sOut\r
+ getaddress of l_sOut to l_pOut\r
+ \r
+ move (RegexpReplace(l_pStr, l_pPattern, l_pReplacement, l_pFlags, l_pOut, MAX_DFREGEX_BUFFER, ERRORS_TO_STDERR)) to l_iReturn\r
+ \r
+ if (l_iReturn = 0);\r
+ move (cstring(l_sOut)) To l_sReturn\r
+ else begin\r
+ if (l_iReturn = -1);\r
+ custom_error ERROR_CODE_REGEX_BUFFER_OVERFLOW$ ERROR_MSG_REGEX_BUFFER_OVERFLOW MAX_DFREGEX_BUFFER \r
+ if (l_iReturn = -2);\r
custom_error ERROR_CODE_REGEX_COMPILE_FAILURE$ ERROR_MSG_REGEX_COMPILE_FAILURE\r
- move "" to l_sReturn\r
- end\r
- \r
- function_return l_sReturn\r
+ move "" to l_sReturn\r
+ end\r
+ \r
+ function_return l_sReturn\r
end_function \r
\r
// Parse an output string from regexp_matches to get the result count\r
// E.g\r
// move (regexp_matches_count(myRegexMatchesOutput)) to myInt\r
function regexp_matches_count global string argv returns integer\r
- local integer l_iCount l_i\r
- local string l_sChar l_sLast\r
- \r
- move "" to l_sChar\r
- move "" to l_sLast\r
- for l_i from 0 to (length(argv))\r
- move (mid(argv,1,l_i)) to l_sChar\r
- if ((l_sChar = '{') and (l_sLast <> '\')) increment l_iCount\r
- move l_sChar to l_sLast\r
- loop\r
- \r
- function_return l_iCount\r
+ local integer l_iCount l_i\r
+ local string l_sChar l_sLast\r
+ \r
+ move "" to l_sChar\r
+ move "" to l_sLast\r
+ for l_i from 0 to (length(argv))\r
+ move (mid(argv,1,l_i)) to l_sChar\r
+ if ((l_sChar = '{') and (l_sLast <> '\')) increment l_iCount\r
+ move l_sChar to l_sLast\r
+ loop\r
+ \r
+ function_return l_iCount\r
end_function\r
\r
// Parse an output string from regexp_matches to get the result at an index\r
+// This can then be treated as csv data.\r
// E.g\r
// move (regexp_matches_item(myRegexMatchesOutput,muInt)) to myString\r
+// object mt is a StringTokenizer\r
+// end_object\r
+// move (regexp_matches_count(myString)) to myCount\r
+// for i from 1 to myCount\r
+// move (regexp_matches_item(myString,i)) to bufString\r
+// send delete_data to mt \r
+// send set_string_csv to mt bufString\r
+// get token_count of mt to myTokenCount\r
+// for j from 0 to myTokenCount\r
+// get token_value of mt item j to bufString\r
+// showln i "-" j ")" buf\r
+// loop\r
+// loop\r
function regexp_matches_item global string argv integer argv2 returns string\r
- local integer l_iCount l_i l_iOpen l_iQuot\r
- local string l_sChar l_sLast l_sNext l_sBuf\r
- \r
- move 0 to l_iCount\r
- move 0 to l_iOpen\r
- move 0 to l_iQuot\r
- move "" to l_sLast\r
- for l_i from 0 to (length(argv))\r
- move (mid(argv,1,l_i)) to l_sChar\r
- move (mid(argv,1,l_i-1)) to l_sLast\r
- \r
- if ((l_sChar = '{') and (l_sLast <> '\')) increment l_iCount \r
- if (l_iCount <> argv2) break begin\r
+ local integer l_iCount l_i\r
+ local string l_sChar l_sLast l_sReturn\r
+ \r
+ move "" to l_sChar\r
+ move "" to l_sLast\r
+ move "" to l_sReturn\r
+ for l_i from 0 to (length(argv))\r
+ move (mid(argv,1,l_i)) to l_sChar\r
+ move (mid(argv,1,l_i-1)) to l_sLast\r
+ if ((l_sChar = '{') and (l_sLast <> '\')) increment l_iCount \r
+ if ((l_sChar = '}') and (l_sLast <> '\') and (l_iCount = argv2)) break\r
+ if (((l_sChar = '{') and (l_sLast <> '\')) or (l_iCount < argv2)) break begin\r
+ \r
+ append l_sReturn l_sChar\r
+ loop\r
+ \r
+ function_return l_sReturn\r
+end_function\r
+\r
+// Parse an output string from regexp_matches to get the result at an index\r
+// stripping out all escaping.\r
+// E.g\r
+// move (regexp_matches_item_stripped(myRegexMatchesOutput,muInt)) to myString\r
+function regexp_matches_item_stripped global string argv integer argv2 returns string\r
+ local integer l_iCount l_i l_iOpen l_iQuot\r
+ local string l_sChar l_sLast l_sNext l_sBuf\r
+ \r
+ move 0 to l_iCount\r
+ move 0 to l_iOpen\r
+ move 0 to l_iQuot\r
+ move "" to l_sLast\r
+ for l_i from 0 to (length(argv))\r
+ move (mid(argv,1,l_i)) to l_sChar\r
+ move (mid(argv,1,l_i-1)) to l_sLast\r
+ \r
+ if ((l_sChar = '{') and (l_sLast <> '\')) increment l_iCount \r
+ if (l_iCount <> argv2) break begin\r
\r
- move (mid(argv,1,l_i+1)) to l_sNext\r
- \r
- if ((l_sChar = '{') and not (l_iQuot)) begin\r
- move 1 to l_iOpen\r
- move "" to l_sBuf \r
- end \r
- else if ((l_sChar = '}') and not (l_iQuot)) begin\r
- move 0 to l_iOpen\r
- end \r
- else if ((l_sChar = '"') and (l_sLast <> '\')) begin\r
- if (l_iQuot) move 0 to l_iQuot\r
- else move 1 to l_iQuot\r
- end\r
- if ((l_sChar = ',') and not (l_iOpen)) break begin\r
- if (((l_sChar = '{') or (l_sChar = '}')) and not (l_iQuot)) break begin\r
- if ((l_sChar = '"') and (l_sLast <> '\')) break begin\r
- if ((l_iQuot) and (l_sChar = '\') and ((l_sNext = '"') or (l_sNext = '\'))) break begin\r
- \r
- append l_sBuf l_sChar \r
- loop\r
- \r
- function_return l_sBuf\r
-end_function
\ No newline at end of file
+ move (mid(argv,1,l_i+1)) to l_sNext\r
+ \r
+ if ((l_sChar = '{') and not (l_iQuot)) begin\r
+ move 1 to l_iOpen\r
+ move "" to l_sBuf \r
+ end \r
+ else if ((l_sChar = '}') and not (l_iQuot)) begin\r
+ move 0 to l_iOpen\r
+ end \r
+ else if ((l_sChar = '"') and (l_sLast <> '\')) begin\r
+ if (l_iQuot) move 0 to l_iQuot\r
+ else move 1 to l_iQuot\r
+ end\r
+ if ((l_sChar = ',') and not (l_iOpen)) break begin\r
+ if (((l_sChar = '{') or (l_sChar = '}')) and not (l_iQuot)) break begin\r
+ if ((l_sChar = '"') and (l_sLast <> '\')) break begin\r
+ if ((l_iQuot) and (l_sChar = '\') and ((l_sNext = '"') or (l_sNext = '\'))) break begin\r
+ \r
+ append l_sBuf l_sChar \r
+ loop\r
+ \r
+ function_return l_sBuf\r
+end_function\r