NetSurf
Functions
string.h File Reference

Interface to utility string handling. More...

#include <stdlib.h>
#include <stdarg.h>
#include "utils/errors.h"
Include dependency graph for string.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

char * squash_whitespace (const char *s)
 Replace consecutive whitespace with a single space. More...
 
char * cnv_space2nbsp (const char *s)
 Converts NUL terminated UTF-8 encoded string s containing zero or more spaces (char 32) or TABs (char 9) to non-breaking spaces (0xC2 + 0xA0 in UTF-8 encoding). More...
 
char * human_friendly_bytesize (unsigned long long int bytesize)
 Create a human readable representation of a size in bytes. More...
 
nserror vsnstrjoin (char **str, size_t *size, char sep, size_t nelm, va_list ap)
 Generate a string from one or more component elements separated with a single value. More...
 
nserror snstrjoin (char **str, size_t *size, char sep, size_t nelm,...)
 Generate a string from one or more component elements separated with a single value. More...
 

Detailed Description

Interface to utility string handling.

Definition in file string.h.

Function Documentation

◆ cnv_space2nbsp()

char * cnv_space2nbsp ( const char *  s)

Converts NUL terminated UTF-8 encoded string s containing zero or more spaces (char 32) or TABs (char 9) to non-breaking spaces (0xC2 + 0xA0 in UTF-8 encoding).

Caller needs to free() result. Returns NULL in case of error. No checking is done on validness of the UTF-8 input string.

Definition at line 67 of file utils.c.

Referenced by box_select_add_option(), and ro_gui_window_prepare_form_select_menu().

Here is the caller graph for this function:

◆ human_friendly_bytesize()

char * human_friendly_bytesize ( unsigned long long int  bytesize)

Create a human readable representation of a size in bytes.

Does a simple conversion which assumes the user speaks English. The buffer returned is one of three static ones so may change each time this call is made. Don't store the buffer for later use. It's done this way for convenience and to fight possible memory leaks, it is not necessarily pretty.

Parameters
bytesizeThe size in bytes.
Returns
A human readable string representing the size.

Definition at line 209 of file utils.c.

References BYTESIZE_BUFFER_SIZE, and messages_get().

Referenced by ami_download_check_overwrite(), fetch_curl_progress(), gui_download_window_create(), gui_download_window_data(), gui_download_window_done(), NSDownloadWindow::NSDownloadWindow(), nsgtk_download_info_to_string(), nsgtk_download_store_update_item(), nsws_download_update_label(), NSDownloadWindow::Progress(), and ro_gui_download_update_status().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ snstrjoin()

nserror snstrjoin ( char **  str,
size_t *  size,
char  sep,
size_t  nelm,
  ... 
)

Generate a string from one or more component elements separated with a single value.

This is similar in intent to the Perl join function creating a single delimited string from an array of several.

Note
If a string is allocated it must be freed by the caller.
Parameters
[in,out]strpointer to string pointer if this is NULL enough storage will be allocated for the complete path.
[in,out]sizeThe size of the space available if str not NULL on input and if not NULL set to the total output length on output.
[in]sepThe character to separate the elements with.
[in]nelmThe number of elements up to a maximum of 16.
[in]...The elements of the path as string pointers.
Returns
NSERROR_OK and the complete path is written to str or error code on failure.

Definition at line 179 of file utils.c.

References vsnstrjoin().

Here is the call graph for this function:

◆ squash_whitespace()

char * squash_whitespace ( const char *  s)

Replace consecutive whitespace with a single space.

Todo:
determine if squash_whitespace utf-8 safe and that it needs to be
Parameters
ssource string
Returns
heap allocated result, or NULL on memory exhaustion

Definition at line 38 of file utils.c.

Referenced by box_construct_element(), box_construct_text(), box_image(), box_select_add_option(), and html_process_title().

Here is the caller graph for this function:

◆ vsnstrjoin()

nserror vsnstrjoin ( char **  str,
size_t *  size,
char  sep,
size_t  nelm,
va_list  ap 
)

Generate a string from one or more component elements separated with a single value.

This is similar in intent to the perl join function creating a single delimited string from an array of several.

Note
If a string is allocated it must be freed by the caller.
Parameters
[in,out]strpointer to string pointer if this is NULL enough storage will be allocated for the complete path.
[in,out]sizeThe size of the space available if str not NULL on input and if not NULL set to the total output length on output.
[in]sepThe character to separate the elements with.
[in]nelmThe number of elements up to a maximum of 16.
[in]apThe elements of the path as string pointers.
Returns
NSERROR_OK and the complete path is written to str or error code on failure.

Definition at line 107 of file utils.c.

References NSERROR_BAD_PARAMETER, NSERROR_NOMEM, NSERROR_NOSPACE, and NSERROR_OK.

Referenced by atari_mkpath(), posix_vmkpath(), snstrjoin(), and windows_mkpath().

Here is the caller graph for this function: