summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp/helpers.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/emacs-lisp/helpers.el')
-rw-r--r--lisp/emacs-lisp/helpers.el32
1 files changed, 32 insertions, 0 deletions
diff --git a/lisp/emacs-lisp/helpers.el b/lisp/emacs-lisp/helpers.el
index 73c2ff1c15c..8049f4e1d1d 100644
--- a/lisp/emacs-lisp/helpers.el
+++ b/lisp/emacs-lisp/helpers.el
@@ -37,6 +37,38 @@
(maphash (lambda (_k v) (push v values)) hash-table)
values))
+(defsubst string-empty-p (string)
+ "Check whether STRING is empty."
+ (string= string ""))
+
+(defsubst string-join (strings &optional separator)
+ "Join all STRINGS using SEPARATOR."
+ (mapconcat 'identity strings separator))
+
+(defsubst string-reverse (str)
+ "Reverse the string STR."
+ (apply 'string (nreverse (string-to-list str))))
+
+(defsubst string-trim-left (string)
+ "Remove leading whitespace from STRING."
+ (if (string-match "\\`[ \t\n\r]+" string)
+ (replace-match "" t t string)
+ string))
+
+(defsubst string-trim-right (string)
+ "Remove trailing whitespace from STRING."
+ (if (string-match "[ \t\n\r]+\\'" string)
+ (replace-match "" t t string)
+ string))
+
+(defsubst string-trim (string)
+ "Remove leading and trailing whitespace from STRING."
+ (string-trim-left (string-trim-right string)))
+
+(defsubst string-blank-p (string)
+ "Check whether STRING is either empty or only whitespace."
+ (string-empty-p (string-trim string)))
+
(provide 'helpers)
;;; helpers.el ends here