emacs-devel
[Top][All Lists]
Advanced

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

Re: Rationale for split-string?


From: Stefan Monnier
Subject: Re: Rationale for split-string?
Date: Thu, 17 Apr 2003 13:44:18 -0400

> What is the rationale for the specification of `split-string'?
> 
> That is, in GNU Emacs
> 
>   ;; an often convenient abbreviation
>   (split-string "  data  ")
> => ("data")
> 
>   ;; weird
>   (split-string "  data  " " ")
> => ("" "data" "")
> 
>   ;; urk (think "gnumeric just-say-no.xls" "save as" "csv")
>   (split-string ",,data,," ",")
> => ("" "data" "")

I think the reason is for the default case.  In XEmacs we get:

ELISP> (split-string "  a  b  ")
("" "a" "b" "")

What is usually desired here is to eliminate all empty parts.
The `+' in the default regexp gets rid of the empty parts inside
the string, but not at the beginning and at the end, so that's
why Emacs gets rid of the empty string at the beginning and at
the end.

I agree that when the regexp used is "," or "[ \t]*,[ \t]*",
then XEmacs's behavior makes a lot more sense.

A gross hack is to test if the last char of the regexp is ?+
and if so get rid of empty strings at start and end.
It should take care of 99% of the cases.


        Stefan





reply via email to

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