NeoMutt  2022-04-29-81-g9c5a59
Teaching an old dog new tricks
DOXYGEN
string2.h
Go to the documentation of this file.
1 
24 /* @note This file is called string2.h so that other files can safely
25  * #include <string.h>
26  */
27 
28 #ifndef MUTT_LIB_STRING2_H
29 #define MUTT_LIB_STRING2_H
30 
31 #include <ctype.h>
32 #include <stdbool.h>
33 #include <stdio.h>
34 
35 #define STR_COMMAND 8192
36 
37 #define NONULL(x) ((x) ? (x) : "")
38 #define IS_SPACE(ch) isspace((unsigned char) ch)
39 
40 /* Exit values */
41 #define S_ERR 127
42 #define S_BKG 126
43 
44 /* this macro must check for (*ch == 0) since isspace(0) has unreliable behavior
45  * on some systems */
46 #define SKIPWS(ch) \
47  while (*(ch) && isspace((unsigned char) *(ch))) \
48  ch++;
49 
50 #define terminate_string(str, strlen, buflen) \
51  (str)[MIN((strlen), (buflen))] = '\0'
52 
53 #define terminate_buffer(str, strlen) \
54  terminate_string(str, strlen, sizeof(str) - 1)
55 
56 void mutt_str_adjust(char **ptr);
57 void mutt_str_append_item(char **str, const char *item, char sep);
58 int mutt_str_asprintf(char **strp, const char *fmt, ...);
59 int mutt_str_coll(const char *a, const char *b);
60 void mutt_str_dequote_comment(char *str);
61 const char *mutt_str_find_word(const char *src);
62 const char *mutt_str_getenv(const char *name);
63 bool mutt_str_inline_replace(char *buf, size_t buflen, size_t xlen, const char *rstr);
64 bool mutt_str_is_ascii(const char *str, size_t len);
65 bool mutt_str_is_email_wsp(char c);
66 size_t mutt_str_len(const char *a);
67 char * mutt_str_lower(char *str);
68 size_t mutt_str_lws_len(const char *s, size_t n);
69 size_t mutt_str_lws_rlen(const char *s, size_t n);
70 const char *mutt_str_next_word(const char *s);
71 void mutt_str_remove_trailing_ws(char *s);
72 char * mutt_str_replace(char **p, const char *s);
73 char * mutt_str_sep(char **stringp, const char *delim);
74 char * mutt_str_skip_email_wsp(const char *s);
75 char * mutt_str_skip_whitespace(const char *p);
76 const char *mutt_str_sysexit(int e);
77 
78 /* case-sensitive flavours */
79 char * mutt_str_cat(char *buf, size_t buflen, const char *s);
80 int mutt_str_cmp(const char *a, const char *b);
81 size_t mutt_str_copy(char *dest, const char *src, size_t dsize);
82 char * mutt_str_dup(const char *str);
83 bool mutt_str_equal(const char *a, const char *b);
84 size_t mutt_str_startswith(const char *str, const char *prefix);
85 
86 /* case-sensitive, length-bound flavours */
87 char * mutt_strn_cat(char *dest, size_t l, const char *s, size_t sl);
88 char * mutt_strn_copy(char *dest, const char *src, size_t len, size_t dsize);
89 char * mutt_strn_dup(const char *begin, size_t l);
90 bool mutt_strn_equal(const char *a, const char *b, size_t num);
91 const char *mutt_strn_rfind(const char *haystack, size_t haystack_length, const char *needle);
92 
93 /* case-insensitive flavours */
94 int mutt_istr_cmp(const char *a, const char *b);
95 bool mutt_istr_equal(const char *a, const char *b);
96 const char *mutt_istr_find(const char *haystack, const char *needle);
97 int mutt_istr_remall(char *str, const char *target);
98 size_t mutt_istr_startswith(const char *str, const char *prefix);
99 
100 /* case-insensitive, length-bound flavours */
101 int mutt_istrn_cmp(const char *a, const char *b, size_t num);
102 bool mutt_istrn_equal(const char *a, const char *b, size_t num);
103 const char *mutt_istrn_rfind(const char *haystack, size_t haystack_length, const char *needle);
104 
105 #endif /* MUTT_LIB_STRING2_H */
bool mutt_str_inline_replace(char *buf, size_t buflen, size_t xlen, const char *rstr)
Replace the beginning of a string.
Definition: string.c:926
int mutt_str_cmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:447
int mutt_istrn_cmp(const char *a, const char *b, size_t num)
Compare two strings ignoring case (to a maximum), safely.
Definition: string.c:487
const char * mutt_str_sysexit(int e)
Return a string matching an error code.
Definition: string.c:166
void mutt_str_remove_trailing_ws(char *s)
Trim trailing whitespace from a string.
Definition: string.c:613
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:796
const char * mutt_str_find_word(const char *src)
Find the end of a word (non-space)
Definition: string.c:884
void mutt_str_dequote_comment(char *str)
Un-escape characters in an email address comment.
Definition: string.c:752
int mutt_str_asprintf(char **strp, const char *fmt,...)
Definition: string.c:1008
const char * mutt_istr_find(const char *haystack, const char *needle)
Find first occurrence of string (ignoring case)
Definition: string.c:569
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:250
size_t mutt_str_lws_len(const char *s, size_t n)
Measure the linear-white-space at the beginning of a string.
Definition: string.c:686
bool mutt_str_is_ascii(const char *str, size_t len)
Is a string ASCII (7-bit)?
Definition: string.c:861
void mutt_str_append_item(char **str, const char *item, char sep)
Add string to another separated by sep.
Definition: string.c:346
const char * mutt_istrn_rfind(const char *haystack, size_t haystack_length, const char *needle)
Find last instance of a substring, ignoring case.
Definition: string.c:517
int mutt_istr_cmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:460
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:784
char * mutt_strn_copy(char *dest, const char *src, size_t len, size_t dsize)
Copy a sub-string into a buffer.
Definition: string.c:408
bool mutt_strn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings (to a maximum), safely.
Definition: string.c:473
char * mutt_str_skip_whitespace(const char *p)
Find the first non-whitespace character in a string.
Definition: string.c:599
const char * mutt_str_next_word(const char *s)
Find the next word in a string.
Definition: string.c:811
int mutt_istr_remall(char *str, const char *target)
Remove all occurrences of substring, ignoring case.
Definition: string.c:950
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:227
void mutt_str_adjust(char **ptr)
Shrink-to-fit a string.
Definition: string.c:370
char * mutt_str_skip_email_wsp(const char *s)
Skip over whitespace as defined by RFC5322.
Definition: string.c:656
bool mutt_str_is_email_wsp(char c)
Is this a whitespace character (for an email header)
Definition: string.c:672
char * mutt_strn_dup(const char *begin, size_t l)
Duplicate a sub-string.
Definition: string.c:428
char * mutt_strn_cat(char *dest, size_t l, const char *s, size_t sl)
Concatenate two strings.
Definition: string.c:294
char * mutt_str_lower(char *str)
Convert all characters in the string to lowercase.
Definition: string.c:384
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:544
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Definition: string.c:904
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:629
char * mutt_str_cat(char *buf, size_t buflen, const char *s)
Concatenate two strings.
Definition: string.c:265
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:326
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:239
const char * mutt_strn_rfind(const char *haystack, size_t haystack_length, const char *needle)
Find last instance of a substring.
Definition: string.c:833
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.
Definition: string.c:501
char * mutt_str_sep(char **stringp, const char *delim)
Find first occurance of any of delim characters in *stringp.
Definition: string.c:183
size_t mutt_str_lws_rlen(const char *s, size_t n)
Measure the linear-white-space at the end of a string.
Definition: string.c:720
int mutt_str_coll(const char *a, const char *b)
Collate two strings (compare using locale), safely.
Definition: string.c:557