Hey,
Everybody thanks for the replies...! I also suffered from CPU eating regexp using '*', but I expected it was my own fault somehow :) But how do I go from here? There's also no trim_right (or _left) function, does anybody have something like that lying around? I guess I just have to process the string, right-to-left, char-by-char...
Depends what you're trying to do, that's not clear for me when reading your mail.
I was about to mention String.trim_all_whites() but it doesn't seem to remove \0. The following does the trick:
----8<----8<----8<----8<---- $ pike Pike v7.6 release 112 running Hilfe v3.5 (Incremental Pike Frontend)
string foo = " This is some text \0\0\0"; String.trim_all_whites(replace(foo,"\0",""));
(1) Result: "This is some text" ---->8---->8---->8---->8----
But if you have a PCRE enabled Pike, i guess something like that is more that you want:
----8<----8<----8<----8<---- $ pike Pike v7.6 release 112 running Hilfe v3.5 (Incremental Pike Frontend)
string foo = " This is some text \0\0\0"; Regexp.PCRE.Studied("[\W]+$")->replace(foo, "");
(1) Result: " This is some text" ---->8---->8---->8---->8----
If you don't have a PCRE enabled Pike, then there should be a solution with Regexp(). But it seems like there's a little bug with $ on Regexp(), but one bug at a time :)
Just recall that Regexp.PCRE() (and thus Regexp.PCRE.Studied()) are Perl Compatible Regular Expression. There are a totally different beast and way faster than Regexp() (which is the same than SimpleRegexp()).
I don't know if something like trim_whites_right() nor trim_whites_left() does exists, but feel free to watch the code of trim_whites()/trim_all_whites() and contribute a Public.String.trim_whites_[right|left]() into http://modules.gotpike.org/ :)