QSC Post Quantum Cryptographic Library 1.0.0.6c (A6)
A post quantum secure library written in Ansi C
 
Loading...
Searching...
No Matches
stringutils.h File Reference

String utilities; common string support functions. More...

#include "common.h"

Go to the source code of this file.

Macros

#define QSC_STRINGUTILS_TOKEN_NOT_FOUND   -1LL
 The search token was not found.
 
#define QSC_STRINGUTILS_HEX_EXTENSION_SIZE   2ULL
 The char size of the hex extension.
 
#define QSC_STRINGUTILS_HEX_BYTE_SIZE   2ULL
 The char size of a hexidecimal byte.
 

Functions

QSC_EXPORT_API size_t qsc_stringutils_formatting_count (const char *dest, size_t dstlen)
 Counts all white-spaces, line stops, and returns from a string.
 
QSC_EXPORT_API size_t qsc_stringutils_formatting_filter (const char *source, size_t srclen, char *dest)
 Remove all white-spaces, lines stops, and returns from a string.
 
QSC_EXPORT_API size_t qsc_stringutils_add_line_breaks (char *dest, size_t dstlen, size_t linelen, const char *source, size_t srclen)
 Add line breaks to a string at a line length interval.
 
QSC_EXPORT_API size_t qsc_stringutils_remove_line_breaks (char *dest, size_t dstlen, const char *source, size_t srclen)
 Removes all line breaks from a string.
 
QSC_EXPORT_API void qsc_stringutils_clear_string (char *source)
 Clear a string of data.
 
QSC_EXPORT_API void qsc_stringutils_clear_substring (char *dest, size_t length)
 Clear a length of data from a string.
 
QSC_EXPORT_API bool qsc_stringutils_compare_strings (const char *str1, const char *str2, size_t length)
 Compare two strings for equivalence.
 
QSC_EXPORT_API size_t qsc_stringutils_concat_strings (char *dest, size_t dstlen, const char *source)
 Concatenate two strings.
 
QSC_EXPORT_API size_t qsc_stringutils_concat_and_copy (char *dest, size_t dstlen, const char *str1, const char *str2)
 Concatenate two strings and copy them to a third string.
 
QSC_EXPORT_API size_t qsc_stringutils_copy_substring (char *dest, size_t dstlen, const char *source, size_t srclen)
 Copy a length of one string to another.
 
QSC_EXPORT_API size_t qsc_stringutils_copy_string (char *dest, size_t dstlen, const char *source)
 Copy a source string to a destination string.
 
QSC_EXPORT_API int64_t qsc_stringutils_find_char (const char *source, const char token)
 Find a character position within a string.
 
QSC_EXPORT_API int64_t qsc_stringutils_find_string (const char *source, const char *token)
 Find a substrings position within a string.
 
QSC_EXPORT_API void qsc_stringutils_byte_to_hex (char *hex, uint8_t input)
 Convert a byte to a hexidecimal string.
 
QSC_EXPORT_API uint8_t qsc_stringutils_hex_to_byte (const char *hex)
 Convert a hexidecimal string to a byte.
 
QSC_EXPORT_API int64_t qsc_stringutils_insert_string (char *dest, size_t dstlen, const char *source, size_t offset)
 Inserts a substring into a string.
 
QSC_EXPORT_API bool qsc_stringutils_is_empty (const char *source)
 Check if a string contains and characters.
 
QSC_EXPORT_API bool qsc_stringutils_is_hex (const char *source, size_t srclen)
 Check that a string contains only hexadecimal ASCII characters.
 
QSC_EXPORT_API bool qsc_stringutils_is_numeric (const char *source, size_t srclen)
 Check that a string contains only numeric ASCII characters.
 
QSC_EXPORT_API char * qsc_stringutils_register_string (char **source, size_t count)
 Join an array of strings to form one string.
 
QSC_EXPORT_API size_t qsc_stringutils_remove_null_chars (char *source, size_t srclen)
 Remove null characters from an array.
 
QSC_EXPORT_API int64_t qsc_stringutils_reverse_find_string (const char *source, const char *token, size_t start)
 Find the position of a substring within a string, searching in reverse.
 
QSC_EXPORT_API const char * qsc_stringutils_reverse_sub_string (const char *source, const char *token)
 Find a substring within a string, searching in reverse.
 
bool qsc_stringutils_string_compare (const char *str1, const char *str2, size_t length)
 Compare two strings for equality.
 
