Commonly used functions.
More...
|
#define | UNUSED(x) (void)(x) |
| Supresses unused variable warnings.
|
|
#define | STR(x) STR_HELPER(x) |
| Converts a macro to a string.
|
|
|
int | strtok_ri (const char *restrict str, char delim, Py_ssize_t *restrict strLen, occurrence_t *restrict lastoccurrence) |
| Version of strtok_r that doesn't modify the original string.
|
|
void | percent_encode_char (char *restrict out, char c) |
| Writes a percent encoded character to a buffer.
|
|
uint32_t | strncount (const char *restrict str, char c, size_t len) |
| Counts the number of occurrences of c in str.
|
|
void * | memchr2 (const void *buf, int c1, int c2, size_t len) |
| Finds the first occurrence of either c1 or c2 in buf.
|
|
Commonly used functions.
Mainly contains functions for string manipulation (very much a core of the library). Also here is where percent encoding handling lives
◆ STR
Converts a macro to a string.
- Parameters
-
◆ UNUSED
#define UNUSED |
( |
|
x | ) |
(void)(x) |
Supresses unused variable warnings.
- Parameters
-
x | the variable to suppress the warning for |
In C++11 you can just not provide a name for the parameter to suppress the warning, but in C you have to use this macro
◆ memchr2()
void * memchr2 |
( |
const void * |
buf, |
|
|
int |
c1, |
|
|
int |
c2, |
|
|
size_t |
len |
|
) |
| |
Finds the first occurrence of either c1 or c2 in buf.
- Parameters
-
buf | the buffer to search in |
c1 | the first character to search for |
c2 | the second character to search for |
len | the length of the buffer to search in |
- Returns
- a pointer to the first occurrence of either c1 or c2 in buf, or NULL if not found
◆ percent_encode_char()
void percent_encode_char |
( |
char *restrict |
out, |
|
|
char |
c |
|
) |
| |
Writes a percent encoded character to a buffer.
Creates a percent encoded character in the form xx and writes it to out
- Parameters
-
out | the buffer to write to |
c | the character to encode |
◆ strncount()
uint32_t strncount |
( |
const char *restrict |
str, |
|
|
char |
c, |
|
|
size_t |
len |
|
) |
| |
Counts the number of occurrences of c in str.
- Parameters
-
str | the string to search in |
c | the character to search for |
len | the length of the string to search in |
- Returns
- the number of occurrences of c in str
◆ strtok_ri()
int strtok_ri |
( |
const char *restrict |
str, |
|
|
char |
delim, |
|
|
Py_ssize_t *restrict |
strLen, |
|
|
occurrence_t *restrict |
lastoccurrence |
|
) |
| |
Version of strtok_r that doesn't modify the original string.
A reentrant inplace string tokenizer. A custom type is used to store the last occurrence of the token. Both strLen and lastoccurrence are modified by this function
- Parameters
-
str | the string to tokenize, may be NULL in which case the last occurrence is used |
delim | the delimiter to use |
strLen | the length of the string to tokenize, will be decremented by the length of the token found. So it will reflect the remaining length of the string after the token |
lastoccurrence | a struct that holds the last occurrence of the token. Cannot be NULL |
- Returns
- -1 on error, 0 on break, 1 on success