#include <ctype.h>
#include <stdbool.h>
#include <stdio.h>
Go to the source code of this file.
Macros | |
#define | STR_COMMAND 8192 |
Enough space for a long command line. More... | |
#define | NONULL(x) ((x) ? (x) : "") |
#define | IS_SPACE(ch) isspace((unsigned char) ch) |
#define | S_ERR 127 |
#define | S_BKG 126 |
#define | SKIPWS(ch) |
#define | terminate_string(str, strlen, buflen) (str)[MIN((strlen), (buflen))] = '\0' |
#define | terminate_buffer(str, strlen) terminate_string(str, strlen, sizeof(str) - 1) |
Functions | |
void | mutt_str_adjust (char **ptr) |
Shrink-to-fit a string. More... | |
void | mutt_str_append_item (char **str, const char *item, char sep) |
Add string to another separated by sep. More... | |
int | mutt_str_asprintf (char **strp, const char *fmt,...) |
int | mutt_str_atoi (const char *str, int *dst) |
Convert ASCII string to an integer. More... | |
int | mutt_str_atol (const char *str, long *dst) |
Convert ASCII string to a long. More... | |
int | mutt_str_atos (const char *str, short *dst) |
Convert ASCII string to a short. More... | |
int | mutt_str_atoui (const char *str, unsigned int *dst) |
Convert ASCII string to an unsigned integer. More... | |
int | mutt_str_atoul (const char *str, unsigned long *dst) |
Convert ASCII string to an unsigned long. More... | |
int | mutt_str_atoull (const char *str, unsigned long long *dst) |
Convert ASCII string to an unsigned long long. More... | |
int | mutt_str_coll (const char *a, const char *b) |
Collate two strings (compare using locale), safely. More... | |
void | mutt_str_dequote_comment (char *str) |
Un-escape characters in an email address comment. More... | |
const char * | mutt_str_find_word (const char *src) |
Find the end of a word (non-space) More... | |
const char * | mutt_str_getenv (const char *name) |
Get an environment variable. More... | |
bool | mutt_str_inline_replace (char *buf, size_t buflen, size_t xlen, const char *rstr) |
Replace the beginning of a string. More... | |
bool | mutt_str_is_ascii (const char *str, size_t len) |
Is a string ASCII (7-bit)? More... | |
bool | mutt_str_is_email_wsp (char c) |
Is this a whitespace character (for an email header) More... | |
size_t | mutt_str_len (const char *a) |
Calculate the length of a string, safely. More... | |
char * | mutt_str_lower (char *str) |
Convert all characters in the string to lowercase. More... | |
size_t | mutt_str_lws_len (const char *s, size_t n) |
Measure the linear-white-space at the beginning of a string. More... | |
size_t | mutt_str_lws_rlen (const char *s, size_t n) |
Measure the linear-white-space at the end of a string. More... | |
const char * | mutt_str_next_word (const char *s) |
Find the next word in a string. More... | |
void | mutt_str_remove_trailing_ws (char *s) |
Trim trailing whitespace from a string. More... | |
char * | mutt_str_replace (char **p, const char *s) |
Replace one string with another. More... | |
char * | mutt_str_skip_email_wsp (const char *s) |
Skip over whitespace as defined by RFC5322. More... | |
char * | mutt_str_skip_whitespace (const char *p) |
Find the first non-whitespace character in a string. More... | |
const char * | mutt_str_sysexit (int e) |
Return a string matching an error code. More... | |
char * | mutt_str_cat (char *buf, size_t buflen, const char *s) |
Concatenate two strings. More... | |
int | mutt_str_cmp (const char *a, const char *b) |
Compare two strings, safely. More... | |
size_t | mutt_str_copy (char *dest, const char *src, size_t dsize) |
Copy a string into a buffer (guaranteeing NUL-termination) More... | |
char * | mutt_str_dup (const char *str) |
Copy a string, safely. More... | |
bool | mutt_str_equal (const char *a, const char *b) |
Compare two strings. More... | |
size_t | mutt_str_startswith (const char *str, const char *prefix) |
Check whether a string starts with a prefix. More... | |
char * | mutt_strn_cat (char *dest, size_t l, const char *s, size_t sl) |
Concatenate two strings. More... | |
char * | mutt_strn_copy (char *dest, const char *src, size_t len, size_t dsize) |
Copy a sub-string into a buffer. More... | |
char * | mutt_strn_dup (const char *begin, size_t l) |
Duplicate a sub-string. More... | |
bool | mutt_strn_equal (const char *a, const char *b, size_t num) |
Check for equality of two strings (to a maximum), safely. More... | |
const char * | mutt_strn_rfind (const char *haystack, size_t haystack_length, const char *needle) |
Find last instance of a substring. More... | |
int | mutt_istr_cmp (const char *a, const char *b) |
Compare two strings ignoring case, safely. More... | |
bool | mutt_istr_equal (const char *a, const char *b) |
Compare two strings, ignoring case. More... | |
const char * | mutt_istr_find (const char *haystack, const char *needle) |
Find first occurrence of string (ignoring case) More... | |
int | mutt_istr_remall (char *str, const char *target) |
Remove all occurrences of substring, ignoring case. More... | |
size_t | mutt_istr_startswith (const char *str, const char *prefix) |
Check whether a string starts with a prefix, ignoring case. More... | |
int | mutt_istrn_cmp (const char *a, const char *b, size_t num) |
Compare two strings ignoring case (to a maximum), safely. More... | |
bool | mutt_istrn_equal (const char *a, const char *b, size_t num) |
Check for equality of two strings ignoring case (to a maximum), safely. More... | |
String manipulation functions
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Definition in file string2.h.
#define STR_COMMAND 8192 |
#define SKIPWS | ( | ch | ) |
#define terminate_string | ( | str, | |
strlen, | |||
buflen | |||
) | (str)[MIN((strlen), (buflen))] = '\0' |
#define terminate_buffer | ( | str, | |
strlen | |||
) | terminate_string(str, strlen, sizeof(str) - 1) |
void mutt_str_adjust | ( | char ** | ptr | ) |
Shrink-to-fit a string.
[out] | ptr | String to alter |
Take a string which is allocated on the heap, find its length and reallocate the memory to be exactly the right size.
This function alters the pointer of the caller.
Definition at line 490 of file string.c.
void mutt_str_append_item | ( | char ** | str, |
const char * | item, | ||
char | sep | ||
) |
Add string to another separated by sep.
[out] | str | String appended |
[in] | item | String to append |
[in] | sep | separator between string item |
Append a string to another, separating them by sep if needed.
This function alters the pointer of the caller.
Definition at line 466 of file string.c.
int mutt_str_asprintf | ( | char ** | strp, |
const char * | fmt, | ||
... | |||
) |
int mutt_str_atoi | ( | const char * | str, |
int * | dst | ||
) |
Convert ASCII string to an integer.
[in] | str | String to read |
[out] | dst | Store the result |
0 | Success |
-1 | Error |
-2 | Error, overflow |
This is a strtol() wrapper with range checking. If dst is NULL, the string will be tested only (without conversion). errno may be set on error, e.g. ERANGE
Definition at line 252 of file string.c.
int mutt_str_atol | ( | const char * | str, |
long * | dst | ||
) |
Convert ASCII string to a long.
[in] | str | String to read |
[out] | dst | Store the result |
0 | Success |
-1 | Error |
-2 | Overflow |
This is a strtol() wrapper with range checking. errno may be set on error, e.g. ERANGE
Definition at line 188 of file string.c.
int mutt_str_atos | ( | const char * | str, |
short * | dst | ||
) |
Convert ASCII string to a short.
[in] | str | String to read |
[out] | dst | Store the result |
0 | Success |
-1 | Error |
-2 | Error, overflow |
This is a strtol() wrapper with range checking. If dst is NULL, the string will be tested only (without conversion).
errno may be set on error, e.g. ERANGE
Definition at line 222 of file string.c.
int mutt_str_atoui | ( | const char * | str, |
unsigned int * | dst | ||
) |
Convert ASCII string to an unsigned integer.
[in] | str | String to read |
[out] | dst | Store the result |
1 | Successful conversion, with trailing characters |
0 | Successful conversion |
-1 | Invalid input |
-2 | Input out of range |
Definition at line 282 of file string.c.
int mutt_str_atoul | ( | const char * | str, |
unsigned long * | dst | ||
) |
Convert ASCII string to an unsigned long.
[in] | str | String to read |
[out] | dst | Store the result |
1 | Successful conversion, with trailing characters |
0 | Successful conversion |
-1 | Invalid input |
Definition at line 311 of file string.c.
int mutt_str_atoull | ( | const char * | str, |
unsigned long long * | dst | ||
) |
Convert ASCII string to an unsigned long long.
[in] | str | String to read |
[out] | dst | Store the result |
1 | Successful conversion, with trailing characters |
0 | Successful conversion |
-1 | Invalid input |
Definition at line 343 of file string.c.
int mutt_str_coll | ( | const char * | a, |
const char * | b | ||
) |
void mutt_str_dequote_comment | ( | char * | str | ) |
const char* mutt_str_find_word | ( | const char * | src | ) |
Find the end of a word (non-space)
src | String to search |
ptr | End of the word |
Skip to the end of the current word. Skip past any whitespace characters.
Definition at line 971 of file string.c.
const char* mutt_str_getenv | ( | const char * | name | ) |
bool mutt_str_inline_replace | ( | char * | buf, |
size_t | buflen, | ||
size_t | xlen, | ||
const char * | rstr | ||
) |
Replace the beginning of a string.
buf | Buffer to modify |
buflen | Length of buffer |
xlen | Length of string to overwrite |
rstr | Replacement string |
true | Success |
String (XX<OOOOOO>......
, 16, 2, RRRR
) becomes RRRR<OOOOOO>....
Definition at line 1013 of file string.c.
bool mutt_str_is_ascii | ( | const char * | str, |
size_t | len | ||
) |
bool mutt_str_is_email_wsp | ( | char | c | ) |
size_t mutt_str_len | ( | const char * | a | ) |
char* mutt_str_lower | ( | char * | str | ) |
size_t mutt_str_lws_len | ( | const char * | s, |
size_t | n | ||
) |
Measure the linear-white-space at the beginning of a string.
s | String to check |
n | Maximum number of characters to check |
num | Count of whitespace characters |
Count the number of whitespace characters at the beginning of a string. They can be <space>
, <tab>
, <cr>
or <lf>
.
Definition at line 773 of file string.c.
size_t mutt_str_lws_rlen | ( | const char * | s, |
size_t | n | ||
) |
Measure the linear-white-space at the end of a string.
s | String to check |
n | Maximum number of characters to check |
num | Count of whitespace characters |
Count the number of whitespace characters at the end of a string. They can be <space>
, <tab>
, <cr>
or <lf>
.
Definition at line 807 of file string.c.
const char* mutt_str_next_word | ( | const char * | s | ) |
Find the next word in a string.
s | String to examine |
ptr | Next word |
If the s is pointing to a word (non-space) is is skipped over. Then, any whitespace is skipped over.
void mutt_str_remove_trailing_ws | ( | char * | s | ) |
char* mutt_str_replace | ( | char ** | p, |
const char * | s | ||
) |
Replace one string with another.
[out] | p | String to replace |
[in] | s | New string |
ptr | Replaced string |
This function free()s the original string, strdup()s the new string and overwrites the pointer to the first string.
This function alters the pointer of the caller.
Definition at line 446 of file string.c.
char* mutt_str_skip_email_wsp | ( | const char * | s | ) |
Skip over whitespace as defined by RFC5322.
s | String to search |
ptr |
|
This is used primarily for parsing header fields.
Definition at line 743 of file string.c.
char* mutt_str_skip_whitespace | ( | const char * | p | ) |
const char* mutt_str_sysexit | ( | int | err_num | ) |
char* mutt_str_cat | ( | char * | buf, |
size_t | buflen, | ||
const char * | s | ||
) |
int mutt_str_cmp | ( | const char * | a, |
const char * | b | ||
) |
size_t mutt_str_copy | ( | char * | dest, |
const char * | src, | ||
size_t | dsize | ||
) |
Copy a string into a buffer (guaranteeing NUL-termination)
dest | Buffer for the result |
src | String to copy |
dsize | Destination buffer size |
num | Destination string length |
char* mutt_str_dup | ( | const char * | str | ) |
bool mutt_str_equal | ( | const char * | a, |
const char * | b | ||
) |
size_t mutt_str_startswith | ( | const char * | str, |
const char * | prefix | ||
) |
char* mutt_strn_cat | ( | char * | d, |
size_t | l, | ||
const char * | s, | ||
size_t | sl | ||
) |
char* mutt_strn_copy | ( | char * | dest, |
const char * | src, | ||
size_t | len, | ||
size_t | dsize | ||
) |
char* mutt_strn_dup | ( | const char * | begin, |
size_t | len | ||
) |
bool mutt_strn_equal | ( | const char * | a, |
const char * | b, | ||
size_t | num | ||
) |
Check for equality of two strings (to a maximum), safely.
a | First string to compare |
b | Second string to compare |
num | Maximum number of bytes to compare |
true | First num chars of both strings are equal |
false | First num chars of both strings not equal |
Definition at line 593 of file string.c.
const char* mutt_strn_rfind | ( | const char * | haystack, |
size_t | haystack_length, | ||
const char * | needle | ||
) |
Find last instance of a substring.
haystack | String to search through |
haystack_length | Length of the string |
needle | String to find |
NULL | String not found |
ptr | Location of string |
Return the last instance of needle in the haystack, or NULL. Like strstr(), only backwards, and for a limited haystack length.
Definition at line 920 of file string.c.
int mutt_istr_cmp | ( | const char * | a, |
const char * | b | ||
) |
bool mutt_istr_equal | ( | const char * | a, |
const char * | b | ||
) |
const char* mutt_istr_find | ( | const char * | haystack, |
const char * | needle | ||
) |
int mutt_istr_remall | ( | char * | str, |
const char * | target | ||
) |
Remove all occurrences of substring, ignoring case.
str | String containing the substring |
target | Target substring for removal |
0 | String contained substring and substring was removed successfully |
1 | String did not contain substring |
Definition at line 1037 of file string.c.
size_t mutt_istr_startswith | ( | const char * | str, |
const char * | prefix | ||
) |
int mutt_istrn_cmp | ( | const char * | a, |
const char * | b, | ||
size_t | num | ||
) |
Compare two strings ignoring case (to a maximum), safely.
a | First string to compare |
b | Second string to compare |
num | Maximum number of bytes to compare |
-1 | a precedes b |
0 | a and b are identical |
1 | b precedes a |
Definition at line 607 of file string.c.
bool mutt_istrn_equal | ( | const char * | a, |
const char * | b, | ||
size_t | num | ||
) |
Check for equality of two strings ignoring case (to a maximum), safely.
a | First string to compare |
b | Second string to compare |
num | Maximum number of bytes to compare |
-1 | a precedes b |
true | First num chars of both strings are equal, ignoring case |
false | First num chars of both strings not equal, ignoring case |
Definition at line 621 of file string.c.