Skip to content

Commit

Permalink
Rename isNilOrWhitespace to isEmptyOrWhitespace and make it use allCh…
Browse files Browse the repository at this point in the history
…arsInSet (#13258)

* Rename isNilOrWhitespace to isEmptyOrWhitespace

* Make isEmptyOrWhitespace use allCharsInSet(Whitespace)
  • Loading branch information
metagn authored and Araq committed Jan 26, 2020
1 parent 6900da3 commit e7744b0
Showing 1 changed file with 13 additions and 10 deletions.
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

0 comments on commit e7744b0

Please sign in to comment.