'#(" " "." "w" "_" "(" ")" "'" "\"" "$" "\\" "/" "<" ">"))
(define (substring-find-next-char-of-syntax string start end table code)
- (guarantee-substring string start end 'SUBSTRING-FIND-NEXT-CHAR-OF-SYNTAX)
- (let loop ((index start))
- (and (fix:< index end)
- (if (char=? code (char->syntax-code table (string-ref string index)))
- index
- (loop (fix:+ index 1))))))
+ (guarantee 8-bit-string? string 'substring-find-next-char-of-syntax)
+ (let ((index
+ (string-find-first-index (syntax-code-predicate code)
+ (string-slice string start end))))
+ (and index
+ (fix:+ start index))))
(define (substring-find-next-char-not-of-syntax string start end table code)
- (guarantee-substring string start end
- 'SUBSTRING-FIND-NEXT-CHAR-NOT-OF-SYNTAX)
- (let loop ((index start))
- (and (fix:< index end)
- (if (char=? code (char->syntax-code table (string-ref string index)))
- (loop (fix:+ index 1))
- index))))
+ (guarantee 8-bit-string? string 'substring-find-next-char-not-of-syntax)
+ (let ((index
+ (string-find-first-index (let ((pred (syntax-code-predicate code)))
+ (lambda (char)
+ (not (pred char))))
+ (string-slice string start end))))
+ (and index
+ (fix:+ start index))))
+
+(define (syntax-code-predicate code)
+ (lambda (char)
+ (char=? code (char->syntax-code char))))
(define (char->syntax-code table char)
(string-ref (vector-ref char-syntax-codes
(define (regsexp-match-input-port crsexp port)
(let ((caller 'REGSEXP-MATCH-INPUT-PORT))
- (guarantee-compiled-regsexp crsexp caller)
+ (guarantee compiled-regsexp? crsexp caller)
(guarantee textual-input-port? port caller)
(%top-level-match crsexp
(%char-source->position
(define (regsexp-match-string crsexp string #!optional start end)
(let ((caller 'REGSEXP-MATCH-STRING))
- (guarantee-compiled-regsexp crsexp caller)
- (guarantee-string string caller)
- (let* ((end
- (let ((length (string-length string)))
- (if (default-object? end)
- length
- (begin
- (guarantee-substring-end-index end length caller)
- end))))
- (start
- (if (default-object? start)
- 0
- (begin
- (guarantee-substring-start-index start end caller)
- start))))
+ (guarantee compiled-regsexp? crsexp caller)
+ (guarantee string? string caller)
+ (let* ((end (fix:end-index end (string-length string) caller))
+ (start (fix:start-index start end caller)))
(%top-level-match crsexp
(cons start (%make-substring string start end))))))
vector-8b-ref
vector-8b-set!)
(export ()
- guarantee-substring
- guarantee-substring-end-index
- guarantee-substring-start-index
string-search-all
string-search-backward
string-search-forward
substring-search-all
substring-search-backward
substring-search-forward
- substring?)
- (initialization (initialize-package!)))
+ substring?))
(define-package (runtime ustring)
(files "ustring")
substring=?)
(export ()
(substring string-copy)
+ 8-bit-string?
grapheme-cluster-length
grapheme-cluster-slice
list->string
(declare (integrate-operator guarantee-string))
(define-guarantee string "string")
-(define-integrable (guarantee-2-strings object1 object2 procedure)
- (if (not (and (string? object1) (string? object2)))
- (guarantee-2-strings/fail object1 object2 procedure)))
-
-(define (guarantee-2-strings/fail object1 object2 procedure)
- (cond ((not (string? object1))
- (error:wrong-type-argument object1 "string" procedure))
- ((not (string? object2))
- (error:wrong-type-argument object2 "string" procedure))))
-
(define-integrable (guarantee-string-index object caller)
(if (not (index-fixnum? object))
(error:wrong-type-argument object "string index" caller)))
(register-predicate! legacy-string? 'legacy-string '<= string?)
(register-predicate! full-string? 'full-string '<= string?)
(register-predicate! slice? 'string-slice '<= string?)
+ (register-predicate! 8-bit-string? '8-bit-string '<= string?)
(register-predicate! ->string-component? '->string-component))
\f
;;;; Strings
(list 'fill-with grapheme-cluster-string? " ")
(list 'clip? boolean? #t))))
\f
+(define (8-bit-string? object)
+ (and (string? object)
+ (string-8-bit? object)))
+
(define (string-8-bit? string)
(receive (string start end) (translate-slice string 0 (string-length string))
(if (legacy-string? string)