From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Leo Liu Newsgroups: gmane.emacs.bugs Subject: bug#13617: 24.2.92; [PATCH] Add strip-string Date: Sun, 03 Feb 2013 15:35:58 +0800 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1359877030 25527 80.91.229.3 (3 Feb 2013 07:37:10 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 3 Feb 2013 07:37:10 +0000 (UTC) To: 13617@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Feb 03 08:37:28 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1U1u8l-00069h-RF for geb-bug-gnu-emacs@m.gmane.org; Sun, 03 Feb 2013 08:37:28 +0100 Original-Received: from localhost ([::1]:35128 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U1u8T-0002A9-Ha for geb-bug-gnu-emacs@m.gmane.org; Sun, 03 Feb 2013 02:37:09 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:42719) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U1u8R-00029D-5G for bug-gnu-emacs@gnu.org; Sun, 03 Feb 2013 02:37:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U1u8P-0005cF-Su for bug-gnu-emacs@gnu.org; Sun, 03 Feb 2013 02:37:07 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:56279) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U1u8P-0005cB-Pe for bug-gnu-emacs@gnu.org; Sun, 03 Feb 2013 02:37:05 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1U1u9K-0007kq-TQ; Sun, 03 Feb 2013 02:38:03 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Leo Liu Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: monnier@iro.umontreal.ca, bug-gnu-emacs@gnu.org Resent-Date: Sun, 03 Feb 2013 07:38:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 13617 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: Stefan Monnier Original-Received: via spool by submit@debbugs.gnu.org id=B.135987703229682 (code B ref -1); Sun, 03 Feb 2013 07:38:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 3 Feb 2013 07:37:12 +0000 Original-Received: from localhost ([127.0.0.1]:33509 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1U1u8W-0007ih-4Y for submit@debbugs.gnu.org; Sun, 03 Feb 2013 02:37:12 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:59495) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1U1u8T-0007ia-Uk for submit@debbugs.gnu.org; Sun, 03 Feb 2013 02:37:11 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U1u7X-0005WK-0U for submit@debbugs.gnu.org; Sun, 03 Feb 2013 02:36:11 -0500 Original-Received: from lists.gnu.org ([208.118.235.17]:44704) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U1u7W-0005WF-TT for submit@debbugs.gnu.org; Sun, 03 Feb 2013 02:36:10 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:42605) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U1u7V-000280-Sc for bug-gnu-emacs@gnu.org; Sun, 03 Feb 2013 02:36:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U1u7U-0005VP-2K for bug-gnu-emacs@gnu.org; Sun, 03 Feb 2013 02:36:09 -0500 Original-Received: from mail-pb0-f53.google.com ([209.85.160.53]:39409) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U1u7T-0005V9-SJ for bug-gnu-emacs@gnu.org; Sun, 03 Feb 2013 02:36:07 -0500 Original-Received: by mail-pb0-f53.google.com with SMTP id un1so2720925pbc.40 for ; Sat, 02 Feb 2013 23:36:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:subject:x-debbugs-cc:date:message-id :mime-version:content-type; bh=gwTC28YpsXhiCK4gt0hqmG7r36KDVEnyAgmi5lCtWPM=; b=D856lPrto+w1byG5hp3/f0Eu+JKEpLCY4KLoogAU6PUsO9vPgDfhKrIy4Es1BymNP8 UNXFh9PkTHDOrYcHLkxj2RemYjxaLk4NXr/31gSQSaPux8BV7aznPL4/56uDQzEtkt7W i97C/rDtNEomgChKlxklX5rBS2tPKDDotyFD2IRImbUTTMg0Nht5qZIfGXdPqPZXb5TC fRu5b8G7W63lpcqP0Zex4Pn9bqkNoipTVwKjN8BL9vmRo4mWUE00O9bEjtiBcMkf6PVc Oie77lVGbwx4ZRrz1ekoS01V9R4Eh1Ef0iwhT/EYeF+V52cSGb/7bFLee+4axw5QrhJS KwbA== X-Received: by 10.68.203.137 with SMTP id kq9mr45037574pbc.115.1359876967119; Sat, 02 Feb 2013 23:36:07 -0800 (PST) Original-Received: from Shidais-iMac.local ([119.255.41.66]) by mx.google.com with ESMTPS id a4sm14935840paw.21.2013.02.02.23.36.04 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 02 Feb 2013 23:36:06 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:70631 Archived-At: 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.