mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-05 16:58:02 +02:00
glib-aux: add nm_strstrip_dup() helper
This commit is contained in:
parent
3378ec1236
commit
fa87ef6cd3
1 changed files with 21 additions and 0 deletions
|
|
@ -1057,6 +1057,27 @@ nm_strstrip(char *str)
|
||||||
return str ? g_strstrip(str) : NULL;
|
return str ? g_strstrip(str) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline char *
|
||||||
|
nm_strstrip_dup(const char *str)
|
||||||
|
{
|
||||||
|
gsize l;
|
||||||
|
char *s;
|
||||||
|
|
||||||
|
if (!str)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
str = nm_str_skip_leading_spaces(str);
|
||||||
|
l = strlen(str);
|
||||||
|
|
||||||
|
while (l > 0 && g_ascii_isspace(str[l - 1]))
|
||||||
|
l--;
|
||||||
|
|
||||||
|
s = g_new(char, l + 1);
|
||||||
|
memcpy(s, str, l);
|
||||||
|
s[l] = '\0';
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
static inline const char *
|
static inline const char *
|
||||||
nm_strstrip_avoid_copy(const char *str, char **str_free)
|
nm_strstrip_avoid_copy(const char *str, char **str_free)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue