mirror of
https://github.com/labwc/labwc.git
synced 2025-11-04 13:30:07 -05:00
Add string-helpers.c
This commit is contained in:
parent
51507df2e7
commit
7e55e2cd09
6 changed files with 47 additions and 54 deletions
|
|
@ -5,4 +5,5 @@ labwc_sources += files(
|
|||
'grab-file.c',
|
||||
'log.c',
|
||||
'spawn.c',
|
||||
'string-helpers.c',
|
||||
)
|
||||
|
|
|
|||
27
src/common/string-helpers.c
Normal file
27
src/common/string-helpers.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static void
|
||||
rtrim(char **s)
|
||||
{
|
||||
size_t len = strlen(*s);
|
||||
if (!len) {
|
||||
return;
|
||||
}
|
||||
char *end = *s + len - 1;
|
||||
while (end >= *s && isspace(*end)) {
|
||||
end--;
|
||||
}
|
||||
*(end + 1) = '\0';
|
||||
}
|
||||
|
||||
char *
|
||||
string_strip(char *s)
|
||||
{
|
||||
rtrim(&s);
|
||||
while (isspace(*s)) {
|
||||
s++;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue