mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-15 10:30:25 -08:00
Move string-trim functions to subr.el
* doc/lispref/strings.texi (Creating Strings): Document them. * lisp/faces.el: Don't require subr-x, because that leads to build errors. * lisp/subr.el (string-trim, string-trim-right) (string-trim-left): Move here from subr-x.el. * lisp/emacs-lisp/shortdoc.el (string): Adjust.
This commit is contained in:
parent
c0d24d5316
commit
a4ececf004
5 changed files with 38 additions and 27 deletions
22
lisp/subr.el
22
lisp/subr.el
|
|
@ -6200,6 +6200,28 @@ returned list are in the same order as in TREE.
|
|||
;; for discoverability:
|
||||
(defalias 'flatten-list #'flatten-tree)
|
||||
|
||||
(defun 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)
|
||||
(substring string (match-end 0))
|
||||
string))
|
||||
|
||||
(defun string-trim-right (string &optional regexp)
|
||||
"Trim STRING of trailing string matching REGEXP.
|
||||
|
||||
REGEXP defaults to \"[ \\t\\n\\r]+\"."
|
||||
(let ((i (string-match-p (concat "\\(?:" (or regexp "[ \t\n\r]+") "\\)\\'")
|
||||
string)))
|
||||
(if i (substring string 0 i) string)))
|
||||
|
||||
(defun 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))
|
||||
|
||||
;; The initial anchoring is for better performance in searching matches.
|
||||
(defconst regexp-unmatchable "\\`a\\`"
|
||||
"Standard regexp guaranteed not to match any string at all.")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue