fix string

pull/2/head
Matthew Butterick 10 years ago
parent a36a6c7f0d
commit ba24e81e21

@ -3,12 +3,12 @@
(define+provide/contract (starts-with? str starter)
(string? string? . -> . coerce/boolean?)
(define starter-pattern (regexp (format "^~a" starter)))
(regexp-match starter-pattern str))
(coerce/string? coerce/string? . -> . coerce/boolean?)
(and (<= (string-length starter) (string-length str))
(equal? (substring str 0 (string-length starter)) starter)))
(define+provide/contract (ends-with? str ender)
(string? string? . -> . coerce/boolean?)
(define ender-pattern (regexp (format "~a$" ender)))
(regexp-match ender-pattern str))
(coerce/string? coerce/string? . -> . coerce/boolean?)
(and (<= (string-length ender) (string-length str))
(equal? (substring str (- (string-length str) (string-length ender)) (string-length str)) ender)))

@ -83,6 +83,7 @@
(check-true ("foobar" . starts-with? . "f"))
(check-true ("foobar" . starts-with? . "foobar"))
(check-false ("foobar" . starts-with? . "bar"))
(check-false ("foobar" . starts-with? . "."))
(check-true ("foobar" . ends-with? . "bar"))
(check-true ("foobar" . ends-with? . "r"))
(check-true ("foobar" . ends-with? . "foobar"))

Loading…
Cancel
Save