diff --git a/lib/chibi/regexp.scm b/lib/chibi/regexp.scm index 881e1ff7..e113e3dc 100644 --- a/lib/chibi/regexp.scm +++ b/lib/chibi/regexp.scm @@ -510,38 +510,16 @@ (char-word-constituent? (string-cursor-ref str (string-cursor-prev str i))))) (define (match/bog str i ch start end matches) - (and - (string-cursor? i start) (or (string-cursor>=? i end) - (let* ((i2 (string-cursor-next str i)) - (ch2 (string-cursor-ref str i2))) - (match/bog str i2 ch2 start end matches))))) + (let ((m (regexp-search re:grapheme str + (string-offset->index str i) + (string-offset->index str end)))) + (and m (string-cursor<=? (regexp-match-submatch-end m 0) i)))))) (define (lookup-char-set name flags) (cond @@ -961,3 +939,5 @@ (error "unknown match replacement" (car ls))))))) (else (lp (cdr ls) (cons (car ls) res)))))) + +(define re:grapheme (regexp 'grapheme)) diff --git a/tests/regexp-tests.scm b/tests/regexp-tests.scm index 87bafb87..b62c1ac9 100644 --- a/tests/regexp-tests.scm +++ b/tests/regexp-tests.scm @@ -152,6 +152,9 @@ (test-re '("한") 'grapheme "한") (test-re '("글") 'grapheme "글") +(test-re '("한") '(: bog grapheme eog) "한") +(test-re #f '(: "ᄒ" bog grapheme eog "ᆫ") "한") + (test '("123" "456" "789") (regexp-extract '(+ digit) "abc123def456ghi789")) (test '("123" "456" "789") (regexp-extract '(* digit) "abc123def456ghi789")) (test '("abc" "def" "ghi") (regexp-split '(+ digit) "abc123def456ghi789"))