From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Trimming strings, /emacs/lisp/emacs-lisp/subr-x.el modification Date: Tue, 02 May 2017 20:16:32 +0300 Message-ID: <83a86vi3gv.fsf@gnu.org> References: Reply-To: Eli Zaretskii NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1493745458 29884 195.159.176.226 (2 May 2017 17:17:38 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 2 May 2017 17:17:38 +0000 (UTC) Cc: emacs-devel@gnu.org To: Jean-Christophe Helary Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue May 02 19:17:34 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 1d5bQc-0007dt-GZ for ged-emacs-devel@m.gmane.org; Tue, 02 May 2017 19:17:34 +0200 Original-Received: from localhost ([::1]:60329 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d5bQg-0006GD-G3 for ged-emacs-devel@m.gmane.org; Tue, 02 May 2017 13:17:38 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45158) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d5bQ3-0006Fo-TR for emacs-devel@gnu.org; Tue, 02 May 2017 13:17:00 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d5bQ0-00026B-NH for emacs-devel@gnu.org; Tue, 02 May 2017 13:16:59 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:33433) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d5bQ0-00025r-JV; Tue, 02 May 2017 13:16:56 -0400 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:3119 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1d5bQ0-0002u2-0A; Tue, 02 May 2017 13:16:56 -0400 In-reply-to: (message from Jean-Christophe Helary on Tue, 2 May 2017 18:34:17 +0900) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e 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:214523 Archived-At: > From: Jean-Christophe Helary > Date: Tue, 2 May 2017 18:34:17 +0900 > > Following the discussion about how trimming in subr-x.el did not allow for non-default regex, I have this small modification to the 3 trimming functions found therein. > > Basically: > 1) I extracted the default regex and assigned it to string-trim-default-regex > 2) I declared optional "trim-left" and "trim-right" arguments respectively for the string-trim-left and string-trim-right functions, and declared both optional for the general string-trim function Thanks. Do we really have use cases for string-trim where trim-left and trim-right should be different? If not, let's give it only one optional argument, not 2. > +(defsubst string-trim-left (string &optional trim-left) > + "Trim STRING of leading whitespace matching TRIM-LEFT. Since TRIM-LEFT could be anything, the "whitespace" part is no longer accurate. Suggest to use "delimiters" instead. > +If TRIM-LEFT is non-nil, it should be a regular expression. If nil, > +it defaults to `string-trim-default-regex', normally \"[ \t\n\r]+\"." This is better worded like this: TRIM-LEFT should be a regular expression, and defaults to `string-trim-default-regex' if omitted or nil. > +(defsubst string-trim-right (string &optional trim-right) > + "Trim STRING of trailing whitespace matching TRIM-RIGHT. > + > +If TRIM-RIGHT is non-nil, it should be a regular expression. If nil, > +it defaults to `string-trim-default-regex', normally \"[ \t\n\r]+\"." Likewise. > +(defsubst string-trim (string &optional trim-left trim-right) > + "Trim STRING of leading and trailing whitespace matching TRIM-LEFT and TRIM-RIGHT. Please make the first line shorter than 80 characters.