NeoMutt  2019-12-07
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 #define EMAIL_WSP " \t\r\n"
40 
41 /* Exit values */
42 #define S_ERR 127
43 #define S_BKG 126
44 
45 /* this macro must check for (*c == 0) since isspace(0) has unreliable behavior
46  * on some systems */
47 #define SKIPWS(ch) \
48  while (*(ch) && isspace((unsigned char) *(ch))) \
49  ch++;
50 
51 #define terminate_string(str, strlen, buflen) \
52  do \
53  { \
54  if ((strlen) < (buflen)) \
55  str[(strlen)] = '\0'; \
56  else \
57  str[(buflen)] = '\0'; \
58  } while (false)
59 
60 #define terminate_buffer(str, strlen) terminate_string(str, strlen, sizeof(str) - 1)
61 
66 {
69 };
70 
71 void mutt_str_adjust(char **p);
72 void mutt_str_append_item(char **str, const char *item, char sep);
73 int mutt_str_asprintf(char **strp, const char *fmt, ...);
74 int mutt_str_atoi(const char *str, int *dst);
75 int mutt_str_atol(const char *str, long *dst);
76 int mutt_str_atos(const char *str, short *dst);
77 int mutt_str_atoui(const char *str, unsigned int *dst);
78 int mutt_str_atoul(const char *str, unsigned long *dst);
79 int mutt_str_atoull(const char *str, unsigned long long *dst);
80 void mutt_str_dequote_comment(char *s);
81 const char *mutt_str_find_word(const char *src);
82 const char *mutt_str_getenv(const char *name);
83 bool mutt_str_inline_replace(char *buf, size_t buflen, size_t xlen, const char *rstr);
84 bool mutt_str_is_ascii(const char *str, size_t len);
85 bool mutt_str_is_email_wsp(char c);
86 size_t mutt_str_lws_len(const char *s, size_t n);
87 size_t mutt_str_lws_rlen(const char *s, size_t n);
88 const char *mutt_str_next_word(const char *s);
89 int mutt_str_remall_strcasestr(char *str, const char *target);
90 void mutt_str_remove_trailing_ws(char *s);
91 void mutt_str_replace(char **p, const char *s);
92 const char *mutt_str_rstrnstr(const char *haystack, size_t haystack_length, const char *needle);
93 char * mutt_str_skip_email_wsp(const char *s);
94 char * mutt_str_skip_whitespace(const char *p);
95 int mutt_str_strcasecmp(const char *a, const char *b);
96 size_t mutt_str_startswith(const char *str, const char *prefix, enum CaseSensitivity cs);
97 const char *mutt_str_strcasestr(const char *haystack, const char *needle);
98 char * mutt_str_strcat(char *buf, size_t buflen, const char *s);
99 const char *mutt_str_strchrnul(const char *s, char c);
100 int mutt_str_strcmp(const char *a, const char *b);
101 int mutt_str_strcoll(const char *a, const char *b);
102 char * mutt_str_strdup(const char *str);
103 size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize);
104 const char *mutt_str_stristr(const char *haystack, const char *needle);
105 size_t mutt_str_strlen(const char *a);
106 char * mutt_str_strlower(char *s);
107 int mutt_str_strncasecmp(const char *a, const char *b, size_t l);
108 char * mutt_str_strncat(char *d, size_t l, const char *s, size_t sl);
109 int mutt_str_strncmp(const char *a, const char *b, size_t l);
110 size_t mutt_str_strnfcpy(char *dest, const char *src, size_t n, size_t dsize);
111 char * mutt_str_substr_copy(const char *begin, const char *end, char *buf, size_t buflen);
112 char * mutt_str_substr_dup(const char *begin, const char *end);
113 const char *mutt_str_sysexit(int e);
114 int mutt_str_word_casecmp(const char *a, const char *b);
115 
116 #endif /* MUTT_LIB_STRING_H */
const char * mutt_str_next_word(const char *s)
Find the next word in a string.
Definition: string.c:916
const char * mutt_str_sysexit(int e)
Return a string matching an error code.
Definition: string.c:117
int mutt_str_remall_strcasestr(char *str, const char *target)
Remove all occurrences of substring, ignoring case.
Definition: string.c:1094
int mutt_str_strncasecmp(const char *a, const char *b, size_t l)
Compare two strings ignoring case (to a maximum), safely.
Definition: string.c:656
const char * mutt_str_strchrnul(const char *s, char c)
Find first occurrence of character in string.
Definition: string.c:538
CaseSensitivity
Should a string&#39;s case matter when matching?
Definition: string2.h:65
char * mutt_str_substr_dup(const char *begin, const char *end)
Duplicate a sub-string.
Definition: string.c:579
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:628
const char * mutt_str_rstrnstr(const char *haystack, size_t haystack_length, const char *needle)
Find last instance of a substring.
Definition: string.c:938
bool mutt_str_is_email_wsp(char c)
Is this a whitespace character (for an email header)
Definition: string.c:788
void mutt_str_remove_trailing_ws(char *s)
Trim trailing whitespace from a string.
Definition: string.c:734
Match case when comparing strings.
Definition: string2.h:67
int mutt_str_atol(const char *str, long *dst)
Convert ASCII string to a long.
Definition: string.c:198
int mutt_str_asprintf(char **strp, const char *fmt,...)
Definition: string.c:1194
char * mutt_str_substr_copy(const char *begin, const char *end, char *buf, size_t buflen)
Copy a sub-string into a buffer.
Definition: string.c:556
const char * mutt_str_strcasestr(const char *haystack, const char *needle)
Find a substring within a string without worrying about case.
Definition: string.c:1119
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
size_t mutt_str_strnfcpy(char *dest, const char *src, size_t n, size_t dsize)
Copy a limited string into a buffer (guaranteeing NUL-termination)
Definition: string.c:801
const char * name
Definition: pgpmicalg.c:46
char * mutt_str_strncat(char *d, size_t l, const char *s, size_t sl)
Concatenate two strings.
Definition: string.c:424
bool mutt_str_is_ascii(const char *str, size_t len)
Is a string ASCII (7-bit)?
Definition: string.c:1005
int mutt_str_atoi(const char *str, int *dst)
Convert ASCII string to an integer.
Definition: string.c:262
char * mutt_str_skip_whitespace(const char *p)
Find the first non-whitespace character in a string.
Definition: string.c:720
const char * mutt_str_stristr(const char *haystack, const char *needle)
Find first occurrence of string (ignoring case)
Definition: string.c:691
char * mutt_str_strlower(char *s)
convert all characters in the string to lowercase
Definition: string.c:509
int mutt_str_atoull(const char *str, unsigned long long *dst)
Convert ASCII string to an unsigned long long.
Definition: string.c:353
char * mutt_str_skip_email_wsp(const char *s)
Skip over whitespace as defined by RFC5322.
Definition: string.c:776
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:815
void mutt_str_adjust(char **p)
Shrink-to-fit a string.
Definition: string.c:495
int mutt_str_strncmp(const char *a, const char *b, size_t l)
Compare two strings (to a maximum), safely.
Definition: string.c:642
Ignore case when comparing strings.
Definition: string2.h:68
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
int mutt_str_word_casecmp(const char *a, const char *b)
Find word a in word list b.
Definition: string.c:973
void mutt_str_append_item(char **str, const char *item, char sep)
Add string to another separated by sep.
Definition: string.c:471
void mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:453
size_t mutt_str_startswith(const char *str, const char *prefix, enum CaseSensitivity cs)
Check whether a string starts with a prefix.
Definition: string.c:168
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Definition: string.c:1048
const char * mutt_str_find_word(const char *src)
Find the end of a word (non-space)
Definition: string.c:1028
int mutt_str_strcoll(const char *a, const char *b)
Collate two strings (compare using locale), safely.
Definition: string.c:679
int mutt_str_atoul(const char *str, unsigned long *dst)
Convert ASCII string to an unsigned long.
Definition: string.c:321
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:849
int mutt_str_atoui(const char *str, unsigned int *dst)
Convert ASCII string to an unsigned integer.
Definition: string.c:292
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:750
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
int mutt_str_atos(const char *str, short *dst)
Convert ASCII string to a short.
Definition: string.c:232
void mutt_str_dequote_comment(char *s)
Un-escape characters in an email address comment.
Definition: string.c:881
char * mutt_str_strcat(char *buf, size_t buflen, const char *s)
Concatenate two strings.
Definition: string.c:395
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:1070