CLibs
|
#include "headers/attributes.h"
#include <regex.h>
#include <stdbool.h>
#include <sys/types.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
Go to the source code of this file.
Macros | |
#define | strndup string_nduplicate |
#define | strdup string_duplicate |
#define | ESCAPED_CHARS "\n\t\r\f\v\"\\" |
Charset of special characters that can be escaped. | |
#define | STRSPLIT_EXCLUDE_EMPTY ( 1 << 0 ) |
#define | STRSPLIT_KEEP_DELIM_BEFORE ( 1 << 1 ) |
#define | STRSPLIT_KEEP_DELIM_AFTER ( 1 << 2 ) |
#define | STRSPLIT_STRIP_RESULTS ( 1 << 3 ) |
Only for string_split() (not regex) |
Typedefs | |
typedef const char * | string_t |
Immutable string. | |
typedef char * | str_t |
Mutable string. | |
typedef unsigned int | strsplit_mode_t |
typedef const string_t * | strjoin_strarr_t |
String array being passed to string_join may be typecast to this. |
#define ESCAPED_CHARS "\n\t\r\f\v\"\\" |
Charset of special characters that can be escaped.
#define strdup string_duplicate |
#define strndup string_nduplicate |
#define STRSPLIT_EXCLUDE_EMPTY ( 1 << 0 ) |
#define STRSPLIT_KEEP_DELIM_AFTER ( 1 << 2 ) |
#define STRSPLIT_KEEP_DELIM_BEFORE ( 1 << 1 ) |
#define STRSPLIT_STRIP_RESULTS ( 1 << 3 ) |
Only for string_split() (not regex)
typedef char* str_t |
Mutable string.
typedef const char* string_t |
Immutable string.
typedef const string_t* strjoin_strarr_t |
String array being passed to string_join may be typecast to this.
typedef unsigned int strsplit_mode_t |
Flags for the string_split[_regex] functions
UseResult char * add_uint_strings | ( | const char * | , |
const char * | ) |
LibraryDefined int asprintf | ( | str_t * | strp, |
const string_t | fmt, | ||
... ) |
Like sprintf(), except it heap-allocates memory for the resulting string. *strp may be passed to free(3) *
UseResult char * mul_uint_strings | ( | const char * | , |
const char * | ) |
Creates a new string with all uppercase letters replaced with lowercase ones
Creates a new string with all lowercase letters replaced with uppercase ones
LibraryDefined UseResult str_t string_duplicate | ( | string_t | s | ) |
strdup implementation (standard in POSIX and C23+)
Escapes characters defined in ESCAPED_CHARS
Example:
prints
bool string_is_blank | ( | string_t | ) |
Returns true if ascii string is blank
bool string_is_blank_l | ( | string_t | , |
size_t | len ) |
Returns true if ascii string is blank
len | max string length |
bool string_is_empty | ( | string_t | s | ) |
Evaluates to true if string contains no characters
s | string |
Joins a string array into one long string.
len | length of strarr |
strarr | array of string (not modified in this function) |
joiner | string to be put between each member of strarr |
LibraryDefined UseResult str_t string_nduplicate | ( | string_t | s, |
size_t | l ) |
strndup implementation (standard in POSIX and C23+)
Replaces all occurrences of a substring with another one. This is done in-place.
The substitution string must be the same length as the old substituted string. (for arbitrary lengths use string_replaced)
string | this string is modified |
old | must be the same length as new |
new | must be the same length as old |
Creates a new string with all occurrences of the sub-string old replaced with new
old | old substring |
new | new substring |
void string_reverse | ( | str_t | ) |
Reverses the string. This is done in place.
Creates a new string with the same characters as the supplied one, reversed.
ssize_t string_split | ( | str_t ** | str_arr_cont, |
string_t | string, | ||
string_t | split_tok, | ||
strsplit_mode_t | mode ) |
Splits str at places matching split_tok
Substring must match perfectly
str_arr_cont | container for the string_array for the result; the resulting string array is allocated in this function |
string | string to be split |
split_tok | boundary |
mode | see strsplit_mode_t |
void string_split_destroy | ( | size_t | size, |
str_t ** | str_arr_cont ) |
free()s all memory allocated by string_split() or string_split_regex().
Also sets str_arr to NULL
size | number of strings in *str_arr_cont |
str_arr_cont | same variable as the one passed to string_split() |
ssize_t string_split_regex | ( | str_t ** | str_arr_cont, |
string_t | string, | ||
const regex_t *__restrict | regexp, | ||
strsplit_mode_t | mode ) |
Splits str at places matching regex
Substring must match regex
str_arr_cont | container for the string_array for the result; the resulting string array is allocated in this function |
string | string to be split |
regexp | boundary; compiled regex |
mode | see strsplit_mode_t |
void string_strip | ( | str_t | ) |
Removes all whitespace from either end of the string. This is done in place.
string_stripped() is implemented separately from string_strip for memory efficiency
void string_strip_lead_zeroes | ( | str_t | ) |
Heap-allocates a new string with all whitespace (as defined in isspace(3)) from either end stripped.
Heap-allocates a new string with all whitespace (as defined in isspace(3)) from either end stripped.
String is treated as if it was length characters long (at most, may be less)
length | maximum number of characters read from string |
void string_to_lower | ( | str_t | ) |
Replaces all uppercase letters to corresponding lowercase letters
void string_to_upper | ( | str_t | ) |
Replaces all lowercase letters to corresponding uppercase letters
Opposite of string_escaped()
LibraryDefined int vasprintf | ( | str_t * | strp, |
const string_t | fmt, | ||
va_list | args ) |
Like vsprintf(), except it heap-allocates memory for the resulting string. *strp may be passed to free(3)
int vsnprintf | ( | char * | str, |
size_t | size, | ||
const char *restrict | format, | ||
va_list | ap ) |
va_list version of snprintf()