NeoMutt  2022-04-29-215-gc12b98
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
56void mutt_str_adjust(char **ptr);
57void mutt_str_append_item(char **str, const char *item, char sep);
58int mutt_str_asprintf(char **strp, const char *fmt, ...);
59int mutt_str_coll(const char *a, const char *b);
60void mutt_str_dequote_comment(char *str);
61const char *mutt_str_find_word(const char *src);
62const char *mutt_str_getenv(const char *name);
63bool mutt_str_inline_replace(char *buf, size_t buflen, size_t xlen, const char *rstr);
64bool mutt_str_is_ascii(const char *str, size_t len);
65bool mutt_str_is_email_wsp(char c);
66size_t mutt_str_len(const char *a);
67char * mutt_str_lower(char *str);
68size_t mutt_str_lws_len(const char *s, size_t n);
69size_t mutt_str_lws_rlen(const char *s, size_t n);
70const char *mutt_str_next_word(const char *s);
71void mutt_str_remove_trailing_ws(char *s);
72char * mutt_str_replace(char **p, const char *s);
73char * mutt_str_sep(char **stringp, const char *delim);
74char * mutt_str_skip_email_wsp(const char *s);
75char * mutt_str_skip_whitespace(const char *p);
76const char *mutt_str_sysexit(int e);
77char * mutt_str_upper(char *str);
78
79/* case-sensitive flavours */
80char * mutt_str_cat(char *buf, size_t buflen, const char *s);
81int mutt_str_cmp(const char *a, const char *b);
82size_t mutt_str_copy(char *dest, const char *src, size_t dsize);
83char * mutt_str_dup(const char *str);
84bool mutt_str_equal(const char *a, const char *b);
85size_t mutt_str_startswith(const char *str, const char *prefix);
86
87/* case-sensitive, length-bound flavours */
88char * mutt_strn_cat(char *dest, size_t l, const char *s, size_t sl);
89char * mutt_strn_copy(char *dest, const char *src, size_t len, size_t dsize);
90char * mutt_strn_dup(const char *begin, size_t l);
91bool mutt_strn_equal(const char *a, const char *b, size_t num);
92const char *mutt_strn_rfind(const char *haystack, size_t haystack_length, const char *needle);
93
94/* case-insensitive flavours */
95int mutt_istr_cmp(const char *a, const char *b);
96bool mutt_istr_equal(const char *a, const char *b);
97const char *mutt_istr_find(const char *haystack, const char *needle);
98int mutt_istr_remall(char *str, const char *target);
99size_t mutt_istr_startswith(const char *str, const char *prefix);
100
101/* case-insensitive, length-bound flavours */
102int mutt_istrn_cmp(const char *a, const char *b, size_t num);
103bool mutt_istrn_equal(const char *a, const char *b, size_t num);
104const char *mutt_istrn_rfind(const char *haystack, size_t haystack_length, const char *needle);
105
106#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:949
const char * mutt_str_sysexit(int e)
Return a string matching an error code.
Definition: string.c:166
int mutt_str_cmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:470
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:510
void mutt_str_remove_trailing_ws(char *s)
Trim trailing whitespace from a string.
Definition: string.c:636
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:819
void mutt_str_dequote_comment(char *str)
Un-escape characters in an email address comment.
Definition: string.c:775
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:250
int mutt_str_asprintf(char **strp, const char *fmt,...)
Definition: string.c:1031
char * mutt_str_upper(char *str)
Convert all characters in the string to uppercase.
Definition: string.c:407
char * mutt_str_lower(char *str)
Convert all characters in the string to lowercase.
Definition: string.c:384
char * mutt_str_skip_email_wsp(const char *s)
Skip over whitespace as defined by RFC5322.
Definition: string.c:679
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:540
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:709
bool mutt_str_is_ascii(const char *str, size_t len)
Is a string ASCII (7-bit)?
Definition: string.c:884
void mutt_str_append_item(char **str, const char *item, char sep)
Add string to another separated by sep.
Definition: string.c:346
int mutt_istr_cmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:483
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:807
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:496
char * mutt_strn_dup(const char *begin, size_t l)
Duplicate a sub-string.
Definition: string.c:451
char * mutt_strn_cat(char *dest, size_t l, const char *s, size_t sl)
Concatenate two strings.
Definition: string.c:294
const char * mutt_str_find_word(const char *src)
Find the end of a word (non-space)
Definition: string.c:907
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:431
int mutt_istr_remall(char *str, const char *target)
Remove all occurrences of substring, ignoring case.
Definition: string.c:973
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Definition: string.c:927
const char * mutt_istr_find(const char *haystack, const char *needle)
Find first occurrence of string (ignoring case)
Definition: string.c:592
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:227
char * mutt_str_skip_whitespace(const char *p)
Find the first non-whitespace character in a string.
Definition: string.c:622
void mutt_str_adjust(char **ptr)
Shrink-to-fit a string.
Definition: string.c:370
bool mutt_str_is_email_wsp(char c)
Is this a whitespace character (for an email header)
Definition: string.c:695
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:567
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:652
const char * mutt_str_next_word(const char *s)
Find the next word in a string.
Definition: string.c:834
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
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:524
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:326
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:743
const char * mutt_strn_rfind(const char *haystack, size_t haystack_length, const char *needle)
Find last instance of a substring.
Definition: string.c:856
int mutt_str_coll(const char *a, const char *b)
Collate two strings (compare using locale), safely.
Definition: string.c:580
char * mutt_str_sep(char **stringp, const char *delim)
Find first occurance of any of delim characters in *stringp.
Definition: string.c:183
char * mutt_str_cat(char *buf, size_t buflen, const char *s)
Concatenate two strings.
Definition: string.c:265