NeoMutt  2020-09-25
Teaching an old dog new tricks
DOXYGEN
string.c
Go to the documentation of this file.
1 
30 #include "config.h"
31 #include <ctype.h>
32 #include <errno.h>
33 #include <limits.h>
34 #include <stdarg.h>
35 #include <stdbool.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include <strings.h>
40 #include "exit.h"
41 #include "logging.h"
42 #include "memory.h"
43 #include "message.h"
44 #include "string2.h"
45 #ifdef HAVE_SYSEXITS_H
46 #include <sysexits.h>
47 #endif
48 
52 struct SysExits
53 {
54  int err_num;
55  const char *err_str;
56 };
57 
58 static const struct SysExits sysexits[] = {
59 #ifdef EX_USAGE
60  { 0xff & EX_USAGE, "Bad usage." },
61 #endif
62 #ifdef EX_DATAERR
63  { 0xff & EX_DATAERR, "Data format error." },
64 #endif
65 #ifdef EX_NOINPUT
66  { 0xff & EX_NOINPUT, "Can't open input." },
67 #endif
68 #ifdef EX_NOUSER
69  { 0xff & EX_NOUSER, "User unknown." },
70 #endif
71 #ifdef EX_NOHOST
72  { 0xff & EX_NOHOST, "Host unknown." },
73 #endif
74 #ifdef EX_UNAVAILABLE
75  { 0xff & EX_UNAVAILABLE, "Service unavailable." },
76 #endif
77 #ifdef EX_SOFTWARE
78  { 0xff & EX_SOFTWARE, "Internal error." },
79 #endif
80 #ifdef EX_OSERR
81  { 0xff & EX_OSERR, "Operating system error." },
82 #endif
83 #ifdef EX_OSFILE
84  { 0xff & EX_OSFILE, "System file missing." },
85 #endif
86 #ifdef EX_CANTCREAT
87  { 0xff & EX_CANTCREAT, "Can't create output." },
88 #endif
89 #ifdef EX_IOERR
90  { 0xff & EX_IOERR, "I/O error." },
91 #endif
92 #ifdef EX_TEMPFAIL
93  { 0xff & EX_TEMPFAIL, "Deferred." },
94 #endif
95 #ifdef EX_PROTOCOL
96  { 0xff & EX_PROTOCOL, "Remote protocol error." },
97 #endif
98 #ifdef EX_NOPERM
99  { 0xff & EX_NOPERM, "Insufficient permission." },
100 #endif
101 #ifdef EX_CONFIG
102  { 0xff & EX_NOPERM, "Local configuration error." },
103 #endif
104  { S_ERR, "Exec error." },
105 };
106 
112 const char *mutt_str_sysexit(int err_num)
113 {
114  for (size_t i = 0; i < mutt_array_size(sysexits); i++)
115  {
116  if (err_num == sysexits[i].err_num)
117  return sysexits[i].err_str;
118  }
119 
120  return NULL;
121 }
122 
131 static size_t startswith(const char *str, const char *prefix, bool match_case)
132 {
133  if (!str || (str[0] == '\0') || !prefix || (prefix[0] == '\0'))
134  {
135  return 0;
136  }
137 
138  const char *saved_prefix = prefix;
139  for (; *str && *prefix; str++, prefix++)
140  {
141  if (*str == *prefix)
142  continue;
143 
144  if (!match_case && tolower(*str) == tolower(*prefix))
145  continue;
146 
147  return 0;
148  }
149 
150  return (*prefix == '\0') ? (prefix - saved_prefix) : 0;
151 }
152 
160 size_t mutt_str_startswith(const char *str, const char *prefix)
161 {
162  return startswith(str, prefix, true);
163 }
164 
172 size_t mutt_istr_startswith(const char *str, const char *prefix)
173 {
174  return startswith(str, prefix, false);
175 }
176 
188 int mutt_str_atol(const char *str, long *dst)
189 {
190  if (dst)
191  *dst = 0;
192 
193  if (!str || (*str == '\0')) /* no input: 0 */
194  return 0;
195 
196  char *e = NULL;
197  errno = 0;
198 
199  long res = strtol(str, &e, 10);
200  if (dst)
201  *dst = res;
202  if (((res == LONG_MIN) || (res == LONG_MAX)) && (errno == ERANGE))
203  return -2;
204  if (e && (*e != '\0'))
205  return -1;
206  return 0;
207 }
208 
222 int mutt_str_atos(const char *str, short *dst)
223 {
224  if (dst)
225  *dst = 0;
226 
227  long res = 0;
228  int rc = mutt_str_atol(str, &res);
229  if (rc < 0)
230  return rc;
231  if ((res < SHRT_MIN) || (res > SHRT_MAX))
232  return -2;
233 
234  if (dst)
235  *dst = (short) res;
236 
237  return 0;
238 }
239 
252 int mutt_str_atoi(const char *str, int *dst)
253 {
254  if (dst)
255  *dst = 0;
256 
257  long res = 0;
258  int rc = mutt_str_atol(str, &res);
259  if (rc < 0)
260  return rc;
261  if ((res < INT_MIN) || (res > INT_MAX))
262  return -2;
263 
264  if (dst)
265  *dst = (int) res;
266 
267  return 0;
268 }
269 
282 int mutt_str_atoui(const char *str, unsigned int *dst)
283 {
284  if (dst)
285  *dst = 0;
286 
287  unsigned long res = 0;
288  int rc = mutt_str_atoul(str, &res);
289  if (rc < 0)
290  return rc;
291  if (res > UINT_MAX)
292  return -2;
293 
294  if (dst)
295  *dst = (unsigned int) res;
296 
297  return rc;
298 }
299 
311 int mutt_str_atoul(const char *str, unsigned long *dst)
312 {
313  if (dst)
314  *dst = 0;
315 
316  if (!str || (*str == '\0')) /* no input: 0 */
317  return 0;
318 
319  char *e = NULL;
320  errno = 0;
321 
322  unsigned long res = strtoul(str, &e, 10);
323  if (dst)
324  *dst = res;
325  if ((res == ULONG_MAX) && (errno == ERANGE))
326  return -1;
327  if (e && (*e != '\0'))
328  return 1;
329  return 0;
330 }
331 
343 int mutt_str_atoull(const char *str, unsigned long long *dst)
344 {
345  if (dst)
346  *dst = 0;
347 
348  if (!str || (*str == '\0')) /* no input: 0 */
349  return 0;
350 
351  char *e = NULL;
352  errno = 0;
353 
354  unsigned long long res = strtoull(str, &e, 10);
355  if (dst)
356  *dst = res;
357  if ((res == ULLONG_MAX) && (errno == ERANGE))
358  return -1;
359  if (e && (*e != '\0'))
360  return 1;
361  return 0;
362 }
363 
370 char *mutt_str_dup(const char *str)
371 {
372  if (!str || (*str == '\0'))
373  return NULL;
374 
375  return strdup(str);
376 }
377 
385 char *mutt_str_cat(char *buf, size_t buflen, const char *s)
386 {
387  if (!buf || (buflen == 0) || !s)
388  return buf;
389 
390  char *p = buf;
391 
392  buflen--; /* Space for the trailing '\0'. */
393 
394  for (; (*buf != '\0') && buflen; buflen--)
395  buf++;
396  for (; *s && buflen; buflen--)
397  *buf++ = *s++;
398 
399  *buf = '\0';
400 
401  return p;
402 }
403 
414 char *mutt_strn_cat(char *d, size_t l, const char *s, size_t sl)
415 {
416  if (!d || (l == 0) || !s)
417  return d;
418 
419  char *p = d;
420 
421  l--; /* Space for the trailing '\0'. */
422 
423  for (; *d && l; l--)
424  d++;
425  for (; *s && l && sl; l--, sl--)
426  *d++ = *s++;
427 
428  *d = '\0';
429 
430  return p;
431 }
432 
446 char *mutt_str_replace(char **p, const char *s)
447 {
448  if (!p)
449  return NULL;
450  const char *tmp = *p;
451  *p = mutt_str_dup(s);
452  FREE(&tmp);
453  return *p;
454 }
455 
466 void mutt_str_append_item(char **str, const char *item, char sep)
467 {
468  if (!str || !item)
469  return;
470 
471  size_t sz = mutt_str_len(item);
472  size_t ssz = mutt_str_len(*str);
473 
474  mutt_mem_realloc(str, ssz + (((ssz > 0) && (sep != '\0')) ? 1 : 0) + sz + 1);
475  char *p = *str + ssz;
476  if ((ssz > 0) && (sep != '\0'))
477  *p++ = sep;
478  memcpy(p, item, sz + 1);
479 }
480 
490 void mutt_str_adjust(char **p)
491 {
492  if (!p || !*p)
493  return;
494  mutt_mem_realloc(p, strlen(*p) + 1);
495 }
496 
504 char *mutt_str_lower(char *s)
505 {
506  if (!s)
507  return NULL;
508 
509  char *p = s;
510 
511  while (*p)
512  {
513  *p = tolower((unsigned char) *p);
514  p++;
515  }
516 
517  return s;
518 }
519 
528 char *mutt_strn_copy(char *dest, const char *src, size_t len, size_t dsize)
529 {
530  if (!src || !dest || (len == 0) || (dsize == 0))
531  return dest;
532 
533  if (len > (dsize - 1))
534  len = dsize - 1;
535  memcpy(dest, src, len);
536  dest[len] = '\0';
537  return dest;
538 }
539 
548 char *mutt_strn_dup(const char *begin, size_t len)
549 {
550  if (!begin)
551  return NULL;
552 
553  char *p = mutt_mem_malloc(len + 1);
554  memcpy(p, begin, len);
555  p[len] = '\0';
556  return p;
557 }
558 
567 int mutt_str_cmp(const char *a, const char *b)
568 {
569  return strcmp(NONULL(a), NONULL(b));
570 }
571 
580 int mutt_istr_cmp(const char *a, const char *b)
581 {
582  return strcasecmp(NONULL(a), NONULL(b));
583 }
584 
593 bool mutt_strn_equal(const char *a, const char *b, size_t l)
594 {
595  return strncmp(NONULL(a), NONULL(b), l) == 0;
596 }
597 
607 int mutt_istrn_cmp(const char *a, const char *b, size_t l)
608 {
609  return strncasecmp(NONULL(a), NONULL(b), l);
610 }
611 
621 bool mutt_istrn_equal(const char *a, const char *b, size_t l)
622 {
623  return strncasecmp(NONULL(a), NONULL(b), l) == 0;
624 }
625 
631 size_t mutt_str_len(const char *a)
632 {
633  return a ? strlen(a) : 0;
634 }
635 
644 int mutt_str_coll(const char *a, const char *b)
645 {
646  return strcoll(NONULL(a), NONULL(b));
647 }
648 
656 const char *mutt_istr_find(const char *haystack, const char *needle)
657 {
658  if (!haystack)
659  return NULL;
660  if (!needle)
661  return haystack;
662 
663  const char *p = NULL, *q = NULL;
664 
665  while (*(p = haystack))
666  {
667  for (q = needle;
668  *p && *q && (tolower((unsigned char) *p) == tolower((unsigned char) *q));
669  p++, q++)
670  {
671  }
672  if ((*q == '\0'))
673  return haystack;
674  haystack++;
675  }
676  return NULL;
677 }
678 
686 char *mutt_str_skip_whitespace(const char *p)
687 {
688  if (!p)
689  return NULL;
690  SKIPWS(p);
691  return (char *) p;
692 }
693 
701 {
702  if (!s)
703  return;
704 
705  for (char *p = s + mutt_str_len(s) - 1; (p >= s) && IS_SPACE(*p); p--)
706  *p = '\0';
707 }
708 
716 size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
717 {
718  if (!dest || (dsize == 0))
719  return 0;
720  if (!src)
721  {
722  dest[0] = '\0';
723  return 0;
724  }
725 
726  char *dest0 = dest;
727  while ((--dsize > 0) && (*src != '\0'))
728  *dest++ = *src++;
729 
730  *dest = '\0';
731  return dest - dest0;
732 }
733 
743 char *mutt_str_skip_email_wsp(const char *s)
744 {
745  if (!s)
746  return NULL;
747 
748  for (; mutt_str_is_email_wsp(*s); s++)
749  ; // Do nothing
750 
751  return (char *) s;
752 }
753 
760 {
761  return c && strchr(" \t\r\n", c);
762 }
763 
773 size_t mutt_str_lws_len(const char *s, size_t n)
774 {
775  if (!s)
776  return 0;
777 
778  const char *p = s;
779  size_t len = n;
780 
781  if (n == 0)
782  return 0;
783 
784  for (; p < (s + n); p++)
785  {
786  if (!strchr(" \t\r\n", *p))
787  {
788  len = p - s;
789  break;
790  }
791  }
792 
793  if ((len != 0) && strchr("\r\n", *(p - 1))) /* LWS doesn't end with CRLF */
794  len = 0;
795  return len;
796 }
797 
807 size_t mutt_str_lws_rlen(const char *s, size_t n)
808 {
809  if (!s)
810  return 0;
811 
812  const char *p = s + n - 1;
813  size_t len = n;
814 
815  if (n == 0)
816  return 0;
817 
818  if (strchr("\r\n", *p)) /* LWS doesn't end with CRLF */
819  return 0;
820 
821  for (; p >= s; p--)
822  {
823  if (!strchr(" \t\r\n", *p))
824  {
825  len = s + n - 1 - p;
826  break;
827  }
828  }
829 
830  return len;
831 }
832 
840 {
841  if (!s)
842  return;
843 
844  char *w = s;
845 
846  for (; *s; s++)
847  {
848  if (*s == '\\')
849  {
850  if (!*++s)
851  break; /* error? */
852  *w++ = *s;
853  }
854  else if (*s != '\"')
855  {
856  if (w != s)
857  *w = *s;
858  w++;
859  }
860  }
861  *w = '\0';
862 }
863 
871 bool mutt_str_equal(const char *a, const char *b)
872 {
873  return (a == b) || (mutt_str_cmp(a, b) == 0);
874 }
875 
883 bool mutt_istr_equal(const char *a, const char *b)
884 {
885  return (a == b) || (mutt_istr_cmp(a, b) == 0);
886 }
887 
898 const char *mutt_str_next_word(const char *s)
899 {
900  if (!s)
901  return NULL;
902 
903  while (*s && !IS_SPACE(*s))
904  s++;
905  SKIPWS(s);
906  return s;
907 }
908 
920 const char *mutt_strn_rfind(const char *haystack, size_t haystack_length, const char *needle)
921 {
922  if (!haystack || (haystack_length == 0) || !needle)
923  return NULL;
924 
925  int needle_length = strlen(needle);
926  const char *haystack_end = haystack + haystack_length - needle_length;
927 
928  for (const char *p = haystack_end; p >= haystack; --p)
929  {
930  for (size_t i = 0; i < needle_length; i++)
931  {
932  if (p[i] != needle[i])
933  goto next;
934  }
935  return p;
936 
937  next:;
938  }
939  return NULL;
940 }
941 
948 bool mutt_str_is_ascii(const char *str, size_t len)
949 {
950  if (!str)
951  return true;
952 
953  for (; (*str != '\0') && (len > 0); str++, len--)
954  if ((*str & 0x80) != 0)
955  return false;
956 
957  return true;
958 }
959 
971 const char *mutt_str_find_word(const char *src)
972 {
973  if (!src)
974  return NULL;
975 
976  while (*src && strchr(" \t\n", *src))
977  src++;
978  while (*src && !strchr(" \t\n", *src))
979  src++;
980  return src;
981 }
982 
991 const char *mutt_str_getenv(const char *name)
992 {
993  if (!name)
994  return NULL;
995 
996  const char *val = getenv(name);
997  if (val && (val[0] != '\0'))
998  return val;
999 
1000  return NULL;
1001 }
1002 
1013 bool mutt_str_inline_replace(char *buf, size_t buflen, size_t xlen, const char *rstr)
1014 {
1015  if (!buf || !rstr || (xlen >= buflen))
1016  return false;
1017 
1018  size_t slen = mutt_str_len(buf + xlen);
1019  size_t rlen = mutt_str_len(rstr);
1020 
1021  if ((slen + rlen) >= buflen)
1022  return false;
1023 
1024  memmove(buf + rlen, buf + xlen, slen + 1);
1025  memmove(buf, rstr, rlen);
1026 
1027  return true;
1028 }
1029 
1037 int mutt_istr_remall(char *str, const char *target)
1038 {
1039  int rc = 1;
1040  if (!str || !target)
1041  return rc;
1042 
1043  // Look through an ensure all instances of the substring are gone.
1044  while ((str = (char *) strcasestr(str, target)))
1045  {
1046  size_t target_len = mutt_str_len(target);
1047  memmove(str, str + target_len, 1 + strlen(str + target_len));
1048  rc = 0; // If we got here, then a substring existed and has been removed.
1049  }
1050 
1051  return rc;
1052 }
1053 
1054 #ifdef HAVE_VASPRINTF
1055 
1063 int mutt_str_asprintf(char **strp, const char *fmt, ...)
1064 {
1065  if (!strp || !fmt)
1066  return -1;
1067 
1068  va_list ap;
1069  int n;
1070 
1071  va_start(ap, fmt);
1072  n = vasprintf(strp, fmt, ap);
1073  va_end(ap);
1074 
1075  /* GNU libc man page for vasprintf(3) states that the value of *strp
1076  * is undefined when the return code is -1. */
1077  if (n < 0)
1078  {
1079  mutt_error(_("Out of memory")); /* LCOV_EXCL_LINE */
1080  mutt_exit(1); /* LCOV_EXCL_LINE */
1081  }
1082 
1083  if (n == 0)
1084  {
1085  /* NeoMutt convention is to use NULL for 0-length strings */
1086  FREE(strp);
1087  }
1088 
1089  return n;
1090 }
1091 #else
1092 /* Allocate a C-string large enough to contain the formatted string.
1093  * This is essentially malloc+sprintf in one.
1094  */
1095 int mutt_str_asprintf(char **strp, const char *fmt, ...)
1096 {
1097  if (!strp || !fmt)
1098  return -1;
1099 
1100  int rlen = 256;
1101 
1102  *strp = mutt_mem_malloc(rlen);
1103  while (true)
1104  {
1105  va_list ap;
1106  va_start(ap, fmt);
1107  const int n = vsnprintf(*strp, rlen, fmt, ap);
1108  va_end(ap);
1109  if (n < 0)
1110  {
1111  FREE(strp);
1112  return n;
1113  }
1114 
1115  if (n < rlen)
1116  {
1117  /* reduce space to just that which was used. note that 'n' does not
1118  * include the terminal nul char. */
1119  if (n == 0) /* convention is to use NULL for zero-length strings. */
1120  FREE(strp);
1121  else if (n != rlen - 1)
1122  mutt_mem_realloc(strp, n + 1);
1123  return n;
1124  }
1125  /* increase size and try again */
1126  rlen = n + 1;
1127  mutt_mem_realloc(strp, rlen);
1128  }
1129  /* not reached */
1130 }
1131 #endif /* HAVE_ASPRINTF */
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:871
int mutt_istr_cmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:580
int mutt_str_cmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:567
char * mutt_str_skip_whitespace(const char *p)
Find the first non-whitespace character in a string.
Definition: string.c:686
static size_t startswith(const char *str, const char *prefix, bool match_case)
Check whether a string starts with a prefix.
Definition: string.c:131
#define NONULL(x)
Definition: string2.h:37
int mutt_str_atoi(const char *str, int *dst)
Convert ASCII string to an integer.
Definition: string.c:252
Memory management wrappers.
#define S_ERR
Definition: string2.h:41
char * mutt_strn_cat(char *d, size_t l, const char *s, size_t sl)
Concatenate two strings.
Definition: string.c:414
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
#define _(a)
Definition: message.h:28
void mutt_str_adjust(char **p)
Shrink-to-fit a string.
Definition: string.c:490
int mutt_str_atol(const char *str, long *dst)
Convert ASCII string to a long.
Definition: string.c:188
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:773
int mutt_str_atos(const char *str, short *dst)
Convert ASCII string to a short.
Definition: string.c:222
int mutt_str_coll(const char *a, const char *b)
Collate two strings (compare using locale), safely.
Definition: string.c:644
Logging Dispatcher.
String manipulation functions.
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Definition: string.c:991
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:621
#define mutt_array_size(x)
Definition: memory.h:33
Lookup table of error messages.
Definition: string.c:52
char * mutt_strn_dup(const char *begin, size_t len)
Duplicate a sub-string.
Definition: string.c:548
#define SKIPWS(ch)
Definition: string2.h:46
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:607
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:528
char * mutt_str_lower(char *s)
Convert all characters in the string to lowercase.
Definition: string.c:504
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:883
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
Message logging.
const char * mutt_str_sysexit(int err_num)
Return a string matching an error code.
Definition: string.c:112
void mutt_str_remove_trailing_ws(char *s)
Trim trailing whitespace from a string.
Definition: string.c:700
bool mutt_str_is_ascii(const char *str, size_t len)
Is a string ASCII (7-bit)?
Definition: string.c:948
bool mutt_str_is_email_wsp(char c)
Is this a whitespace character (for an email header)
Definition: string.c:759
int mutt_istr_remall(char *str, const char *target)
Remove all occurrences of substring, ignoring case.
Definition: string.c:1037
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:160
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:90
Leave the program NOW.
int mutt_str_atoui(const char *str, unsigned int *dst)
Convert ASCII string to an unsigned integer.
Definition: string.c:282
int mutt_str_atoull(const char *str, unsigned long long *dst)
Convert ASCII string to an unsigned long long.
Definition: string.c:343
char * mutt_str_skip_email_wsp(const char *s)
Skip over whitespace as defined by RFC5322.
Definition: string.c:743
void mutt_str_dequote_comment(char *s)
Un-escape characters in an email address comment.
Definition: string.c:839
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:172
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:593
char * mutt_str_cat(char *buf, size_t buflen, const char *s)
Concatenate two strings.
Definition: string.c:385
#define IS_SPACE(ch)
Definition: string2.h:38
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition: main.c:137
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:807
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:631
const char * mutt_istr_find(const char *haystack, const char *needle)
Find first occurrence of string (ignoring case)
Definition: string.c:656
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:716
const char * err_str
Definition: string.c:55
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:446
#define mutt_error(...)
Definition: logging.h:84
int mutt_str_atoul(const char *str, unsigned long *dst)
Convert ASCII string to an unsigned long.
Definition: string.c:311
#define FREE(x)
Definition: memory.h:40
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:1013
const char * mutt_strn_rfind(const char *haystack, size_t haystack_length, const char *needle)
Find last instance of a substring.
Definition: string.c:920
int mutt_str_asprintf(char **strp, const char *fmt,...)
Definition: string.c:1095
void mutt_str_append_item(char **str, const char *item, char sep)
Add string to another separated by sep.
Definition: string.c:466
const char * mutt_str_next_word(const char *s)
Find the next word in a string.
Definition: string.c:898
const char * mutt_str_find_word(const char *src)
Find the end of a word (non-space)
Definition: string.c:971
int err_num
Definition: string.c:54