From: Drew Adams <drew.adams@oracle.com>
To: Jean-Christophe Helary <jean.christophe.helary@gmail.com>,
emacs-devel <emacs-devel@gnu.org>
Subject: RE: split-string description in the ELR
Date: Mon, 1 May 2017 09:20:45 -0700 (PDT) [thread overview]
Message-ID: <7c26dfd7-b40a-4339-89e0-8f627c99c247@default> (raw)
In-Reply-To: <B941DB53-18AA-43E0-A54C-3308BC161BC0@gmail.com>
> 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.
>
> 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
next prev parent reply other threads:[~2017-05-01 16:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-01 15:38 split-string description in the ELR Jean-Christophe Helary
2017-05-01 16:20 ` Drew Adams [this message]
2017-05-01 22:46 ` Jean-Christophe Helary
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7c26dfd7-b40a-4339-89e0-8f627c99c247@default \
--to=drew.adams@oracle.com \
--cc=emacs-devel@gnu.org \
--cc=jean.christophe.helary@gmail.com \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).