update sugar/file docs

dev-refac-2020
Matthew Butterick 7 years ago
parent a4d560f7be
commit b7933d769b

@ -3,7 +3,7 @@
;; this is identical to `filename-extension` in `racket/path` ;; this is identical to `filename-extension` in `racket/path`
;; but will not treat hidden files as an extension (which IMHO is a bug) ;; but will not treat hidden files as an extension (which is a bug)
(define (filename-extension name) (define (filename-extension name)
(let* ([name (file-name-from-path name)] (let* ([name (file-name-from-path name)]
[name (and name (path->bytes name))]) [name (and name (path->bytes name))])

@ -8,7 +8,7 @@
@title{File extensions} @title{File extensions}
@defmodule[#:multi (sugar/file (submod sugar/file safe))] @defmodule[#:multi (sugar/file (submod sugar/file safe))]
These functions don't access the filesystem. These functions don't access the filesystem. @bold{Warning}: these functions adopt the simplifying assumption that the paths are encoded as ASCII or UTF-8. A fully precise treatment of paths would need to handle them as byte strings. If you need that, see the functions in @racketmodname[racket/path]. This library will remain naive.
Arguments that are @racket[pathish?] can take either a string or a path. For clarity below, I've used strings. Arguments that are @racket[pathish?] can take either a string or a path. For clarity below, I've used strings.
@ -30,10 +30,11 @@ Return the last file extension of @racket[_file-path] as a string, or @racket[#f
[file-path pathish?] [file-path pathish?]
[ext stringish?]) [ext stringish?])
boolean?] boolean?]
Return @racket[#t] if the last file extension of @racket[_file-path] is @racket[_ext], otherwise @racket[#f]. Return @racket[#t] if the last file extension of @racket[_file-path] is @racket[_ext], otherwise @racket[#f]. Not sensitive to case.
@examples[#:eval my-eval @examples[#:eval my-eval
(has-ext? "foo.txt" "txt") (has-ext? "foo.txt" "txt")
(has-ext? "foo.txt" "TXT")
(has-ext? "foo.txt" "jpg") (has-ext? "foo.txt" "jpg")
(has-ext? "foo.jpg.txt" "jpg")] (has-ext? "foo.jpg.txt" "jpg")]

Loading…
Cancel
Save