QSC_EXPORT_API int32_t qsc_stringutils_string_comparison (const char *source, const char *token)
 Test if the string contains a substring.
 
QSC_EXPORT_API bool qsc_stringutils_string_contains (const char *source, const char *token)
 Test if the string contains a substring.
 
QSC_EXPORT_API bool qsc_stringutils_strings_equal (const char *str1, const char *str2)
 Compare two strings for equality.
 
QSC_EXPORT_API char ** qsc_stringutils_split_string (char *source, const char *delim, size_t *count)
 Split a string into a substring 2-dimensional array.
 
QSC_EXPORT_API void qsc_stringutils_split_strings (char *dest1, char *dest2, size_t destlen, const char *source, const char *token)
 Split a string into two substrings.
 
QSC_EXPORT_API char * qsc_stringutils_sub_string (const char *source, const char *token)
 Find a substring within a string.
 
QSC_EXPORT_API int32_t qsc_stringutils_string_to_int (const char *source)
 Convert a string to a 32-bit integer.
 
QSC_EXPORT_API size_t qsc_stringutils_string_size (const char *source)
 Get the character length of a string.
 
QSC_EXPORT_API void qsc_stringutils_int_to_string (int32_t num, char *dest, size_t dstlen)
 Convert a 32-bit signed integer to a string.
 
QSC_EXPORT_API void qsc_stringutils_uint32_to_string (uint32_t num, char *dest, size_t destlen)
 Convert a 32-bit unsigned integer to a string.
 
QSC_EXPORT_API void qsc_stringutils_int64_to_string (int64_t num, char *dest, size_t dstlen)
 Convert a 64-bit signed integer to a string.
 
QSC_EXPORT_API void qsc_stringutils_uint64_to_string (uint64_t num, char *dest, size_t dstlen)
 Convert a 64-bit unsigned integer to a string.
 
QSC_EXPORT_API void qsc_stringutils_to_lowercase (char *source)
 Convert a string to all lower-case characters.
 
QSC_EXPORT_API void qsc_stringutils_to_uppercase (char *source)
 Convert a string to all upper-case characters.
 
QSC_EXPORT_API void qsc_stringutils_trim_newline (char *source)
 Trim null and newline characters from a string.
 
QSC_EXPORT_API void qsc_stringutils_trim_spaces (char *source)
 Trim a trailing space character from a string.
 
QSC_EXPORT_API size_t qsc_stringutils_whitespace_count (const char *source, size_t srclen)
 Count all the white-spaces in a string.
 
QSC_EXPORT_API size_t qsc_stringutils_whitespace_filter (const char *source, size_t srclen, char *dest)
 Remove all the white-spaces from a string.
 

Detailed Description

String utilities; common string support functions.

This header provides a comprehensive set of functions for handling strings, including operations for formatting (adding and removing line breaks or whitespace), concatenation, substring extraction, comparison, and conversion between data types and their string representations. These utilities are designed to simplify the manipulation and processing of strings within applications.

// Example: Remove all whitespace from a string.
const char* original = " Hello, World! ";
char cleaned[50] = { 0 };
size_t new_len = qsc_stringutils_whitespace_filter(original, strlen(original), cleaned);
printf("Cleaned string: '%s' (length: %zu)\n", cleaned, new_len);

Reference Links:

Function Documentation

◆ qsc_stringutils_add_line_breaks()

QSC_EXPORT_API size_t qsc_stringutils_add_line_breaks ( char * dest,
size_t dstlen,
size_t linelen,
const char * source,
size_t srclen )

Add line breaks to a string at a line length interval.

Parameters
dest[char*] The string receiving the formatted text
dstlen[size_t] The size of the dest array
linelen[size_t] The line length where a new line character is placed
source[const char*] The source string to copy from
srclen[size_t] The length of the source array
Returns
[size_t] Returns the size of the dest string

◆ qsc_stringutils_byte_to_hex()

QSC_EXPORT_API void qsc_stringutils_byte_to_hex ( char * hex,
uint8_t input )

Convert a byte to a hexidecimal string.

Parameters
hex[char*] The hex string output
input[uint8_t] The byte to be converted

◆ qsc_stringutils_clear_string()

QSC_EXPORT_API void qsc_stringutils_clear_string ( char * source)

Clear a string of data.

Parameters
source[char*] The string to clear

◆ qsc_stringutils_clear_substring()

QSC_EXPORT_API void qsc_stringutils_clear_substring ( char * dest,
size_t length )

Clear a length of data from a string.

