|
| char * | qstrtrim (char *str) |
| | Remove whitespace, including CR and LF, from both ends of a string.
|
| char * | qstrtrim_head (char *str) |
| | Remove leading whitespace from a string.
|
| char * | qstrtrim_tail (char *str) |
| | Remove trailing whitespace, including CR and LF, from a string.
|
| char * | qstrunchar (char *str, char head, char tail) |
| | Remove matching characters from the start and end of a string.
|
| char * | qstrreplace (const char *mode, char *srcstr, const char *tokstr, const char *word) |
| | Replace tokens or strings in a source string using the given mode.
|
| char * | qstrcpy (char *dst, size_t size, const char *src) |
| | Copy src string to dst.
|
| char * | qstrncpy (char *dst, size_t size, const char *src, size_t nbytes) |
| | Copy src string to dst no more than n bytes.
|
| char * | qstrdupf (const char *format,...) |
| | Duplicate a formatted string.
|
| char * | qstrdup_between (const char *str, const char *start, const char *end) |
| | Duplicate a substring between two markers.
|
| void * | qmemdup (const void *data, size_t size) |
| | Duplicate a block of memory.
|
| char * | qstrcatf (char *str, const char *format,...) |
| | Append formatted text to the end of a string.
|
| char * | qstrgets (char *buf, size_t size, char **offset) |
| | Read one line from a string.
|
| char * | qstrrev (char *str) |
| | Reverse the order of characters in the string.
|
| char * | qstrupper (char *str) |
| | Convert character to bigger character.
|
| char * | qstrlower (char *str) |
| | Convert character to lower character.
|
| char * | qstrtok (char *str, const char *delimiters, char *retstop, int *offset) |
| | Split a string into tokens.
|
| qlist_t * | qstrtokenizer (const char *str, const char *delimiters) |
| | Tokenize a string.
|
| char * | qstrunique (const char *seed) |
| | Generate a unique ID.
|
| char * | qstr_comma_number (int number) |
| | Convert an integer to a comma-separated string.
|
| bool | qstrtest (int(*testfunc)(int), const char *str) |
| | Test whether a string matches a character rule.
|
| bool | qstr_is_email (const char *email) |
| | Test for an email-address formatted string.
|
| bool | qstr_is_ip4addr (const char *str) |
| | Test for an IPv4 address string.
|
| char * | qstr_conv_encoding (const char *str, const char *fromcode, const char *tocode, float mag) |
| | Convert character encoding.
|
String APIs.
Definition in file qstring.c.
| char * qstrreplace |
( |
const char * | mode, |
|
|
char * | srcstr, |
|
|
const char * | tokstr, |
|
|
const char * | word ) |
Replace tokens or strings in a source string using the given mode.
- Parameters
-
| mode | replace mode |
| srcstr | source string |
| tokstr | token or string to match |
| word | replacement string |
- Returns
- pointer to the result string on success, or NULL on failure.
- Note
- The mode has two characters.
The first character selects how matching works:
- t matches each character in tokstr as a token.
- s matches tokstr as a full string.
The second character selects where the result is stored:
- n returns a newly allocated string.
- r writes the result back into srcstr.
When r is used, srcstr must have enough space for the result, and it must point to writable memory.
Supported modes:
- tn : token replace, return a new string
- tr : token replace, update srcstr
- sn : string replace, return a new string
- sr : string replace, update srcstr
char srcstr[256], *retstr;
char mode[4][2+1] = {"tn", "tr", "sn", "sr"};
for (i = 0; i < 4; i++) {
strcpy(srcstr, "Welcome to The qDecoder Project.");
printf("before %s : srcstr = %s\n", mode[i], srcstr);
printf("after %s : srcstr = %s\n", mode[i], srcstr);
printf(" retstr = %s\n\n", retstr);
if (mode[i][1] == 'n') free(retstr);
}
char * qstrreplace(const char *mode, char *srcstr, const char *tokstr, const char *word)
Replace tokens or strings in a source string using the given mode.
Definition at line 209 of file qstring.c.