First commit
This commit is contained in:
commit
0a28bac78a
37 changed files with 1963 additions and 0 deletions
31
trim.c
Normal file
31
trim.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#include "trim.h"
|
||||
|
||||
char * ltrim(char *s) {
|
||||
char *start = s;
|
||||
|
||||
// Find first non-whitespace character.
|
||||
while (isspace(*start))
|
||||
start++;
|
||||
|
||||
// Move string part to beginning, including null terminator.
|
||||
memmove(s, start, strlen(start) + 1);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
char * rtrim(char *s) {
|
||||
char *end = s + strlen(s);
|
||||
|
||||
// Find last non-whitespace character.
|
||||
while ((end != s) && isspace(*(end - 1)))
|
||||
end--;
|
||||
|
||||
// Mark new string endpoint.
|
||||
*end = '\0';
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
char * trim(char *s) {
|
||||
return ltrim(rtrim(s));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue