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]

Suggestion of three new functions for glibc


These functions handle trimming of strings.
What is trimming? Trimming is removing from left and/or right side of
string all characthers matching trimmers. These functions do that.
The modification is done directly into the buffer, as the result will
require as much or less memory than original.

Please, feel free to comment or anything. Would be nice to hear what you
think.

Aki Tossavainen
cmouse@quakenet.org
void strtrimleft(char *string, const char *trimmers) {
  char *cp;
  if ((!trimmers)||(!string)) return;
  for(cp = string; (*cp)&&(strchr(trimmers,*cp)); cp++);
  memmove(string,cp,strlen(cp)+1);
}

void strtrimright(char *string, const char *trimmers) {
  char *cp;
  if ((!trimmers)||(!string)) return;
  for(cp = string + strlen(string); (cp >= string)&&(strchr(trimmers,*cp)); cp--);
  *(++cp) = '\0';
}

void strtrim(char *string, const char *trimmers) {
  strtrimleft(string,trimmers);
  strtrimright(string,trimmers);
}

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