mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-09 05:14:20 +00:00
Adding isNilOrEmpty and isNilOrWhitespace
As discussed in #4184, this patch adds `isNilOrEmpty` and `isNilOrWhitespace` to `strutils`. It also modifies the existing `isSpace` proc slightly to exit early rather than looping through all characters in a string.
This commit is contained in:
@@ -95,5 +95,16 @@ assert(' '.repeat(0) == "")
|
||||
assert(" ".repeat(0) == "")
|
||||
assert(spaces(0) == "")
|
||||
|
||||
assert(isNilOrEmpty(""))
|
||||
assert(isNilOrEmpty(nil))
|
||||
assert(not isNilOrEmpty("test"))
|
||||
assert(not isNilOrEmpty(" "))
|
||||
|
||||
assert(isNilOrWhitespace(""))
|
||||
assert(isNilOrWhitespace(nil))
|
||||
assert(isNilOrWhitespace(" "))
|
||||
assert(isNilOrWhitespace("\t\l \v\r\f"))
|
||||
assert(not isNilOrWhitespace("ABc \td"))
|
||||
|
||||
main()
|
||||
#OUT ha/home/a1xyz/usr/bin
|
||||
|
||||
Reference in New Issue
Block a user