Anthrino commented on code in PR #3460:
URL: https://github.com/apache/calcite/pull/3460#discussion_r1355648351


##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -603,6 +605,38 @@ public String regexpReplace(String s, String regex, String 
replacement,
       return Unsafe.regexpReplace(s, pattern, replacement, pos, occurrence);
     }
 
+    /** SQL {@code REGEXP_REPLACE} function with 3 arguments with
+     * {@code \\} based indexing for capturing groups.
+     */
+    public String regexpReplaceNonDollarIndexed(String s, String regex,
+        String replacement) {
+      // Preprocessing to convert double-backslash based indexing for capturing
+      // groups into $ based indices recognized by java regex.
+
+      // Explicitly escaping any $ symbols coming from input
+      // to ignore them from being considered as capturing group index.
+      String indexedReplacement = replacement.replace("\\\\", "\\")
+          .replace("$", "\\$");
+
+      // Check each occurrence of escaped chars, convert \<n> integers into
+      // $<n> indices, keep \\ and \$, throw an error for any other invalid 
escapes.
+      int lastOccIdx = 0;
+      while (lastOccIdx != -1) {

Review Comment:
   Thanks for the feedback Tanner, restructured the index lookup statement 
outside the loop to remove one if condition. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to