apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vaclav Ovsik <Vaclav.Ov...@i.cz>
Subject to add function apr_chomp into string functions?
Date Thu, 27 Mar 2003 11:14:27 GMT
Hello,
I have need to strip the line separator from a string now. Something
like perl's chomp could be useful, when a text file is read by
e.g. apr_file_gets().
In perl ...

zito@bobek zito $ perl -e '$_="BLA\n"; chomp $_; print "X${_}X\n";'
XBLAX

What about to include code like below to APR under ./strings  ?

/**
 * Strip trailing EOL from a string (in place)
 * @param s The string to chop EOL in place.
 */
APR_DECLARE(char *) apr_chomp(char *s);


APR_DECLARE(char *) apr_chomp(char *s)
{
    int s_len, eol_len;
    char *p;

    s_len = strlen(s);
    eol_len = strlen(APR_EOL_STR);
    if ( s_len < eol_len )
        return s;
    p = s + s_len - eol_len;
    if ( strcmp(p, APR_EOL_STR) == 0 )
        *p = (char)0;
    return s;
}

Maybe I missed another simple way to do this, please tell mi if.
-- 
Zito

Mime
View raw message