Suggestion of three new functions for glibc
Bruno Haible
bruno@clisp.org
Fri Oct 24 17:08:00 GMT 2003
> void strtrimleft(char *string, const char *trimmers) {
> void strtrimright(char *string, const char *trimmers) {
You're assuming that a character and a 'char' are the same thing. This
is wrong nowadays. For example, if I wanted to remove spaces from an
UTF-8 string, the set of trimmers would be
{ "\x20", "\xe2\x80\x82", "\xe2\x80\x83", "\xe2\x80\x84", ... }
i.e. an array of 'char*', not an array of 'char'.
> for(cp = string + strlen(string); (cp >= string)&&(strchr(trimmers,*cp)); cp--);
Parsing a string from the end is a no-no when the string is encoded using
some encoding like BIG5, GBK or SHIFT_JIS.
Furthermore, the function you propose are neither
- so generally useful that they need to be in libc,
- dependent on the kernel
therefore I'd say they don't belong in libc.
Bruno
More information about the Libc-alpha
mailing list