OpenVAS Libraries  4.0+rc3.SVN
Defines | Functions
base/openvas_string.c File Reference

String utilities. More...

#include <assert.h>
#include <ctype.h>
#include <glib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include "openvas_string.h"

Defines

#define TRACE   1
 Trace flag.
#define G_LOG_DOMAIN   "md string"
 GLib log domain.

Functions

void openvas_append_string (gchar **var, const gchar *string)
 Append a string to a string variable.
void openvas_append_text (gchar **var, const gchar *string, gsize length)
 Append a string of a known length to a string variable.
void openvas_free_string_var (string *var)
 Free a string variable.
char * openvas_strip_space (char *string, char *end)
 "Strip" space and newline characters from either end of some memory.
int openvas_isalnumstr (const char *string)
 Check whether a string contains only alphanumeric characters.
int openvas_isbase64 (const char *string)
 Check whether a string contains only base64 characters.
gboolean openvas_strv_contains_str (gchar **strv, const gchar *str)
 Check whether a NULL-terminated string vector contains a string.
gchar * openvas_string_flatten_string_list (GSList *string_list, const gchar *separator)
 Concatenates strings in a GSList, optionally separating these with.
void openvas_string_list_free (GSList *string_list)
 Frees content of list and list with g_(slist_)free.

Detailed Description

String utilities.


Define Documentation

#define TRACE   1

Trace flag.

0 to turn off all tracing messages.


Function Documentation

void openvas_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.
void openvas_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.
void openvas_free_string_var ( string *  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.
int openvas_isalnumstr ( const char *  string)

Check whether a string contains only alphanumeric characters.

Parameters:
stringString to check.
Returns:
1 if all characters are alphanumeric, else 0.
int openvas_isbase64 ( const char *  string)

Check whether a string contains only base64 characters.

Parameters:
stringString to check.
Returns:
1 if all characters are base64 characters, else 0.
gchar* openvas_string_flatten_string_list ( GSList *  string_list,
const gchar *  separator 
)

Concatenates strings in a GSList, optionally separating these with.

a defined string.

Parameters:
[in]string_listList of strings, if NULL, return empty string.
[in]separatorIf not NULL, string to put between each two strings in string_list.
Returns:
Concatenation of strings in string_list, empty string if list is empty. Caller has to free with g_free.
void openvas_string_list_free ( GSList *  string_list)

Frees content of list and list with g_(slist_)free.

Parameters:
[in]string_listGSList to free.
char* openvas_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.
gboolean openvas_strv_contains_str ( gchar **  strv,
const gchar *  str 
)

Check whether a NULL-terminated string vector contains a string.

Parameters:
strv[in]NULL-terminated string vector.
str[in]String to search in strv.
Returns:
TRUE if str is found in strv, FALSE otherwise.