From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Lars Hansen Newsgroups: gmane.emacs.devel Subject: Re: string-strip Date: Wed, 21 Jun 2006 18:47:41 +0200 Message-ID: <4499782D.4020408@soem.dk> References: <449266B2.7030500@easy-emacs.de> <4496E618.8090401@soem.dk> <32964.128.165.123.239.1150741470.squirrel@webmail.lanl.gov> <449796E7.9090808@soem.dk> <44984C66.8090006@easy-emacs.de> <17560.20884.675268.166167@kahikatea.snap.net.nz> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------090105070409000401000307" X-Trace: sea.gmane.org 1150908503 21165 80.91.229.2 (21 Jun 2006 16:48:23 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 21 Jun 2006 16:48:23 +0000 (UTC) Cc: andreas.roehler@easy-emacs.de, Richard Stallman , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Jun 21 18:48:21 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Ft5sF-0004DI-C3 for ged-emacs-devel@m.gmane.org; Wed, 21 Jun 2006 18:48:15 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ft5sE-0001Kv-Tk for ged-emacs-devel@m.gmane.org; Wed, 21 Jun 2006 12:48:14 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Ft5rs-0001Dt-Dj for emacs-devel@gnu.org; Wed, 21 Jun 2006 12:47:52 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Ft5rq-0001Be-Ct for emacs-devel@gnu.org; Wed, 21 Jun 2006 12:47:52 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ft5rq-0001BY-6K for emacs-devel@gnu.org; Wed, 21 Jun 2006 12:47:50 -0400 Original-Received: from [212.99.225.245] (helo=odin.broadcom.dk) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1Ft62Z-00078M-6q; Wed, 21 Jun 2006 12:58:55 -0400 Original-Received: from pppoe3-ves.broadcom.dk ([212.99.255.42] helo=[10.17.0.131]) by odin.broadcom.dk with esmtp (Exim 4.24; FreeBSD) id 1Ft5qJ-0002jH-2m; Wed, 21 Jun 2006 18:46:15 +0200 User-Agent: Debian Thunderbird 1.0.2 (X11/20060423) X-Accept-Language: en-us, en Original-To: =?ISO-8859-1?Q?Johan_Bockg=E5rd?= In-Reply-To: X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:56059 Archived-At: This is a multi-part message in MIME format. --------------090105070409000401000307 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Johan Bockgård wrote: >Or how about if it worked like `split-string'? > > Brilliant idea. How about this? --------------090105070409000401000307 Content-Type: text/x-patch; name="subr.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="subr.diff" *** /home/lh/cvsroot/emacs/lisp/subr.el 2006-06-13 12:37:24.000000000 +0200 --- subr.el 2006-06-21 18:44:11.200360589 +0200 *************** *** 2615,2620 **** --- 2615,2642 ---- ;;;; Replacement in strings. + (defconst string-strip-default-white-space "[ \f\t\n\r\v]*" + "The default value of white-space for `string-strip'. + A regexp matching strings of white space.") + + (defun string-strip (string &optional white-space) + "Remove leading and trailing WHITE-SPACE from STRING. + If WHITE-SPACE is non-nil, it should be a regular expression matching white + space. If nil it defaults to `string-strip-default-white-space', normally + \"[ \\f\\t\\n\\r\\v]*\". + + Examples: + (string-strip \" foo \") => \"foo\" + (string-strip \" foo\\nbar\\n \") => \"foo\\nbar\" + (string-strip \" \") => \"\" + " + (let ((ws (or white-space string-strip-default-white-space))) + (save-match-data + (string-match + (concat "\\`\\(?:" ws "\\)\\(\\(?:.\\|\n\\)*?\\)\\(?:" ws "\\)\\'") + string) + (match-string 1 string)))) + (defun subst-char-in-string (fromchar tochar string &optional inplace) "Replace FROMCHAR with TOCHAR in STRING each time it occurs. Unless optional argument INPLACE is non-nil, return a new string." --------------090105070409000401000307 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --------------090105070409000401000307--