all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Leo Liu <sdl.web@gmail.com>
To: 13617@debbugs.gnu.org
Subject: bug#13617: 24.2.92; [PATCH] Add strip-string
Date: Sun, 03 Feb 2013 15:35:58 +0800	[thread overview]
Message-ID: <m2r4kx97dt.fsf@gmail.com> (raw)

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.





             reply	other threads:[~2013-02-03  7:35 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-03  7:35 Leo Liu [this message]
2013-02-03  8:23 ` bug#13617: 24.2.92; [PATCH] Add strip-string Andreas Schwab
2013-02-03  8:50   ` Leo Liu
2013-02-03  8:56     ` Andreas Schwab
2013-02-03  9:40       ` Leo Liu
2013-03-25  3:42         ` Leo Liu
2013-03-25  7:48         ` Andreas Röhler
2016-02-24  5:51 ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2r4kx97dt.fsf@gmail.com \
    --to=sdl.web@gmail.com \
    --cc=13617@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.