Parameters
dest[char*] The string dest to clear
length[size_t] The number of characters to clear

◆ qsc_stringutils_compare_strings()

QSC_EXPORT_API bool qsc_stringutils_compare_strings ( const char * str1,
const char * str2,
size_t length )

Compare two strings for equivalence.

Parameters
str1[const char*] The first string
str2[const char*] The second string
length[size_t] The number of characters to compare
Returns
[bool] Returns true if the strings are equal

◆ qsc_stringutils_concat_and_copy()

QSC_EXPORT_API size_t qsc_stringutils_concat_and_copy ( char * dest,
size_t dstlen,
const char * str1,
const char * str2 )

Concatenate two strings and copy them to a third string.

Parameters
dest[char*] The destination string to copy to
dstlen[size_t] The size of the destination dest
str1[const char*] The first string to copy from
str2[const char*] The second string to copy from
Returns
[size_t] Returns the size of the string

◆ qsc_stringutils_concat_strings()

QSC_EXPORT_API size_t qsc_stringutils_concat_strings ( char * dest,
size_t dstlen,
const char * source )

Concatenate two strings.

Parameters
dest[char*] The destination dest
dstlen[size_t] The size of the destination dest
source[const char*] The source string to copy
Returns
[size_t] Returns the size of the string

◆ qsc_stringutils_copy_string()

QSC_EXPORT_API size_t qsc_stringutils_copy_string ( char * dest,
size_t dstlen,
const char * source )

Copy a source string to a destination string.

Parameters
dest[char*] The destination string to copy to
dstlen[size_t] The size of the destination dest
source[const char*] The string to copy from
Returns
[size_t] Returns the size of the string

◆ qsc_stringutils_copy_substring()

QSC_EXPORT_API size_t qsc_stringutils_copy_substring ( char * dest,
size_t dstlen,
const char * source,
size_t srclen )

Copy a length of one string to another.

Parameters
dest[char*] The destination string to copy to
dstlen[size_t] The size of the destination dest
source[const char*] The string to copy from
srclen[size_t] The substring length
Returns
[size_t] Returns the size of the string

◆ qsc_stringutils_find_char()

QSC_EXPORT_API int64_t qsc_stringutils_find_char ( const char * source,
const char token )

Find a character position within a string.

Parameters
source[const char*] The string to check for the substring
token[char] The character to search for
Returns
[int64_t] Returns the character position within the string, or QSC_STRINGUTILS_TOKEN_NOT_FOUND if the character is not found

◆ qsc_stringutils_find_string()

QSC_EXPORT_API int64_t qsc_stringutils_find_string ( const char * source,
const char * token )

Find a substrings position within a string.

Parameters
source[const char*] The string to check for the substring
token[const char*] The substring to search for
Returns
[int64_t] Returns the character position within the string, or QSC_STRINGUTILS_TOKEN_NOT_FOUND if the string is not found

◆ qsc_stringutils_formatting_count()

QSC_EXPORT_API size_t qsc_stringutils_formatting_count ( const char * dest,
size_t dstlen )

Counts all white-spaces, line stops, and returns from a string.

Parameters
dest[const char*] The string dest to check
dstlen[size_t] The size of the dest string
Returns
[size_t] Returns the number of line stops, carriage returns and white-spaces in the string

◆ qsc_stringutils_formatting_filter()

QSC_EXPORT_API size_t qsc_stringutils_formatting_filter ( const char * source,
size_t srclen,
char * dest )

Remove all white-spaces, lines stops, and returns from a string.

Parameters
source[const char*] The source string to copy from
srclen[size_t] The size of the source string
dest[char*] The string receiving the filtered characters
Returns
[size_t] Returns the number of characters copied

◆ qsc_stringutils_hex_to_byte()

QSC_EXPORT_API uint8_t qsc_stringutils_hex_to_byte ( const char * hex)

Convert a hexidecimal string to a byte.

Parameters
hex[const char*] The hex string
Returns
[uint8_t] Returns the byte value

◆ qsc_stringutils_insert_string()

QSC_EXPORT_API int64_t qsc_stringutils_insert_string ( char * dest,
size_t dstlen,
const char * source,
size_t offset )

Inserts a substring into a string.

Parameters
dest[char*] The string receiving the substring
dstlen[size_t] The size of the source dest
source[const char*] The substring to insert
offset[size_t] The insertion starting position within the source string; position is ordinal, 0-n
Returns
[int64_t] Returns the size of the new string, or QSC_STRINGUTILS_TOKEN_NOT_FOUND if the string insert operation failed

