gvm-libs  11.0.1
About: GVM Libraries for the Greenbone Vulnerability Management (GVM-10) framework (derived from the former openvas-libraries).
  Fossies Dox: gvm-libs-11.0.1.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

strings.h File Reference

String utilities. More...

#include <glib.h>
Include dependency graph for strings.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void gvm_append_string (gchar **, const gchar *)
 Append a string to a string variable. More...
 
void gvm_append_text (gchar **, const gchar *, gsize)
 Append a string of a known length to a string variable. More...
 
void gvm_free_string_var (gchar **)
 Free a string variable. More...
 
char * gvm_strip_space (char *, char *)
 "Strip" space and newline characters from either end of some memory. More...
 

Detailed Description

String utilities.

Definition in file strings.h.

Function Documentation

◆ gvm_append_string()

void gvm_append_string ( gchar **  var,
const gchar *  string 
)

Append a string to a string variable.

When the variable is NULL store a copy of the given string in the variable.

When the variable already contains a string replace the string with a new string that is the concatenation of the two, freeing the old string. It is up to the caller to free the given string if it was dynamically allocated.

Parameters
[in]varThe address of a string variable, that is, a pointer to a string.
[in]stringThe string to append to the string in the variable.

Definition at line 44 of file strings.c.

45 {
46  if (*var)
47  {
48  char *old = *var;
49  *var = g_strconcat (old, string, NULL);
50  g_free (old);
51  }
52  else
53  *var = g_strdup (string);
54 }

◆ 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.

When the variable is NULL store a copy of the given string in the variable.

When the variable already contains a string replace the string with a new string that is the concatenation of the two, freeing the old string. It is up to the caller to free the given string if it was dynamically allocated.

The string must be NULL terminated, and the given length must be the actual length of the string.

Parameters
[in]varThe address of a string variable, that is, a pointer to a string.
[in]stringThe string to append to the string in the variable.
[in]lengthThe length of string.

Definition at line 74 of file strings.c.

75 {
76  if (*var)
77  {
78  char *old = *var;
79  *var = g_strconcat (old, string, NULL);
80  g_free (old);
81  }
82  else
83  *var = g_strndup (string, length);
84 }

Referenced by append_to_credentials_password(), and append_to_credentials_username().

Here is the caller graph for this function:

◆ gvm_free_string_var()

void gvm_free_string_var ( gchar **  var)

Free a string variable.

Free the string in the variable and set the variable to NULL.

Parameters
[in]varThe address of a string variable, that is, a pointer to a string.

Definition at line 95 of file strings.c.

96 {
97  g_free (*var);
98  *var = NULL;
99 }

◆ gvm_strip_space()

char* gvm_strip_space ( char *  string,
char *  end 
)

"Strip" space and newline characters from either end of some memory.

Return the given pointer moved forward past any spaces, replacing the first of any contiguous spaces at or before the end of the memory with a terminating NULL.

This is for use when string points into a static buffers.

Parameters
[in,out]stringThe start of the memory.
[in]endPointer to the byte after the end of the memory.
Returns
A new pointer into the string.

Definition at line 116 of file strings.c.

117 {
118  assert (string <= end);
119  if (string >= end)
120  return string;
121  end--;
122  while (string[0] == ' ' || string[0] == '\n')
123  {
124  string++;
125  if (string >= end)
126  {
127  end[0] = '\0';
128  return end;
129  }
130  }
131 
132  /* Here string is < end. */
133  if (end[0] == ' ' || end[0] == '\n')
134  {
135  end--;
136  while (end >= string && (end[0] == ' ' || end[0] == '\n'))
137  {
138  end--;
139  }
140  end[1] = '\0';
141  }
142  return string;
143 }