|
| struct clod_string | clod_string_from_cstr (const char *cstr) |
| | Make a string from a C string.
|
| size_t | clod_string_cat (struct clod_string *dst, struct clod_string src) |
| size_t | clod_string_insert (struct clod_string *dst, struct clod_string src) |
| int | clod_string_cmp (struct clod_string str1, struct clod_string str2) |
| void | clod_string_put_char (struct clod_string *str, char c) |
| | Append a single char to the end of the string.
|
| char | clod_string_get_char (struct clod_string *str) |
| | Remove a single char from the start of the string.
|
| char | clod_string_peek_char (struct clod_string str) |
| | Get the first char in the string.
|
| CLOD_API int | clod_string_parse (struct clod_string src, struct clod_string fmt,...) |
|
CLOD_API int | clod_string_vparse (struct clod_string src, struct clod_string fmt, va_list args) |
| | Same as clod_string_parse but takes a va-list argument instead of '...'.
|
| CLOD_API struct clod_string | clod_string_contains (struct clod_string str, struct clod_string elem) |
| CLOD_API struct clod_string | clod_string_find (struct clod_string str, char elem, int occurrence) |
| CLOD_API bool | clod_string_remove_prefix (struct clod_string *str, struct clod_string prefix) |
| CLOD_API size_t | clod_string_put_int (struct clod_string *dst, intmax_t val, struct clod_string alphabet, unsigned char base, unsigned char min_digits, unsigned char max_digits) |
| CLOD_API intmax_t | clod_string_get_int (struct clod_string *str, struct clod_string alphabet, unsigned char base) |
| CLOD_API size_t | clod_string_put_uint (struct clod_string *dst, uintmax_t val, struct clod_string alphabet, unsigned char base, unsigned char min_digits, unsigned char max_digits) |
| CLOD_API uintmax_t | clod_string_get_uint (struct clod_string *str, struct clod_string alphabet, unsigned char base) |
| CLOD_API size_t | clod_string_put_double (struct clod_string *dst, double val, struct clod_string alphabet, unsigned char base, unsigned char min_digits, unsigned char max_digits) |
| CLOD_API double | clod_string_get_double (struct clod_string *str, struct clod_string alphabet, unsigned char base) |
Sized string helpers.
A definition of a sized string and a few simple methods for dealing with them. It's C-centric and mostly serves as a helper for some C-centric public libclod methods.
The general approach here is that methods operate on a particular input clod_string, and return that same string but with the length field updated to reflect the result of the operation. Some methods may make other changes, but no memory allocation is ever performed.
Definition in file string.h.
Compare two strings. If str1 > str2 it returns 1, if str1 == str2 it returns 0, and if str1 < str2 it returns -1;
Strings are first compared by their length, longer is larger. Then they are compared bytewise, returning on the first non-equal comparison. Otherwise, they are considered equal and 0 is returned.
- Parameters
-
| [in] | str1 | 1st string. |
| [in] | str2 | 2nd string. |
- Returns
- The result of str1 - str2.
Definition at line 75 of file string.c.
Format a string similarly to snprintf. The format specification differs from the standard library in a few ways.
%[flags][width][.precision]<type>
- Flags Options for changing formatting.
- Width the minimum size of the number as formatted.
- Precision the maximum size of the number as formatted.
- Type the type of the value passed as argument.
| Flag | Description |
| 0 | Pad with zeroes instead of spaces. |
| X | Base 16, uppercase. |
| x | Base 16, lowercase. |
| o | Base 8 |
| b | Base 2 |
| Type | Specifier |
| int | i |
| unsigned int | u |
| long | l |
| unsigned long | ul |
| long long | ll |
| unsigned long long | ull |
| int32_t | i32 |
| uint32_t | u32 |
| int64_t | i64 |
| uint64_t | u64 |
| size_t | size |
| ptrdiff_t | ptrdiff |
| void * | ptr |
| double | d |
| struct clod_string * | str |
| C string | s |
- Parameters
-
| [in] | dst | Where the formatted string is written to. |
| [in] | fmt | Format. |
| [in] | ... | Values to format. |
- Returns
- The number of characters that have been, or would have been, written to
dst. */ CLOD_API size_t clod_string_format(struct clod_string *dst, struct clod_string fmt, ...);
/ Same as clod_string_format, but takes a va_list argument instead of '...'. CLOD_API size_t clod_string_vformat(struct clod_string *dst, struct clod_string fmt, va_list args);
/** Parses values in a string into the provided arguments. Attempts to be as close to a reverse of clod_string_format as possible.
- Parameters
-
| [in] | src | Source string to parse. |
| [in] | fmt | Format. |
| [in] | ... | Pointers to the types specified in fmt. |
- Returns
- Number of parameters parsed.