strings.c
Go to the documentation of this file.
/* SPDX-FileCopyrightText: 2009-2023 Greenbone AG
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "strings.h"
#include <assert.h> /* for assert */
#include <glib.h> /* for g_free, g_strconcat, gchar, g_strdup, g_strndup */
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "libgvm base"
void
gvm_append_string (gchar **var, const gchar *string)
{
if (*var)
{
char *old = *var;
*var = g_strconcat (old, string, NULL);
g_free (old);
}
else
*var = g_strdup (string);
}
void
gvm_append_text (gchar **var, const gchar *string, gsize length)
{
if (*var)
{
char *old = *var;
*var = g_strconcat (old, string, NULL);
g_free (old);
}
else
*var = g_strndup (string, length);
}
void
gvm_free_string_var (gchar **var)
{
g_free (*var);
*var = NULL;
}
char *
gvm_strip_space (char *string, char *end)
{
assert (string <= end);
if (string >= end)
return string;
end--;
while (string[0] == ' ' || string[0] == '\n')
{
string++;
if (string >= end)
{
end[0] = '\0';
return end;
}
}
/* Here string is < end. */
if (end[0] == ' ' || end[0] == '\n')
{
end--;
while (end >= string && (end[0] == ' ' || end[0] == '\n'))
{
end--;
}
end[1] = '\0';
}
return string;
}
gvm_append_text
void gvm_append_text(gchar **var, const gchar *string, gsize length)
Append a string of a known length to a string variable.
Definition strings.c:66
gvm_append_string
void gvm_append_string(gchar **var, const gchar *string)
Append a string to a string variable.
Definition strings.c:36
gvm_strip_space
char * gvm_strip_space(char *string, char *end)
"Strip" space and newline characters from either end of some memory.
Definition strings.c:108
gvm_free_string_var
void gvm_free_string_var(gchar **var)
Free a string variable.
Definition strings.c:87
strings.h
String utilities.