aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/emacs-lisp/subr-x.el24
1 files changed, 15 insertions, 9 deletions
diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el
index 8a955277fed..849ac19d6a5 100644
--- a/lisp/emacs-lisp/subr-x.el
+++ b/lisp/emacs-lisp/subr-x.el
@@ -178,21 +178,27 @@ VARLIST can just be a plain tuple.
178 178
179(define-obsolete-function-alias 'string-reverse 'reverse "25.1") 179(define-obsolete-function-alias 'string-reverse 'reverse "25.1")
180 180
181(defsubst string-trim-left (string) 181(defsubst string-trim-left (string &optional regexp)
182 "Remove leading whitespace from STRING." 182 "Trim STRING of leading string matching REGEXP.
183 (if (string-match "\\`[ \t\n\r]+" string) 183
184REGEXP defaults to \"[ \\t\\n\\r]+\"."
185 (if (string-match (concat "\\`\\(?:" (or regexp "[ \t\n\r]+")"\\)") string)
184 (replace-match "" t t string) 186 (replace-match "" t t string)
185 string)) 187 string))
186 188
187(defsubst string-trim-right (string) 189(defsubst string-trim-right (string &optional regexp)
188 "Remove trailing whitespace from STRING." 190 "Trim STRING of trailing string matching REGEXP.
189 (if (string-match "[ \t\n\r]+\\'" string) 191
192REGEXP defaults to \"[ \\t\\n\\r]+\"."
193 (if (string-match (concat "\\(?:" (or regexp "[ \t\n\r]+") "\\)\\'") string)
190 (replace-match "" t t string) 194 (replace-match "" t t string)
191 string)) 195 string))
192 196
193(defsubst string-trim (string) 197(defsubst string-trim (string &optional trim-left trim-right)
194 "Remove leading and trailing whitespace from STRING." 198 "Trim STRING of leading and trailing strings matching TRIM-LEFT and TRIM-RIGHT.
195 (string-trim-left (string-trim-right string))) 199
200TRIM-LEFT and TRIM-RIGHT default to \"[ \\t\\n\\r]+\"."
201 (string-trim-left (string-trim-right string trim-right) trim-left))
196 202
197(defsubst string-blank-p (string) 203(defsubst string-blank-p (string)
198 "Check whether STRING is either empty or only whitespace." 204 "Check whether STRING is either empty or only whitespace."