◆ qsc_stringutils_int64_to_string()

QSC_EXPORT_API void qsc_stringutils_int64_to_string ( int64_t num,
char * dest,
size_t dstlen )

Convert a 64-bit signed integer to a string.

Parameters
num[int64_t] The integer to convert
dest[char*] The destination string
dstlen[size_t] The size of the output dest

◆ qsc_stringutils_int_to_string()

QSC_EXPORT_API void qsc_stringutils_int_to_string ( int32_t num,
char * dest,
size_t dstlen )

Convert a 32-bit signed integer to a string.

Parameters
num[int32_t] The integer to convert
dest[char*] The destination string
dstlen[size_t] The size of the output dest

◆ qsc_stringutils_is_empty()

QSC_EXPORT_API bool qsc_stringutils_is_empty ( const char * source)

Check if a string contains and characters.

Parameters
source[const char*] The string to check for characters
Returns
[bool] Returns true if the string is empty

◆ qsc_stringutils_is_hex()

QSC_EXPORT_API bool qsc_stringutils_is_hex ( const char * source,
size_t srclen )

Check that a string contains only hexadecimal ASCII characters.

Parameters
source[const char*] The string to check for hexadecimal characters
srclen[size_t] The number of characters to check
Returns
[bool] Returns true if the string is hexadecimal

◆ qsc_stringutils_is_numeric()

QSC_EXPORT_API bool qsc_stringutils_is_numeric ( const char * source,
size_t srclen )

Check that a string contains only numeric ASCII characters.

Parameters
source[const char*] The string to check for numeric characters
srclen[size_t] The number of characters to check
Returns
[bool] Returns true if the string is numeric

◆ qsc_stringutils_register_string()

QSC_EXPORT_API char * qsc_stringutils_register_string ( char ** source,
size_t count )

Join an array of strings to form one string.

Warning
The string returned must be freed by the caller
Parameters
source[char**] The array of substrings
count[size_t] The number of substring arrays
Returns
[char*] Returns a concatenated string

◆ qsc_stringutils_remove_line_breaks()

QSC_EXPORT_API size_t qsc_stringutils_remove_line_breaks ( char * dest,
size_t dstlen,
const char * source,
size_t srclen )

Removes all line breaks from a string.

Parameters
dest[char*] The string receiving the formatted text
dstlen[size_t] The size of the dest array
source[const char*] The source string to copy from
srclen[size_t] The length of the source array
Returns
[size_t] Returns the size of the dest string

◆ qsc_stringutils_remove_null_chars()

QSC_EXPORT_API size_t qsc_stringutils_remove_null_chars ( char * source,
size_t srclen )

Remove null characters from an array.

Parameters
source[char*] The string to check for null characters
srclen[size_t] The number of characters to check
Returns
[size_t] The size of the cleaned string

◆ qsc_stringutils_reverse_find_string()

QSC_EXPORT_API int64_t qsc_stringutils_reverse_find_string ( const char * source,
const char * token,
size_t start )

Find the position of a substring within a string, searching in reverse.

Parameters
source[const char*] The string to check for the substring
token[const char*] The token separator
start[size_t] The starting position within the source string
Returns
[int64_t] Returns the substring starting position, or -1 if not found

◆ qsc_stringutils_reverse_sub_string()

QSC_EXPORT_API const char * qsc_stringutils_reverse_sub_string ( const char * source,
const char * token )

Find a substring within a string, searching in reverse.

Parameters
source[const char*] The string to check for the substring
token[const char*] The token separator
Returns
[const char*] Returns the substring, or NULL if not found

◆ qsc_stringutils_split_string()

QSC_EXPORT_API char ** qsc_stringutils_split_string ( char * source,
const char * delim,
size_t * count )

Split a string into a substring 2-dimensional array.

Warning
The array of strings returned must be freed by the caller
Parameters
source[char*] The string to split
delim[const char*] The char delimiter used to split the string
count[size_t*] The number of substrings in the new array
Returns
[char**] Returns a 2 dimensional character array of substrings

◆ qsc_stringutils_split_strings()

QSC_EXPORT_API void qsc_stringutils_split_strings ( char * dest1,
char * dest2,
size_t destlen,
const char * source,
const char * token )

Split a string into two substrings.

Parameters
dest1[char*] The first destination string
dest2[char*] The second destination string
destlen[size_t] The destination strings length
source[const char*] The source string
token[const char*] The search token

