additional string-cursor fixes for snow

This commit is contained in:
Alex Shinn 2016-05-19 23:38:13 +09:00
parent 3d8fbafab9
commit 5804493889
5 changed files with 25 additions and 22 deletions

View file

@ -19,7 +19,7 @@
(define (extract-snowball-package bv) (define (extract-snowball-package bv)
(define (path-top path) (define (path-top path)
(substring path (string-cursor-start path) (string-find path #\/))) (substring-cursor path (string-cursor-start path) (string-find path #\/)))
(guard (exn (guard (exn
(else (else
(log-error "couldn't extract package.scm: " exn) (log-error "couldn't extract package.scm: " exn)

View file

@ -79,15 +79,15 @@
(test "" (string-trim " ")) (test "" (string-trim " "))
(test "" (string-trim " ")) (test "" (string-trim " "))
;; (test #t (string-prefix? "abc" "abc")) (test #t (string-prefix? "abc" "abc"))
;; (test #t (string-prefix? "abc" "abcde")) (test #t (string-prefix? "abc" "abcde"))
;; (test #f (string-prefix? "abcde" "abc")) (test #f (string-prefix? "abcde" "abc"))
;; (test #t (string-suffix? "abc" "abc")) (test #t (string-suffix? "abc" "abc"))
;; (test #f (string-suffix? "abc" "abcde")) (test #f (string-suffix? "abc" "abcde"))
;; (test #f (string-suffix? "abcde" "abc")) (test #f (string-suffix? "abcde" "abc"))
;; (test #f (string-suffix? "abcde" "cde")) (test #f (string-suffix? "abcde" "cde"))
;; (test #t (string-suffix? "cde" "abcde")) (test #t (string-suffix? "cde" "abcde"))
(test 3 (string-count "!a0 bc /.," char-alphabetic?)) (test 3 (string-count "!a0 bc /.," char-alphabetic?))

View file

@ -198,11 +198,14 @@
;;> Returns true iff \var{suffix} is a suffix of \var{str}. ;;> Returns true iff \var{suffix} is a suffix of \var{str}.
(define (string-suffix? suffix str) (define (string-suffix? suffix str)
(string-cursor=? (string-cursor-prev suffix (string-cursor-start suffix)) (let ((diff (- (string-size str) (string-size suffix))))
(and (>= diff 0)
(string-cursor=? (string-cursor-prev suffix
(string-cursor-start suffix))
(string-cursor-back (string-cursor-back
str str
(string-mismatch-right suffix str) (string-mismatch-right suffix str)
(- (string-size str) (string-size suffix))))) diff)))))
;;> The fundamental string iterator. Calls \var{kons} on each ;;> The fundamental string iterator. Calls \var{kons} on each
;;> character of \var{str} and an accumulator, starting with ;;> character of \var{str} and an accumulator, starting with
@ -323,14 +326,14 @@
;;> the cursor \var{i}. ;;> the cursor \var{i}.
(define (string-cursor-forward str cursor n) (define (string-cursor-forward str cursor n)
(if (zero? n) (if (positive? n)
cursor (string-cursor-forward str (string-cursor-next str cursor) (- n 1))
(string-cursor-forward str (string-cursor-next str cursor) (- n 1)))) cursor))
(define (string-cursor-back str cursor n) (define (string-cursor-back str cursor n)
(if (zero? n) (if (positive? n)
cursor (string-cursor-back str (string-cursor-prev str cursor) (- n 1))
(string-cursor-back str (string-cursor-prev str cursor) (- n 1)))) cursor))
;;> \procedure{(string-cursor<? i j)} ;;> \procedure{(string-cursor<? i j)}
;;> \procedure{(string-cursor>? i j)} ;;> \procedure{(string-cursor>? i j)}

View file

@ -97,7 +97,7 @@
;; not a tar-bomb and no absolute paths ;; not a tar-bomb and no absolute paths
(define (tar-safe? tarball) (define (tar-safe? tarball)
(define (path-top path) (define (path-top path)
(substring path 0 (string-find path #\/))) (substring-cursor path (string-cursor-start path) (string-find path #\/)))
(let ((files (map path-normalize (tar-files tarball)))) (let ((files (map path-normalize (tar-files tarball))))
(and (every path-relative? files) (and (every path-relative? files)
(or (< (length files) 2) (or (< (length files) 2)

View file

@ -350,7 +350,7 @@
(uri-with-path (uri-with-path
(uri-with-fragment (uri-with-query uri #f) #f) (uri-with-fragment (uri-with-query uri #f) #f)
(path-resolve path (path-resolve path
(if (string-suffix? (uri-path uri) "/") (if (string-suffix? "/" (uri-path uri))
(uri-path uri) (uri-path uri)
(path-directory (uri-path uri))))) (path-directory (uri-path uri)))))
(path-resolve path orig-uri))))) (path-resolve path orig-uri)))))