ss_string_ltrim(3) - Linux man page

Name

ss_string_trim, ss_string_ltrim, ss_string_rtrim - deletes leading

characters

Synopsis

#include <sstrings2.h>

Linking with -lsstrings2

int ss_string_trim(ss_string *string, int (*blank)(int));
int ss_string_ltrim(ss_string *string, int (*blank)(int));
int ss_string_rtrim(ss_string *string, int (*blank)(int));

Descripton

ss_string_trim deletes all identical leading characters from the beginning and from the end of the string saved in string. The characters are determined by the function pointed to by blank. Note that string must be a valid ss_string object (initialized with ss_string_new).

ss_string_ltrim deletes all identical leading characters from the left of the string saved in string. The characters are determined by the function pointed to by blank. Note that string must be a valid ss_string object (initialized with ss_string_new).

ss_string_rtrim deletes all identical leading characters from the right of the string saved in string. The characters are determined by the function pointed to by blank. Note that string must be a valid ss_string object (initialized with ss_string_new).

blank returns 1 if the character has to be deleted, 0 otherwise. Please take a look at the example above.

Returning values

The functions return 1 on success, 0 otherwise

Error values for ss_errno

SS_NULL is a parameter

is NULL

SS_EINVAL if the ss_string objects are invalid

Examples

I want to delete all blank spaces (' ', TAB) and new-lines/carriage-return (\r, \n)
#include <sstrings2.h>
#include <stdio.h>
int space(int c)
{
    switch(c)
    {
        case ' ':
        case '\n':
        case '\t':
        case '\r':
            return 1;
    }
        return 0;
}
int main(void)
{
    ss_string *string;
    string = ss_string_new("     \t\n     Hello, World     \n\n");
    if(!string)
        return 1;
    ss_string_trim(string, space);
    printf("%s\n", string->str);
    ss_string_free(string, 1);
    return 0;
}

Bugs

Please send your bug reports to yanezp@informatik.uni-freiburg.de

See Also

ss_string_append(3), ss_string_append_c_string(3), ss_string_append_c_string_l(3), ss_string_new(3)

Referenced By

sstrings2(5)