update sugar/string & docs

pull/2/head
Matthew Butterick 11 years ago
parent f9a68d0ae1
commit bfd916f64b

@ -0,0 +1,53 @@
#lang scribble/manual
@(require scribble/eval (for-label racket sugar))
@(define my-eval (make-base-eval))
@(my-eval `(require sugar))
@title{String}
@defmodule[sugar/string]
@defproc[
(starts-with?
[str stringish?]
[starter stringish?])
boolean?]
Return @racket[#t] if @racket[_str] starts with @racket[_starter], otherwise @racket[#f].
@examples[#:eval my-eval
(starts-with? "foobar" "foo")
(starts-with? "foobar" "foobar")
(starts-with? "foobar" "zam")
(starts-with? "foobar" "foobars")
]
@defproc[
(ends-with?
[str stringish?]
[ender stringish?])
boolean?]
Return @racket[#t] if @racket[_str] ends with @racket[_ender], otherwise @racket[#f].
@examples[#:eval my-eval
(ends-with? "foobar" "foo")
(ends-with? "foobar" "foobar")
(ends-with? "foobar" "zam")
(ends-with? "foobar" "foobars")
]
@defproc[
(capitalized?
[str stringish?])
boolean?]
Return @racket[#t] if @racket[_str] starts with a capital letter, otherwise @racket[#f].
@examples[#:eval my-eval
(capitalized? "Brennan")
(capitalized? "Brennan stinks")
(capitalized? "stinks")
]

@ -30,6 +30,8 @@ A collection of small functions to help make Racket code simpler & more readable
@include-section["list.scrbl"]
@include-section["string.scrbl"]
@include-section["license.scrbl"]
@index-section[]

@ -1,13 +1,11 @@
#lang racket/base
(require "define.rkt" "coerce.rkt")
(define+provide/contract (starts-with? str starter)
(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)
(coerce/string? coerce/string? . -> . coerce/boolean?)
(and (<= (string-length ender) (string-length str))

@ -141,4 +141,16 @@
(check-equal? (remove-ext* foo.txt-path) foo-path)
(check-equal? (remove-ext* (->path ".foo.txt")) (->path ".foo.txt"))
(check-not-equal? (remove-ext* foo.bar.txt-path) foo.bar-path) ; removes more than one ext
(check-equal? (remove-ext* foo.bar.txt-path) foo-path)
(check-equal? (remove-ext* foo.bar.txt-path) foo-path)
(check-true (starts-with? "foobar" "foo"))
(check-true (starts-with? "foobar" "foobar"))
(check-false (starts-with? "foobar" "zam"))
(check-false (starts-with? "foobar" "foobars"))
(check-true (ends-with? "foobar" "bar"))
(check-false (ends-with? "foobar" "zam"))
(check-true (ends-with? "foobar" "foobar"))
(check-false (ends-with? "foobar" "foobars"))
(check-true (capitalized? "Brennan"))
(check-false (capitalized? "foobar"))
Loading…
Cancel
Save