From 0879347cde425bc49371482e4695ae8d57f2e125 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Tue, 16 Feb 2016 18:36:16 -0800 Subject: [PATCH] add `whitespace?` to unstable/typography --- pollen/private/ts.rktd | 2 +- pollen/scribblings/typography.scrbl | 32 +++++++++++++++++++++++++++++ pollen/unstable/typography.rkt | 4 +++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/pollen/private/ts.rktd b/pollen/private/ts.rktd index a471ae6..42584b1 100644 --- a/pollen/private/ts.rktd +++ b/pollen/private/ts.rktd @@ -1 +1 @@ -1455307528 +1455676575 diff --git a/pollen/scribblings/typography.scrbl b/pollen/scribblings/typography.scrbl index e4157ec..8f7a8f3 100644 --- a/pollen/scribblings/typography.scrbl +++ b/pollen/scribblings/typography.scrbl @@ -69,4 +69,36 @@ Be warned: there are many edge cases this function does not handle well. @examples[#:eval my-eval (code:comment @#,t{Argh: this edge case is not handled properly}) (wrap-hanging-quotes '(p "“" (em "What?") "We need to hang quotes?”")) +] + +@defproc[ +(whitespace? +[v any/c]) +boolean?] +A predicate that returns @racket[#t] for any stringlike @racket[_v] that's entirely whitespace, but also the empty string, as well as lists and vectors that are made only of @racket[whitespace?] members. Following the @racket[regexp-match] convention, @racket[whitespace?] does not return @racket[#t] for a nonbreaking space. If you prefer that behavior, use @racket[whitespace/nbsp?]. + + +@examples[#:eval my-eval +(whitespace? "\n\n ") +(whitespace? (string->symbol "\n\n ")) +(whitespace? "") +(whitespace? '("" " " "\n\n\n" " \n")) +(define nonbreaking-space (format "~a" #\u00A0)) +(whitespace? nonbreaking-space) +] + +@defproc[ +(whitespace/nbsp? +[v any/c]) +boolean?] +Like @racket[whitespace?], but also returns @racket[#t] for nonbreaking spaces. + + +@examples[#:eval my-eval +(whitespace/nbsp? "\n\n ") +(whitespace/nbsp? (string->symbol "\n\n ")) +(whitespace/nbsp? "") +(whitespace/nbsp? '("" " " "\n\n\n" " \n")) +(define nonbreaking-space (format "~a" #\u00A0)) +(whitespace/nbsp? nonbreaking-space) ] \ No newline at end of file diff --git a/pollen/unstable/typography.rkt b/pollen/unstable/typography.rkt index b0ad454..3a96bdc 100644 --- a/pollen/unstable/typography.rkt +++ b/pollen/unstable/typography.rkt @@ -1,5 +1,7 @@ #lang racket/base -(require racket/list sugar/define sugar/test txexpr racket/match sugar/unstable/container sugar/coerce sugar/unstable/len racket/string "../private/to-string.rkt" ) +(require racket/list sugar/define sugar/test txexpr racket/match sugar/unstable/container sugar/coerce sugar/unstable/len "../private/whitespace.rkt") + +(provide whitespace? whitespace/nbsp?) (define (make-replacer query+replacement) (let ([queries (map car query+replacement)]