summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorJean-Christophe Helary <jean.christophe.helary@gmail.com>2017-05-19 14:27:10 +0300
committerEli Zaretskii <eliz@gnu.org>2017-05-19 14:27:10 +0300
commitc189986b241cbe79b0e027fa08bba710ac645bb3 (patch)
tree3dd75515917ccc4f02c5ba053bd579c504814cd6 /lisp/emacs-lisp
parentcecd99d826547d4bfd918bba476eda206f0f0afc (diff)
downloademacs-c189986b241cbe79b0e027fa08bba710ac645bb3.tar.gz
emacs-c189986b241cbe79b0e027fa08bba710ac645bb3.tar.bz2
emacs-c189986b241cbe79b0e027fa08bba710ac645bb3.zip
Add an optional arguments to string-trim
* lisp/emacs-lisp/subr-x.el (string-trim-left, string-trim-right) (string-trim): Add optional args that serve as defaults per the original behavior. (Bug#26908)
Diffstat (limited to 'lisp/emacs-lisp')
-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.
(define-obsolete-function-alias 'string-reverse 'reverse "25.1")
-(defsubst string-trim-left (string)
- "Remove leading whitespace from STRING."
- (if (string-match "\\`[ \t\n\r]+" string)
+(defsubst string-trim-left (string &optional regexp)
+ "Trim STRING of leading string matching REGEXP.
+
+REGEXP defaults to \"[ \\t\\n\\r]+\"."
+ (if (string-match (concat "\\`\\(?:" (or regexp "[ \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)
+(defsubst string-trim-right (string &optional regexp)
+ "Trim STRING of trailing string matching REGEXP.
+
+REGEXP defaults to \"[ \\t\\n\\r]+\"."
+ (if (string-match (concat "\\(?:" (or regexp "[ \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-trim (string &optional trim-left trim-right)
+ "Trim STRING of leading and trailing strings matching TRIM-LEFT and TRIM-RIGHT.
+
+TRIM-LEFT and TRIM-RIGHT default to \"[ \\t\\n\\r]+\"."
+ (string-trim-left (string-trim-right string trim-right) trim-left))
(defsubst string-blank-p (string)
"Check whether STRING is either empty or only whitespace."