NeoMutt  2020-08-07-1-gab41a1
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_STRING_H
29 #define MUTT_LIB_STRING_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 (*c == 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 **p);
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_atoi(const char *str, int *dst);
60 int mutt_str_atol(const char *str, long *dst);
61 int mutt_str_atos(const char *str, short *dst);
62 int mutt_str_atoui(const char *str, unsigned int *dst);
63 int mutt_str_atoul(const char *str, unsigned long *dst);
64 int mutt_str_atoull(const char *str, unsigned long long *dst);
65 int mutt_str_coll(const char *a, const char *b);
66 void mutt_str_dequote_comment(char *s);
67 const char *mutt_str_find_word(const char *src);
68 const char *mutt_str_getenv(const char *name);
69 bool mutt_str_inline_replace(char *buf, size_t buflen, size_t xlen, const char *rstr);
70 bool mutt_str_is_ascii(const char *str, size_t len);
71 bool mutt_str_is_email_wsp(char c);
72 size_t mutt_str_len(const char *a);
73 char * mutt_str_lower(char *s);
74 size_t mutt_str_lws_len(const char *s, size_t n);
75 size_t mutt_str_lws_rlen(const char *s, size_t n);
76 const char *mutt_str_next_word(const char *s);
77 void mutt_str_remove_trailing_ws(char *s);
78 char * mutt_str_replace(char **p, const char *s);
79 char * mutt_str_skip_email_wsp(const char *s);
80 char * mutt_str_skip_whitespace(const char *p);
81 const char *mutt_str_sysexit(int e);
82 
83 /* case-sensitive flavours */
84 char * mutt_str_cat(char *buf, size_t buflen, const char *s);
85 int mutt_str_cmp(const char *a, const char *b);
86 size_t mutt_str_copy(char *dest, const char *src, size_t dsize);
87 char * mutt_str_dup(const char *str);
88 bool mutt_str_equal(const char *a, const char *b);
89 size_t mutt_str_startswith(const char *str, const char *prefix);
90 
91 /* case-sensitive, length-bound flavours */
92 char * mutt_strn_cat(char *dest, size_t l, const char *s, size_t sl);
93 char * mutt_strn_copy(char *dest, const char *src, size_t len, size_t dsize);
94 char * mutt_strn_dup(const char *begin, size_t l);
95 bool mutt_strn_equal(const char *a, const char *b, size_t l);
96 const char *mutt_strn_rfind(const char *haystack, size_t haystack_length, const char *needle);
97 
98 /* case-insensitive flavours */
99 int mutt_istr_cmp(const char *a, const char *b);
100 bool mutt_istr_equal(const char *a, const char *b);
101 const char *mutt_istr_find(const char *haystack, const char *needle);
102 int mutt_istr_remall(char *str, const char *target);
103 size_t mutt_istr_startswith(const char *str, const char *prefix);
104 
105 /* case-insensitive, length-bound flavours */
106 int mutt_istrn_cmp(const char *a, const char *b, size_t l);
107 bool mutt_istrn_equal(const char *a, const char *b, size_t l);
108 
109 #endif /* MUTT_LIB_STRING_H */
const char * mutt_str_next_word(const char *s)
Find the next word in a string.
Definition: string.c:903
const char * mutt_str_sysexit(int e)
Return a string matching an error code.
Definition: string.c:117
int mutt_istrn_cmp(const char *a, const char *b, size_t l)
Compare two strings ignoring case (to a maximum), safely.
Definition: string.c:612
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:721
static int const char * fmt
Definition: acutest.h:488
const char * mutt_istr_find(const char *haystack, const char *needle)
Find first occurrence of string (ignoring case)
Definition: string.c:661
bool mutt_str_is_email_wsp(char c)
Is this a whitespace character (for an email header)
Definition: string.c:764
void mutt_str_remove_trailing_ws(char *s)
Trim trailing whitespace from a string.
Definition: string.c:705
int mutt_str_atol(const char *str, long *dst)
Convert ASCII string to a long.
Definition: string.c:193
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:177
int mutt_str_asprintf(char **strp, const char *fmt,...)
Definition: string.c:1100
int mutt_str_coll(const char *a, const char *b)
Collate two strings (compare using locale), safely.
Definition: string.c:649
bool mutt_strn_equal(const char *a, const char *b, size_t l)
Check for equality of two strings (to a maximum), safely.
Definition: string.c:598
char * mutt_str_cat(char *buf, size_t buflen, const char *s)
Concatenate two strings.
Definition: string.c:390
int mutt_istr_remall(char *str, const char *target)
Remove all occurrences of substring, ignoring case.
Definition: string.c:1042
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:876
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:375
int mutt_str_cmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:572
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:888
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:165
bool mutt_str_is_ascii(const char *str, size_t len)
Is a string ASCII (7-bit)?
Definition: string.c:953
int mutt_str_atoi(const char *str, int *dst)
Convert ASCII string to an integer.
Definition: string.c:257
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:451
char * mutt_str_skip_whitespace(const char *p)
Find the first non-whitespace character in a string.
Definition: string.c:691
int mutt_str_atoull(const char *str, unsigned long long *dst)
Convert ASCII string to an unsigned long long.
Definition: string.c:348
char * mutt_strn_dup(const char *begin, size_t l)
Duplicate a sub-string.
Definition: string.c:553
char * mutt_str_skip_email_wsp(const char *s)
Skip over whitespace as defined by RFC5322.
Definition: string.c:748
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:778
void mutt_str_adjust(char **p)
Shrink-to-fit a string.
Definition: string.c:495
bool mutt_istrn_equal(const char *a, const char *b, size_t l)
Check for equality of two strings ignoring case (to a maximum), safely.
Definition: string.c:626
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:533
void mutt_str_append_item(char **str, const char *item, char sep)
Add string to another separated by sep.
Definition: string.c:471
int n
Definition: acutest.h:492
int mutt_istr_cmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:585
char * mutt_strn_cat(char *dest, size_t l, const char *s, size_t sl)
Concatenate two strings.
Definition: string.c:419
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Definition: string.c:996
const char * mutt_str_find_word(const char *src)
Find the end of a word (non-space)
Definition: string.c:976
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:636
int mutt_str_atoul(const char *str, unsigned long *dst)
Convert ASCII string to an unsigned long.
Definition: string.c:316
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:812
int mutt_str_atoui(const char *str, unsigned int *dst)
Convert ASCII string to an unsigned integer.
Definition: string.c:287
int mutt_str_atos(const char *str, short *dst)
Convert ASCII string to a short.
Definition: string.c:227
char * mutt_str_lower(char *s)
Convert all characters in the string to lowercase.
Definition: string.c:509
void mutt_str_dequote_comment(char *s)
Un-escape characters in an email address comment.
Definition: string.c:844
const char * mutt_strn_rfind(const char *haystack, size_t haystack_length, const char *needle)
Find last instance of a substring.
Definition: string.c:925
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:1018