From 3cbfb9354082c9e3466156d81da3dfe9d7d9f99f Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Fri, 20 Dec 2013 18:37:10 +0200 Subject: [PATCH] * lisp/emacs-lisp/subr-x.el: (string-remove-prefix): New function. (string-remove-suffix): New function. --- etc/NEWS | 2 ++ lisp/ChangeLog | 2 ++ lisp/emacs-lisp/subr-x.el | 12 ++++++++++++ 3 files changed, 16 insertions(+) diff --git a/etc/NEWS b/etc/NEWS index 49ad61d9fdb..1e44a020856 100644 --- 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' diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 8b3a15e1bc9..b3315ca8c56 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -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 diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el index 07e47794134..41c3ff63ae4 100644 --- a/lisp/emacs-lisp/subr-x.el +++ b/lisp/emacs-lisp/subr-x.el @@ -73,6 +73,18 @@ "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 -- 2.39.2