diff options
| author | Jean-Christophe Helary | 2017-05-19 14:27:10 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2017-05-19 14:27:10 +0300 |
| commit | c189986b241cbe79b0e027fa08bba710ac645bb3 (patch) | |
| tree | 3dd75515917ccc4f02c5ba053bd579c504814cd6 | |
| parent | cecd99d826547d4bfd918bba476eda206f0f0afc (diff) | |
| download | emacs-c189986b241cbe79b0e027fa08bba710ac645bb3.tar.gz 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)
| -rw-r--r-- | lisp/emacs-lisp/subr-x.el | 24 |
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 | |
| 184 | REGEXP 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 | |
| 192 | REGEXP 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 | |
| 200 | TRIM-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." |