diff --git a/pkgs/racket-doc/scribblings/reference/strings.scrbl b/pkgs/racket-doc/scribblings/reference/strings.scrbl index df7055db72..6b16f7c236 100644 --- a/pkgs/racket-doc/scribblings/reference/strings.scrbl +++ b/pkgs/racket-doc/scribblings/reference/strings.scrbl @@ -507,6 +507,13 @@ trimmed (which is an alternative to using a @tech{regular expression} (string-trim "aaaxaayaa" "aa") ]} +@defproc[(non-empty-string? [x any/c]) boolean?]{ +Returns @racket[#t] if @racket[x] is a string and is not empty; +returns @racket[#f] otherwise. +@history[#:added "6.2.900.15"]{} +} + + @; ---------------------------------------- @include-section["format.scrbl"] diff --git a/racket/collects/racket/string.rkt b/racket/collects/racket/string.rkt index 29e3e57367..6e8ad8d18b 100644 --- a/racket/collects/racket/string.rkt +++ b/racket/collects/racket/string.rkt @@ -5,7 +5,8 @@ string-trim string-normalize-spaces string-split - string-replace) + string-replace + non-empty-string?) (define string-append* (case-lambda [(strs) (apply string-append strs)] ; optimize common cases @@ -134,3 +135,6 @@ (if all? (regexp-replace* from* str to*) (regexp-replace from* str to*))) + +(define (non-empty-string? x) + (and (string? x) (not (zero? (string-length x)))))