This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Suggestion of three new functions for glibc


> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]