Commits

camlspotter  committed 935c960

(partial) bug fix of find_non_excaped_slash

  • Participants
  • Parent commits 9045e80

Comments (0)

Files changed (1)

File pa/pa_regexp.ml

     Top.may_put_in_top rex
   ;;
 
-  let find_non_escaped_slash from s =
+  (* CR jfuruse; BUG: This is wrong.
+     It cannot parse correctly \\/
+  *)
+  let rec find_non_escaped_slash from s =
     let pos = String.rindex_from s from '/' in
     if pos = 0 || s.[pos-1] <> '\\' then pos
-    else raise Not_found (* flags cannot have "\/" *)
+    else find_non_escaped_slash (pos - 1) s
   ;;
 
   let split_by_non_escaped_slash s =
     (* CR jfuruse: concating back with '/' is ugly *)
     let rex_replace, flags = 
       match split_by_non_escaped_slash q.q_contents with
-      | [ rex; replace; flags ] -> rex ^ "/" ^ replace, flags
-      | [ rex; replace ] -> rex ^ "/" ^ replace, ""
+      | [ rex; replace; flags ] -> 
+(*
+          Format.eprintf "s3 %s // %s // %s@." rex replace flags;
+*)
+          rex ^ "/" ^ replace, flags
+      | [ rex; replace ] -> 
+(*
+          Format.eprintf "s2 %s // %s@." rex replace;
+*)
+          rex ^ "/" ^ replace, ""
+      | [] -> raise (Stream.Error 
+		       (Printf.sprintf "no / in pcre replace expr %S" q.q_contents))
       | _ -> raise (Stream.Error 
-		       (Printf.sprintf "too less or too many /s in pcre replace expr %S" q.q_contents))
+		       (Printf.sprintf "too many /s in pcre replace expr %S" q.q_contents))
     in
     let replace_global = ref false in
     let parse_flag = function