Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added string-blank-p

  • Loading branch information...
commit 34e771cdeacbc2ae2c47c16eabfc677ba283f6ba 1 parent e97a0e0
@sroccaserra authored
Showing with 23 additions and 1 deletion.
  1. +8 −0 tools.el
  2. +15 −1 tools.elk
View
8 tools.el
@@ -47,6 +47,14 @@
(defun string-not-empty-p (str)
(not (string-empty-p str)))
+(defun string-blank-p (str)
+ (if (string-empty-p str)
+ t
+ (not (null (string-match "^\\(?:\s*\n\\)*$" str)))))
+
+(defun string-not-blank-p (str)
+ (not (string-blank-p str)))
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Undestructive alist functions
View
16 tools.elk
@@ -168,19 +168,32 @@
(deftest "an empty string is empty, a non empty string is not empty"
(assert-nil (string-empty-p "hello"))
+ (assert-nil (string-empty-p " "))
(assert-t (string-empty-p (copy-seq "")))
(assert-t (string-empty-p nil))
(assert-error "string" (string-empty-p 1)))
(deftest "I can tell if a sring is blank"
(assert-t (string-not-empty-p "hello"))
- (assert-nil (string-not-empty-p nil))
(assert-nil (string-not-empty-p ""))
+ (assert-nil (string-not-empty-p nil))
(assert-error "string" (string-not-empty-p 1)))
(deftest "symbols are non empty"
(assert-nil (string-empty-p 'hello)))
+(deftest "an empty string or a string containing only whitespaces is blank"
+ (assert-t (string-blank-p ""))
+ (assert-t (string-blank-p nil))
+ (assert-t (string-blank-p " \t\n")))
+
+(deftest "a string containing non whitespace chars is not blank"
+ (assert-t (string-not-blank-p "h"))
+ (assert-t (string-not-blank-p "hello"))
+ (assert-t (string-not-blank-p " hello"))
+ (assert-t (string-not-blank-p "hello "))
+ (assert-t (string-not-blank-p " hello ")))
+
;;;;;;;;;;;;;;;;;;;;;
;; Destructuring bind
@@ -224,3 +237,4 @@
(deftest "defun* can destructure"
(assert-equal [1 2 3]
(destructest* 1 '(2 3))))
+
Please sign in to comment.
Something went wrong with that request. Please try again.