Re: New "cut" operator (was: Pike 8.0 RC1)
Martin Bähr <[email protected]>
| Newsgroups | gmane.comp.lang.pike.user |
|---|---|
| Message-ID | <[email protected]> |
Excerpts from 郭雪松's message of 2014-11-16 17:18:07 +0100:
> > "cut left example" << " " == " left example"
> That is useless.
well, yes, but it demonstrates why << and >> are not a good fit for this operation.
consider "cut left example" << "left"
i would not expect this to return " example", but instead i would expect "left example"
> what I really need is the feature of "between", just like this:
> "<some thing>" << "<" >> ">" == "some thing"
> "<title>TITLE</title>" << "<" >> ">"=="titile"
> "<title>TITLE</title>"[sizeof("title")+2..]=="TITLE</title>"
> "TITLE</title>" >> "<"=="TITLE"
> "TITLE</title>"[sizeof("TITLE")..]=="</title>"
even with added spaces those examples don't feel very readable.
consider instead:
string chomp(string in, void|string cutleft, void|string cutright);
{ /* implementation of this function is left to the reader */ }
chomp("<some thing>", "<", ">") == "some thing";
chomp("<title>TITLE</title>", ">", "<") == "TITLE";
chomp("TITLE</title>", 0, "<") == "TITLE";
chomp("TITLE</title>", "TITLE") == "</title>";
greetings, martin.
--
eKita - the online platform for your entire academic life
--
chief engineer eKita.co
pike programmer pike.lysator.liu.se caudium.net societyserver.org
BLUG secretary beijinglug.org
foresight developer foresightlinux.org realss.com
unix sysadmin
Martin Bähr working in china http://societyserver.org/mbaehr/