Fix (CHAR-SET->REGEXP (CHAR-SET <char>)).
authorTaylor R Campbell <campbell@mumble.net>
Sat, 6 Mar 2010 20:32:27 +0000 (15:32 -0500)
committerTaylor R Campbell <campbell@mumble.net>
Sat, 6 Mar 2010 20:32:27 +0000 (15:32 -0500)
Factor LET binding in RE-QUOTE-STRING's definition to the top level.
Perhaps CHAR-SET:RE-SPECIAL ought to be exported.

src/runtime/regexp.scm
src/runtime/rgxcmp.scm

index 6e3dd40906a2fe337b81b45da7ca643a5fabc0c6..b0e1254a0bb3c12ebccc591856deca3ee3de15cb 100644 (file)
@@ -211,5 +211,5 @@ USA.
                                      (fix:+ i 1)))))
                        (string-set! s i #\])))
                  s)))
-           (re-quote-string (car chars)))
+           (re-quote-string (string (car chars))))
        "")))
\ No newline at end of file
index a28745c54b6059617bd2a869f8d0b14d59b4b10f..63565d205957ecd10cae7ae6069d77434a610e0d 100644 (file)
@@ -218,36 +218,37 @@ USA.
                           (substring-move! string i j result (fix:+ p 2))
                           (loop (fix:- n 255) j (fix:+ p 257)))))))))))))
 
-(define re-quote-string
-  (let ((special (char-set #\[ #\] #\* #\. #\\ #\? #\+ #\^ #\$)))
-    (lambda (string)
-      (let ((end (string-length string)))
-       (let ((n
-              (let loop ((start 0) (n 0))
-                (let ((index
-                       (substring-find-next-char-in-set string start end
-                                                        special)))
-                  (if index
-                      (loop (1+ index) (1+ n))
-                      n)))))
-         (if (zero? n)
-             string
-             (let ((result (string-allocate (+ end n))))
-               (let loop ((start 0) (i 0))
-                 (let ((index
-                        (substring-find-next-char-in-set string start end
-                                                         special)))
-                   (if index
-                       (begin
-                         (substring-move! string start index result i)
-                         (let ((i (+ i (- index start))))
-                           (string-set! result i #\\)
-                           (string-set! result
-                                        (1+ i)
-                                        (string-ref string index))
-                           (loop (1+ index) (+ i 2))))
-                       (substring-move! string start end result i))))
-               result)))))))
+(define char-set:re-special
+  (char-set #\[ #\] #\* #\. #\\ #\? #\+ #\^ #\$))
+
+(define (re-quote-string string)
+  (let ((end (string-length string)))
+    (let ((n
+          (let loop ((start 0) (n 0))
+            (let ((index
+                   (substring-find-next-char-in-set string start end
+                                                    char-set:re-special)))
+              (if index
+                  (loop (1+ index) (1+ n))
+                  n)))))
+      (if (zero? n)
+         string
+         (let ((result (string-allocate (+ end n))))
+           (let loop ((start 0) (i 0))
+             (let ((index
+                    (substring-find-next-char-in-set string start end
+                                                     char-set:re-special)))
+               (if index
+                   (begin
+                     (substring-move! string start index result i)
+                     (let ((i (+ i (- index start))))
+                       (string-set! result i #\\)
+                       (string-set! result
+                                    (1+ i)
+                                    (string-ref string index))
+                       (loop (1+ index) (+ i 2))))
+                   (substring-move! string start end result i))))
+           result)))))
 \f
 ;;;; Char-Set Compiler