[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rationale for split-string?

From: Stephen J. Turnbull
Subject: Re: Rationale for split-string?
Date: Mon, 21 Apr 2003 19:58:48 +0900
User-agent: Gnus/5.090016 (Oort Gnus v0.16) XEmacs/21.5 (cabbage)

>>>>> "rms" == Richard Stallman <address@hidden> writes:

    rms> I don't entirely agree.  The default case uses strings of
    rms> whitespace as the separator, and for that case, the only
    rms> intelligent approach is token-parsing.  So the function needs
    rms> to be able to do token-parsing.

I was afraid of that (I prefer regular behavior over intelligent
behavior if I must make a choice), but I can live with it.  I really
would prefer a separate `tokenize-string' function, though.  (That
name is not used in the GNU Emacs or XEmacs cores, or anywhere in the
XEmacs packages.  Several packages have their own tokenize functions
but they're all properly prefixed, and one might fear semantic would
use the name, but it doesn't.)

    rms> This feature therefore may as well also be available for any
    rms> separator.

But that's not compatible with a *single* function with with *two*
arguments.  So I suppose you want a simpler version of Luc Teirlinck's
suggestion.  How about:

;; one function, three arguments

(defun split-string (string &optional separators omit-nulls)
  "Splits STRING into substrings bounded by matches for SEPARATORS.

The beginning and end of STRING, and each match for SEPARATORS, are
splitting points.  The substrings between the splitting points are
collected in a list, which is returned.  (The substrings matching
SEPARATORS are removed.)

If SEPARATORS is nil, it defaults to \"[ \f\t\n\r\v]+\".

If OMIT-NULLs is t, zero-length substrings are omitted from the list
(so that for the default value of SEPARATORS leading and trailing
whitespace are trimmed).  If nil, all zero-length substrings are
retained, which correctly parses CSV format, for example."

  ;; implementation

Institute of Policy and Planning Sciences     http://turnbull.sk.tsukuba.ac.jp
University of Tsukuba                    Tennodai 1-1-1 Tsukuba 305-8573 JAPAN
               Ask not how you can "do" free software business;
              ask what your business can "do for" free software.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]