2021-09-24 21:45:48 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2020-10-09 19:46:59 +01:00
|
|
|
#include <ctype.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
2023-01-31 03:35:13 +01:00
|
|
|
#include "common/string-helpers.h"
|
2020-10-09 19:46:59 +01:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2021-02-16 21:03:38 +00:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
string_truncate_at_pattern(char *buf, const char *pattern)
|
|
|
|
|
{
|
|
|
|
|
char *p = strstr(buf, pattern);
|
|
|
|
|
if (!p) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
*p = '\0';
|
|
|
|
|
}
|