◆ qsc_stringutils_string_compare()

bool qsc_stringutils_string_compare ( const char * str1,
const char * str2,
size_t length )

Compare two strings for equality.

Parameters
str1[const char*] The string to check for the substring
str2[const char*] The substring to search for
length[size_t] The string length
Returns
[bool] Returns true if the strings are equal

◆ qsc_stringutils_string_comparison()

QSC_EXPORT_API int32_t qsc_stringutils_string_comparison ( const char * source,
const char * token )

Test if the string contains a substring.

Parameters
source[const char*] The string to check for the substring
token[const char*] The substring to search for
Returns
[int32_t] Returns zero if the strings are equal

◆ qsc_stringutils_string_contains()

QSC_EXPORT_API bool qsc_stringutils_string_contains ( const char * source,
const char * token )

Test if the string contains a substring.

Parameters
source[const char*] The string to check for the substring
token[const char*] The substring to search for
Returns
[bool] Returns true if the substring is found

◆ qsc_stringutils_string_size()

QSC_EXPORT_API size_t qsc_stringutils_string_size ( const char * source)

Get the character length of a string.

Parameters
source[const char*] The source string pointer
Returns
[size_t] Returns the size of the string

◆ qsc_stringutils_string_to_int()

QSC_EXPORT_API int32_t qsc_stringutils_string_to_int ( const char * source)

Convert a string to a 32-bit integer.

Parameters
source[const char*] The string to convert to an integer
Returns
[int32_t] Returns the converted integer

◆ qsc_stringutils_strings_equal()

QSC_EXPORT_API bool qsc_stringutils_strings_equal ( const char * str1,
const char * str2 )

Compare two strings for equality.

Parameters
str1[const char*] The first comparison string
str2[const char*] The second first comparison string
Returns
[bool] Returns true if the two strings are identical

◆ qsc_stringutils_sub_string()

QSC_EXPORT_API char * qsc_stringutils_sub_string ( const char * source,
const char * token )

Find a substring within a string.

Warning
The string returned must be freed by the caller
Parameters
source[const char*] The string to check for the substring
token[const char*] The token separator
Returns
[char*] Returns the substring, or NULL if not found

◆ qsc_stringutils_to_lowercase()

QSC_EXPORT_API void qsc_stringutils_to_lowercase ( char * source)

Convert a string to all lower-case characters.

Parameters
source[char*] The string to convert to lower-case

◆ qsc_stringutils_to_uppercase()

QSC_EXPORT_API void qsc_stringutils_to_uppercase ( char * source)

Convert a string to all upper-case characters.

Parameters
source[char*] The string to convert to upper-case

◆ qsc_stringutils_trim_newline()

QSC_EXPORT_API void qsc_stringutils_trim_newline ( char * source)

Trim null and newline characters from a string.

Parameters
source[char*] The string to trim

◆ qsc_stringutils_trim_spaces()

QSC_EXPORT_API void qsc_stringutils_trim_spaces ( char * source)

Trim a trailing space character from a string.

Parameters
source[char*] The string to trim

◆ qsc_stringutils_uint32_to_string()

QSC_EXPORT_API void qsc_stringutils_uint32_to_string ( uint32_t num,
char * dest,
size_t destlen )

Convert a 32-bit unsigned integer to a string.

Parameters
num[uint32_t] The integer to convert
dest[char*] The destination string
destlen[size_t] The size of the output dest

◆ qsc_stringutils_uint64_to_string()

QSC_EXPORT_API void qsc_stringutils_uint64_to_string ( uint64_t num,
char * dest,
size_t dstlen )

Convert a 64-bit unsigned integer to a string.

Parameters
num[uint64_t] The integer to convert
dest[char*] The destination string
dstlen[size_t] The size of the output dest

◆ qsc_stringutils_whitespace_count()

QSC_EXPORT_API size_t qsc_stringutils_whitespace_count ( const char * source,
size_t srclen )

Count all the white-spaces in a string.

Parameters
source[const char*] The string dest to check
srclen[size_t] The size of the dest string
Returns
[size_t] Returns the number of white-spaces in the string

◆ qsc_stringutils_whitespace_filter()

QSC_EXPORT_API size_t qsc_stringutils_whitespace_filter ( const char * source,
size_t srclen,
char * dest )

Remove all the white-spaces from a string.

Parameters
source[const char*] The source string to copy from
srclen[size_t] The size of the source string
dest[char*] The destination string receiving the filtered characters
Returns
[size_t] Returns the number of characters copied