String whitespace strip method

I've written a simple method for stripping whitespace from the begining and end of strings
(same thing as python's strip() or java's trim()).

It has come in pretty useful for application level string handling. Would it be possible to
add it to the code base?

Also, is there any plan to modulerize the builtins? (e.g.@load builtins.string), as the project
grows, bro.bif is going to get (further) out of control.

thanks :slight_smile:
.martin

function strip%(str: string%): string
    %{
        const char* s = str->CheckString();

        int n = strlen(s) + 1;
        char* strip_s = new char[n];

        while(isspace(*s))
        { s++; }
        strncpy(strip_s, s, n);

        s = strip_s;
        char* e = (char*)(s + (strlen(s) - 1));

        while(isspace(*e))
        { e--; }
        *(e+1) = 0;
        return new StringVal(new BroString(1, byte_vec(s), (e-s)+1));
    %}

Hi Martin,

Also, is there any plan to modulerize the builtins? (e.g.@load
builtins.string), as the project
grows, bro.bif is going to get (further) out of control.

fyi I've started to do this in my tree. There are no separate namespaces
so far, but at least things have moved from one humongous file into
multiple, more manageable ones. I've also started to make the function
naming more uniform. I should probably push a bunch of changes to Vern
sometime soon.

Cheers,
Christian.