mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2025-01-18 18:05:07 +00: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
@ -390,6 +390,22 @@ whitespace to a single space character, as well as removing all
|
||||
whitespace from the start and the end of @var{string}.
|
||||
@end defun
|
||||
|
||||
@defun string-trim-left string &optional regexp
|
||||
Remove the leading text that matches @var{regexp} from @var{string}.
|
||||
@var{regexp} defaults to @samp{[ \t\n\r]+}.
|
||||
@end defun
|
||||
|
||||
@defun string-trim-right string &optional regexp
|
||||
Remove the trailing text that matches @var{regexp} from @var{string}.
|
||||
@var{regexp} defaults to @samp{[ \t\n\r]+}.
|
||||
@end defun
|
||||
|
||||
@defun string-trim string &optional trim-left trim-right
|
||||
Remove the leading text that matches @var{trim-left} and trailing text
|
||||
that matches @var{trim-right} from from @var{string}. Both regexps
|
||||
default to @samp{[ \t\n\r]+}.
|
||||
@end defun
|
||||
|
||||
@defun string-fill string length
|
||||
Attempt to Word-wrap @var{string} so that no lines are longer than
|
||||
@var{length}. Filling is done on whitespace boundaries only. If
|
||||
|
@ -168,15 +168,12 @@ There can be any number of :example/:result elements."
|
||||
(replace-regexp-in-string
|
||||
:eval (replace-regexp-in-string "[a-z]+" "_" "*foo*"))
|
||||
(string-trim
|
||||
:no-manual t
|
||||
:args (string)
|
||||
:doc "Trim STRING of leading and trailing white space."
|
||||
:eval (string-trim " foo "))
|
||||
(string-trim-left
|
||||
:no-manual t
|
||||
:eval (string-trim-left "oofoo" "o+"))
|
||||
(string-trim-right
|
||||
:no-manual t
|
||||
:eval (string-trim-right "barkss" "s+"))
|
||||
(string-truncate-left
|
||||
:no-manual t
|
||||
|
@ -215,28 +215,6 @@ The variable list SPEC is the same as in `if-let'."
|
||||
|
||||
(define-obsolete-function-alias 'string-reverse 'reverse "25.1")
|
||||
|
||||
(defsubst 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))
|
||||
|
||||
(defsubst 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)))
|
||||
|
||||
(defsubst 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))
|
||||
|
||||
;;;###autoload
|
||||
(defun string-truncate-left (string length)
|
||||
"Truncate STRING to LENGTH, replacing initial surplus with \"...\"."
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
;;; Code:
|
||||
|
||||
(eval-when-compile (require 'subr-x))
|
||||
|
||||
(defcustom term-file-prefix (purecopy "term/")
|
||||
"If non-nil, Emacs startup performs terminal-specific initialization.
|
||||
It does this by: (load (concat term-file-prefix (getenv \"TERM\")))
|
||||
|
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…
Reference in New Issue
Block a user