First commit

This commit is contained in:
Steffen Lange 2018-04-08 21:34:42 +02:00
commit 0a28bac78a
37 changed files with 1963 additions and 0 deletions

31
trim.c Normal file
View 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));
}