Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename isNilOrWhitespace to isEmptyOrWhitespace and make it use allCharsInSet #13258

Merged
merged 2 commits into from
Jan 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions lib/pure/strutils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2849,13 +2849,16 @@ iterator tokenize*(s: string, seps: set[char] = Whitespace): tuple[
break
i = j

proc isEmptyOrWhitespace*(s: string): bool {.noSideEffect, procvar, rtl,
extern: "nsuIsEmptyOrWhitespace".} =
## Checks if `s` is empty or consists entirely of whitespace characters.
result = s.allCharsInSet(Whitespace)

proc isNilOrWhitespace*(s: string): bool {.noSideEffect, procvar, rtl,
extern: "nsuIsNilOrWhitespace".} =
## Checks if `s` is nil or consists entirely of whitespace characters.
result = true
for c in s:
if not c.isSpaceAscii():
return false
extern: "nsuIsNilOrWhitespace",
deprecated: "use isEmptyOrWhitespace instead".} =
## Alias for isEmptyOrWhitespace
result = isEmptyOrWhitespace(s)

when isMainModule:
proc nonStaticTests =
Expand Down Expand Up @@ -2981,10 +2984,10 @@ when isMainModule:
doAssert isSpaceAscii('\l')
doAssert(not isSpaceAscii('A'))

doAssert(isNilOrWhitespace(""))
doAssert(isNilOrWhitespace(" "))
doAssert(isNilOrWhitespace("\t\l \v\r\f"))
doAssert(not isNilOrWhitespace("ABc \td"))
doAssert(isEmptyOrWhitespace(""))
doAssert(isEmptyOrWhitespace(" "))
doAssert(isEmptyOrWhitespace("\t\l \v\r\f"))
doAssert(not isEmptyOrWhitespace("ABc \td"))

doAssert isLowerAscii('a')
doAssert isLowerAscii('z')
Expand Down