maidh91 / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Suggestion: Strings.isBlank() #397

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have found a method like this to be very useful when validating user input, 
especially from a servlet.

Essentially: return Strings.nullToEmpty(s).trim().isEmpty();

But it could be implemented more efficiently since the trim() is unnecessary: 
once a non-whitespace character is found you can return false. (And isEmpty() 
is 1.6)

Original issue reported on code.google.com by ray.j.gr...@gmail.com on 11 Aug 2010 at 11:42

GoogleCodeExporter commented 9 years ago
If you want a method that returns false immediately when a non-whitespace 
character is found:

CharMatcher.WHITESPACE.matchesAllOf(Strings.nullToEmpty(s))

Original comment by fin...@gmail.com on 15 Aug 2010 at 12:53

GoogleCodeExporter commented 9 years ago
Oh hey, this is a duplicate of 352. (And 387.)

Original comment by ray.j.gr...@gmail.com on 13 Sep 2010 at 7:41

GoogleCodeExporter commented 9 years ago

Original comment by boppenh...@google.com on 23 Sep 2010 at 5:05

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:15

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:09