<div dir="ltr">2008/10/13 Richard O'Keefe <span dir="ltr"><<a href="mailto:ok@cs.otago.ac.nz" target="_blank">ok@cs.otago.ac.nz</a>></span><br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><br>
On 13 Oct 2008, at 9:22 am, Robert Virding wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I suggest a function string:split/2 which splits the input string with the separator and assumes that there is no separator and either end of the string. So:<br>
<br>
string:split("ab:de:fg", ":") ==> ["ab","de","fg"]<br>
string:split(":ab:de:fg:", ":") ==> [[],"ab","de","fg",[]]<br>
</blockquote>
<br></div>
This violates the assumption "that there is no separator [at]<br>
either end of the string". To make that assumption is to<br>
assume that something that _looks_ like a separator at either<br>
end _isn't_ one, so<br>
string:split(":ab:de:fg:", ":") ==> [":ab","de","fg:"]<br>
under that assumption.<br>
<br>
I _think_ you are talking about the issue that came up<br>
last week with *multicharacter* separators:<br>
string:split("a:::b", "::")<br>
==> ["a:","b"]<br>
or ["a",":b"] -- the code I posted does this</blockquote><div><br>That was me being extremely unclear. The examples I showed describe what I mean, and not what I wrote. I think the function should search for the separator from left-to-right as your second example. The question is how do you describe in text what it returns when it finds the separator at the beginning and at the end.<br>
<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
This also matches what will be in the re module (if they get it right) and what is in the old regexp module.<br>
</blockquote>
<br></div>
No, it DOESN'T match it. It CONFLICTS with regexp splitting.<br>
In fact, that's why it is useful!</blockquote><div><br>regexp:split("ab:cd:ef", ":"). ==> {ok,["ab","cd","ef"]}<br>regexp:split(":ab:cd:ef:", ":"). ==> {ok,[[],"ab","cd","ef",[]]}<br>
regexp:split(":::ab:::cd::ef", "::"). ==> {ok,[[],":ab",":cd","ef"]}<br><br>Or have I misunderstood you. What the new re:split will do I don't know, hopefully the same thing.<br>
<br>Not to be different I have also included some code for a split/2. It is a bit simpler than yours, at least I think so, but no guarantees for speed. Although it would be easy to modify so that strip_sep/2 never returns but directly calls strip/4.<br>
</div><div><br> %% strip(String, Separator) -> [String].<br><br>strip(S, Sep) -> strip(S, Sep, [], []).<br><br>strip([H|T]=S0, Sep, R, Rs) -><br> case strip_sep(S0, Sep) of<br> {yes,S1} -> strip(S1, Sep, [], [R|Rs]);<br>
no -> strip(T, Sep, [H|R], Rs)<br> end;<br>strip([], _, R, Rs) -> strip_rev([R|Rs], []).<br><br>strip_rev([R|Rs], Acc) -><br> strip_rev(Rs, [reverse(R)|Acc]);<br>strip_rev([], Acc) -> Acc.<br> <br>
strip_sep([C|S], [C|Sep]) -> strip_sep(S, Sep);<br>strip_sep(S, []) -> {yes,S};<br>strip_sep(_, _) -> no.<br><br></div></div>Robert<br><br></div>