NeoMutt  2024-11-14-138-ge5ca67
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
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_MUTT_STRING2_H
29#define MUTT_MUTT_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
39/* Exit values */
40#define S_ERR 127
41#define S_BKG 126
42
43/* this macro must check for (*ch == 0) since isspace(0) has unreliable behavior
44 * on some systems */
45#define SKIPWS(ch) \
46 while (*(ch) && isspace((unsigned char) *(ch))) \
47 ch++;
48
49#define terminate_string(str, strlen, buflen) \
50 (str)[MIN((strlen), (buflen))] = '\0'
51
52#define terminate_buffer(str, strlen) \
53 terminate_string(str, strlen, sizeof(str) - 1)
54
55void mutt_str_adjust(char **ptr);
56int mutt_str_asprintf(char **strp, const char *fmt, ...)
57 __attribute__((__format__(__printf__, 2, 3)));
58int mutt_str_coll(const char *a, const char *b);
59const char *mutt_str_find_word(const char *src);
60const char *mutt_str_getenv(const char *name);
61void mutt_str_hyphenate(char *buf, size_t buflen, const char *str);
62bool mutt_str_is_ascii(const char *str, size_t len);
63size_t mutt_str_len(const char *a);
64char * mutt_str_lower(char *str);
65size_t mutt_str_lws_len(const char *s, size_t n);
66void mutt_str_remove_trailing_ws(char *s);
67char * mutt_str_replace(char **p, const char *s);
68char * mutt_str_sep(char **stringp, const char *delim);
69char * mutt_str_skip_email_wsp(const char *s);
70char * mutt_str_skip_whitespace(const char *p);
71const char *mutt_str_sysexit(int e);
72char * mutt_str_upper(char *str);
73
74/* case-sensitive flavours */
75int mutt_str_cmp(const char *a, const char *b);
76size_t mutt_str_copy(char *dest, const char *src, size_t dsize);
77char * mutt_str_dup(const char *str);
78bool mutt_str_equal(const char *a, const char *b);
79size_t mutt_str_startswith(const char *str, const char *prefix);
80
81/* case-sensitive, length-bound flavours */
82char * mutt_strn_copy(char *dest, const char *src, size_t len, size_t dsize);
83char * mutt_strn_dup(const char *begin, size_t l);
84bool mutt_strn_equal(const char *a, const char *b, size_t num);
85
86/* case-insensitive flavours */
87int mutt_istr_cmp(const char *a, const char *b);
88bool mutt_istr_equal(const char *a, const char *b);
89const char *mutt_istr_find(const char *haystack, const char *needle);
90int mutt_istr_remall(char *str, const char *target);
91size_t mutt_istr_startswith(const char *str, const char *prefix);
92int mutt_str_inbox_cmp(const char *a, const char *b);
93
94/* case-insensitive, length-bound flavours */
95int mutt_istrn_cmp(const char *a, const char *b, size_t num);
96bool mutt_istrn_equal(const char *a, const char *b, size_t num);
97const char *mutt_istrn_rfind(const char *haystack, size_t haystack_length, const char *needle);
98
104static inline bool mutt_str_is_email_wsp(char c)
105{
106 return (c == ' ') || (c == '\t') || (c == '\r') || (c == '\n');
107}
108
109#endif /* MUTT_MUTT_STRING2_H */
int mutt_str_inbox_cmp(const char *a, const char *b)
Do two folders share the same path and one is an inbox -.
Definition: string.c:887
const char * mutt_str_sysexit(int e)
Return a string matching an error code.
Definition: string.c:169
int mutt_str_cmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:399
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:439
void mutt_str_remove_trailing_ws(char *s)
Trim trailing whitespace from a string.
Definition: string.c:565
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:672
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
int mutt_str_asprintf(char **strp, const char *fmt,...) __attribute__((__format__(__printf__
char * mutt_str_upper(char *str)
Convert all characters in the string to uppercase.
Definition: string.c:336
char * mutt_str_lower(char *str)
Convert all characters in the string to lowercase.
Definition: string.c:313
char * mutt_str_skip_email_wsp(const char *s)
Skip over whitespace as defined by RFC5322.
Definition: string.c:608
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:469
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:628
bool mutt_str_is_ascii(const char *str, size_t len)
Is a string ASCII (7-bit)?
Definition: string.c:683
int mutt_istr_cmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:412
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:660
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:425
char * mutt_strn_dup(const char *begin, size_t l)
Duplicate a sub-string.
Definition: string.c:380
int int mutt_str_coll(const char *a, const char *b)
Collate two strings (compare using locale), safely.
Definition: string.c:509
const char * mutt_str_find_word(const char *src)
Find the end of a word (non-space)
Definition: string.c:706
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:360
int mutt_istr_remall(char *str, const char *target)
Remove all occurrences of substring, ignoring case.
Definition: string.c:745
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Definition: string.c:726
const char * mutt_istr_find(const char *haystack, const char *needle)
Find first occurrence of string (ignoring case)
Definition: string.c:521
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:230
void mutt_str_hyphenate(char *buf, size_t buflen, const char *str)
Hyphenate a snake-case string.
Definition: string.c:849
char * mutt_str_skip_whitespace(const char *p)
Find the first non-whitespace character in a string.
Definition: string.c:551
void mutt_str_adjust(char **ptr)
Shrink-to-fit a string.
Definition: string.c:299
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:496
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:581
static bool mutt_str_is_email_wsp(char c)
Is this a whitespace character (for an email header)
Definition: string2.h:104
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:242
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:453
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:280
char * mutt_str_sep(char **stringp, const char *delim)
Find first occurrence of any of delim characters in *stringp.
Definition: string.c:186