From 5f43b3a91323997e7c7a3cca4188d711dd26a64c Mon Sep 17 00:00:00 2001 From: Vincent St-Amour Date: Tue, 8 Sep 2015 10:09:29 -0500 Subject: [PATCH] Move `non-empty-string?` to `racket/string`. From `unstable/contract`. --- pkgs/racket-doc/scribblings/reference/strings.scrbl | 7 +++++++ racket/collects/racket/string.rkt | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) 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)))))