summary refs log tree commit diff stats
path: root/lib/pure
diff options
context:
space:
mode:
authorhlaaftana <10591326+hlaaftana@users.noreply.github.com>2020-01-26 16:02:07 +0300
committerAndreas Rumpf <rumpf_a@web.de>2020-01-26 14:02:07 +0100
commite7744b0909f90b16bb49cdbf8c99f6b1f8e1d23e (patch)
tree5ca0c71492cd1a407bfd32026d298c627210146e /lib/pure
parent6900da314ccd8c3f97dbeb340858b870bccadc89 (diff)
downloadNim-e7744b0909f90b16bb49cdbf8c99f6b1f8e1d23e.tar.gz
Rename isNilOrWhitespace to isEmptyOrWhitespace and make it use allCharsInSet (#13258)
* Rename isNilOrWhitespace to isEmptyOrWhitespace

* Make isEmptyOrWhitespace use allCharsInSet(Whitespace)
Diffstat (limited to 'lib/pure')
-rw-r--r--lib/pure/strutils.nim23
1 files changed, 13 insertions, 10 deletions
diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim
index 8e362a917..42a3ac579 100644
--- a/lib/pure/strutils.nim
+++ b/lib/pure/strutils.nim
@@ -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 =
@@ -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')