]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/emacs-lisp/subr-x.el: (string-remove-prefix): New function.
authorBozhidar Batsov <bozhidar@batsov.com>
Fri, 20 Dec 2013 16:37:10 +0000 (18:37 +0200)
committerBozhidar Batsov <bozhidar@batsov.com>
Fri, 20 Dec 2013 16:37:10 +0000 (18:37 +0200)
(string-remove-suffix): New function.

etc/NEWS
lisp/ChangeLog
lisp/emacs-lisp/subr-x.el

index 49ad61d9fdb1f1a3066fbe447e944d0c6381f8ab..1e44a020856de1183cfe16c867527eca762aaeec 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -885,6 +885,8 @@ frame.
 *** `string-trim-left'
 *** `string-trim-right'
 *** `string-trim'
+*** `string-remove-prefix'
+*** `string-remove-suffix'
 
 ** Obsoleted functions:
 *** `log10'
index 8b3a15e1bc9371677e2748ee8bc096a89f4cefc3..b3315ca8c560d0a995d3f697a6725d236f55fa84 100644 (file)
@@ -2,6 +2,8 @@
 
        * emacs-lisp/subr-x.el: Renamed from helpers.el.
        helpers.el was a poor choice of name.
+       (string-remove-prefix): New function.
+       (string-remove-suffix): New function.
 
 2013-12-20  Martin Rudalics  <rudalics@gmx.at>
 
index 07e47794134a836d0e5005e35c0e760db244333b..41c3ff63ae44c43c9138d9b16fb7eea33323a0a7 100644 (file)
   "Check whether STRING is either empty or only whitespace."
   (string-match-p "\\`[ \t\n\r]*\\'" string))
 
+(defsubst string-remove-prefix (prefix string)
+  "Remove PREFIX from STRING if present."
+  (if (string-prefix-p prefix string)
+      (substring string (length prefix))
+    string))
+
+(defsubst string-remove-suffix (suffix string)
+  "Remove SUFFIX from STRING if present."
+  (if (string-suffix-p suffix string)
+      (substring string 0 (- (length string) (length suffix)))
+    string))
+
 (provide 'subr-x)
 
 ;;; subr-x.el ends here