Provides string helper structures/functions (roughly equivalent to std::string).
#include <util/dstr.h>
Case insensitive string comparison function.
Case insensitive wide string comparison function.
String comparison function for a specific number of characters.
Wide string comparison function for a specific number of characters.
Case insensitive string comparison function for a specific number of characters.
Case insensitive wide string comparison function for a specific number of characters.
Case insensitive version of strstr.
Case insensitive version of wcsstr.
Removes padding characters (tab, space, CR, LF) from the front and end of a string.
Removes padding characters (tab, space, CR, LF) from the front and end of a wide string.
Splits a string in to a list of multiple sub-strings, terminated by
NULL. If split_ch does not exist in the string, the first
sub-string will be the same as str. Free with strlist_free().
str – The string to be split
split_ch – The delimiter
include_empty – If true, empty strings caused by having the
split_ch right next to another will be
included in the list. If false, they won’t
be included.
Sample usage:
char **words = strlist_split("OBS Studio", ' ', false);
int count = 0;
for (char **word = words; *word; ++word) {
count++;
blog(LOG_DEBUG, "%s", *word);
}
strlist_free(words);
// count == 2
Frees a string list created with strlist_split().
Initializes a dynamic string variable (just zeroes the variable).
dst – Dynamic string to initialize
Moves a src to dst without copying data and zeroes src.
dst – Destination
src – Source
Sets a bmalloc-allocated string as the dynamic string without copying/reallocating.
dst – Dynamic string to initialize
str – bmalloc-allocated string
Initializes a dynamic string with a copy of a string
dst – Dynamic string to initialize
src – String to copy
Initializes a dynamic string with a copy of another dynamic string
dst – Dynamic string to initialize
src – Dynamic string to copy
Copies a string.
dst – Dynamic string
array – String to copy
Copies another dynamic string.
dst – Dynamic string
src – Dynamic string to copy
Copies a specific number of characters from a string.
dst – Dynamic string
array – String to copy
len – Number of characters to copy
Copies a specific number of characters from another dynamic string.
dst – Dynamic string
src – Dynamic string to copy
len – Number of characters to copy
Sets the size of the dynamic string. If the new size is bigger than current size, zeroes the new characters.
dst – Dynamic string
num – New size
Reserves a specific number of characters in the buffer (but does not change the size). Does not work if the value is smaller than the current reserve size.
dst – Dynamic string
num – New reserve size
Returns whether the dynamic string is empty.
str – Dynamic string
true if empty, false otherwise
Concatenates a dynamic string.
dst – Dynamic string
array – String to concatenate with
Concatenates a dynamic string with another dynamic string.
dst – Dynamic string to concatenate to
str – Dynamic string to concatenate with
Concatenates a dynamic string with a single character.
dst – Dynamic string to concatenate to
ch – Character to concatenate
Concatenates a dynamic string with a specific number of characters from a string.
dst – Dynamic string to concatenate to
array – String to concatenate with
len – Number of characters to concatenate with
Concatenates a dynamic string with a specific number of characters from another dynamic string.
dst – Dynamic string to concatenate to
str – Dynamic string to concatenate with
len – Number of characters to concatenate with
Inserts a string in to a dynamic string at a specific index.
dst – Dynamic string to insert in to
idx – Character index to insert at
array – String to insert
Inserts another dynamic string in to a dynamic string at a specific index.
dst – Dynamic string to insert in to
idx – Character index to insert at
str – Dynamic string to insert
Inserts a character in to a dynamic string at a specific index.
dst – Dynamic string to insert in to
idx – Character index to insert at
ch – Character to insert
Removes a specific number of characters starting from a specific index.
dst – Dynamic string
idx – Index to start removing characters at
count – Number of characters to remove
Sets a dynamic string to a formatted string.
dst – Dynamic string
format – Format string
Concatenates a dynamic string with a formatted string.
dst – Dynamic string
format – Format string
Finds a string within a dynamic string, case insensitive.
str – Dynamic string
find – String to find
Pointer to the first occurrence, or NULL if not found
Finds a string within a dynamic string.
str – Dynamic string
find – String to find
Pointer to the first occurrence, or NULL if not found
Replaces all occurrences of find with replace.
str – Dynamic string
find – String to find
replace – Replacement string
Compares with a string.
str1 – Dynamic string
str2 – String to compare
0 if equal, nonzero otherwise
Compares with a string, case-insensitive.
str1 – Dynamic string
str2 – String to compare
0 if equal, nonzero otherwise
Compares a specific number of characters.
str1 – Dynamic string
str2 – String to compare
n – Number of characters to compare
0 if equal, nonzero otherwise
Compares a specific number of characters, case-insensitive.
str1 – Dynamic string
str2 – String to compare
n – Number of characters to compare
0 if equal, nonzero otherwise
Removes all padding characters (tabs, spaces, CR, LF) from the front and ends of a dynamic string.
dst – Dynamic string
Copies a certain number of characters from the left side of one dynamic string in to another.
dst – Destination
str – Source
pos – Number of characters
Copies a certain number of characters from the middle of one dynamic string in to another.
dst – Destination
str – Source
start – Starting index within str
count – Number of characters to copy
Copies a certain number of characters from the right of one dynamic string in to another.
dst – Destination
str – Source
pos – Index of str to copy from
str – Dynamic string
The last character of a dynamic string
Copies a wide string in to a dynamic string and converts it to UTF-8.
dst – Dynamic string
wstr – Wide string
Converts a dynamic array to a wide string. Free with
bfree().
str – Dynamic string
Wide string allocation. Free with bfree()
Converts all characters within a dynamic array to uppercase.
str – Dynamic string