From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.devel Subject: RE: split-string description in the ELR Date: Mon, 1 May 2017 09:20:45 -0700 (PDT) Message-ID: <7c26dfd7-b40a-4339-89e0-8f627c99c247@default> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1493655669 27544 195.159.176.226 (1 May 2017 16:21:09 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 1 May 2017 16:21:09 +0000 (UTC) To: Jean-Christophe Helary , emacs-devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon May 01 18:21:05 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d5E4N-00070o-4o for ged-emacs-devel@m.gmane.org; Mon, 01 May 2017 18:21:03 +0200 Original-Received: from localhost ([::1]:55028 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d5E4S-0000lp-Ok for ged-emacs-devel@m.gmane.org; Mon, 01 May 2017 12:21:08 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48264) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d5E4M-0000lZ-FP for emacs-devel@gnu.org; Mon, 01 May 2017 12:21:03 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d5E4H-0004iQ-D9 for emacs-devel@gnu.org; Mon, 01 May 2017 12:21:02 -0400 Original-Received: from userp1040.oracle.com ([156.151.31.81]:31820) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d5E4H-0004iL-4L for emacs-devel@gnu.org; Mon, 01 May 2017 12:20:57 -0400 Original-Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v41GKqKh030970 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 1 May 2017 16:20:52 GMT Original-Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id v41GKpBt011919 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 1 May 2017 16:20:51 GMT Original-Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id v41GKlkk016014; Mon, 1 May 2017 16:20:48 GMT In-Reply-To: X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 12.0.6767.5000 (x86)] X-Source-IP: userv0021.oracle.com [156.151.31.71] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 156.151.31.81 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:214495 Archived-At: > Without Eli's comment I would never have thought of using split-string to > trim a string. But even reading the reference did not make it's use super > clear. In the description "trim" is just an option to trim the substrings > resulting from splitting the string and it is not obvious that it can be > used on it's own to trim a given string. >=20 > Could a small modification of the reference be in order to emphasize that > use (with an example eventually) ? Good idea. Additionally, or instead, we could create a function that is an alias and that has "trim" in the name. ---- FWIW, I define function `split-string-by-regexp' to do just what vanilla `split-string' does, and I redefine `split-string' to handle additional ways to specify the splitting. The redefined function does `split-string-by-regexp' by default. Here are the signature and doc string of the redefined `split-string': (split-string STRING &optional HOW OMIT-NULLS TRIM FLIP TEST) Split STRING into substrings. Arg HOW determines how splitting is done. it is one of the following: * a regexp (a string) - see function `split-string-by-regexp' * a list whose first element is a text property (a symbol) and whose second element is the property value - see function `split-string-by-property' * a predicate that accepts a character as its first argument - see function `split-string-by-predicate' If optional arg OMIT-NULLS is t, then empty substrings are omitted from the returned list. If nil, zero-length substrings are retained, which correctly parses CSV format, for example. If TRIM is non-nil, it should be a regular expression to match text to trim from the beginning and end of each substring. If trimming makes a substring empty, it is treated according to OMIT-NULLS. Optional arg TEST is used only if HOW is a (PROPERTY VALUE) list, in which case it is passed to function `split-string-by-property' (which see). Otherwise, it is ignored. Modifies the match data; use `save-match-data' if necessary. Each of the HOW possibilities corresponds also to a separate function: split-string-by-regexp split-string-by-property split-string-by-predicate https://www.emacswiki.org/emacs/download/subr%2b.el