GNU bug report logs -
#13617
24.2.92; [PATCH] Add strip-string
Previous Next
Reported by: Leo Liu <sdl.web <at> gmail.com>
Date: Sun, 3 Feb 2013 07:38:02 UTC
Severity: wishlist
Tags: fixed, patch
Found in version 24.2.92
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
Hello Stefan,
Any objection to adding a general utility function strip-string?
Thanks,
Leo.
diff --git a/lisp/subr.el b/lisp/subr.el
index 72b629d6..afa0b753 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -3683,6 +3683,19 @@ (defun subst-char-in-string (fromchar tochar string &optional inplace)
(aset newstr i tochar)))
newstr))
+(defun strip-string (string &optional leading-chars trailing-chars)
+ "Strip STRING of LEADING-CHARS and TRAILING-CHARS.
+LEADING-CHARS and TRAILING-CHARS defaults to \" \f\t\n\r\v\"."
+ (let ((lchars (if (equal leading-chars "")
+ ""
+ (concat "[" (or leading-chars " \f\t\n\r\v") "]*")))
+ (rchars (if (equal trailing-chars "")
+ ""
+ (concat "[" (or trailing-chars " \f\t\n\r\v") "]*"))))
+ (string-match (concat "\\`" lchars "\\(\\(?:.\\|\n\\)*?\\)" rchars "\\'")
+ string)
+ (match-string 1 string)))
+
(defun replace-regexp-in-string (regexp rep string &optional
fixedcase literal subexp start)
"Replace all matches for REGEXP with REP in STRING.
This bug report was last modified 9 years and 176 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.