This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Suggestion of three new functions for glibc
- From: Aki Tossavainen <cmouse at quakenet dot org>
- To: libc-alpha at gnu dot org
- Date: Tue, 21 Oct 2003 17:57:43 +0300 (EEST)
- Subject: 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);
}