diff options
author | Bozhidar Batsov <bozhidar@batsov.com> | 2013-11-24 11:31:51 +0200 |
---|---|---|
committer | Bozhidar Batsov <bozhidar@batsov.com> | 2013-11-24 11:31:51 +0200 |
commit | b55aea382c32f4448892265f322a38290ce10305 (patch) | |
tree | e0e666ad75c49a6a84cc1b1b958175d832f28537 /lisp/emacs-lisp | |
parent | 41ce6f702730d95ef62e770a1b8160e3aac9d0a8 (diff) | |
download | emacs-b55aea382c32f4448892265f322a38290ce10305.tar.gz emacs-b55aea382c32f4448892265f322a38290ce10305.tar.bz2 emacs-b55aea382c32f4448892265f322a38290ce10305.zip |
* lisp/emacs-lisp/helpers.el: Add some string helpers.
(string-trim-left): Removes leading whitespace.
(string-trim-right): Removes trailing whitespace.
(string-trim): Removes leading and trailing whitespace.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r-- | lisp/emacs-lisp/helpers.el | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lisp/emacs-lisp/helpers.el b/lisp/emacs-lisp/helpers.el index 73c2ff1c15c..fd5985467b5 100644 --- a/lisp/emacs-lisp/helpers.el +++ b/lisp/emacs-lisp/helpers.el @@ -37,6 +37,22 @@ (maphash (lambda (_k v) (push v values)) hash-table) values)) +(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))) + (provide 'helpers) ;;; helpers.el ends here |