NeoMutt  2025-09-05-43-g177ed6
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
string2.h File Reference

String manipulation functions. More...

#include <stdbool.h>
#include <stdio.h>
#include "array.h"
#include "memory.h"
+ Include dependency graph for string2.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define STR_COMMAND   8192
 Enough space for a long command line.
 
#define NONULL(x)
 
#define S_ERR   127
 
#define S_BKG   126
 
#define SKIPWS(ch)
 
#define terminate_string(str, strlen, buflen)
 
#define terminate_buffer(str, strlen)
 

Functions

 ARRAY_HEAD (StringArray, const char *)
 Useful ARRAY of strings.
 
void string_array_clear (struct StringArray *arr)
 Free all memory of a StringArray.
 
void mutt_str_adjust (char **ptr)
 Shrink-to-fit a string.
 
int mutt_str_asprintf (char **strp, const char *fmt,...) __attribute__((__format__(__printf__
 
int int mutt_str_coll (const char *a, const char *b)
 Collate two strings (compare using locale), safely.
 
const char * mutt_str_find_word (const char *src)
 Find the end of a word (non-space)
 
const char * mutt_str_getenv (const char *name)
 Get an environment variable.
 
void mutt_str_hyphenate (char *buf, size_t buflen, const char *str)
 Hyphenate a snake-case string.
 
bool mutt_str_is_ascii (const char *str, size_t len)
 Is a string ASCII (7-bit)?
 
size_t mutt_str_len (const char *a)
 Calculate the length of a string, safely.
 
char * mutt_str_lower (char *str)
 Convert all characters in the string to lowercase.
 
size_t mutt_str_lws_len (const char *s, size_t n)
 Measure the linear-white-space at the beginning of a string.
 
void mutt_str_remove_trailing_ws (char *s)
 Trim trailing whitespace from a string.
 
char * mutt_str_replace (char **p, const char *s)
 Replace one string with another.
 
char * mutt_str_sep (char **stringp, const char *delim)
 Find first occurrence of any of delim characters in *stringp.
 
char * mutt_str_skip_email_wsp (const char *s)
 Skip over whitespace as defined by RFC5322.
 
char * mutt_str_skip_whitespace (const char *p)
 Find the first non-whitespace character in a string.
 
const char * mutt_str_sysexit (int e)
 Return a string matching an error code.
 
char * mutt_str_upper (char *str)
 Convert all characters in the string to uppercase.
 
int mutt_str_cmp (const char *a, const char *b)
 Compare two strings, safely.
 
size_t mutt_str_copy (char *dest, const char *src, size_t dsize)
 Copy a string into a buffer (guaranteeing NUL-termination)
 
char * mutt_str_dup (const char *str)
 Copy a string, safely.
 
bool mutt_str_equal (const char *a, const char *b)
 Compare two strings.
 
size_t mutt_str_startswith (const char *str, const char *prefix)
 Check whether a string starts with a prefix.
 
char * mutt_strn_copy (char *dest, const char *src, size_t len, size_t dsize)
 Copy a sub-string into a buffer.
 
char * mutt_strn_dup (const char *begin, size_t l)
 Duplicate a sub-string.
 
bool mutt_strn_equal (const char *a, const char *b, size_t num)
 Check for equality of two strings (to a maximum), safely.
 
int mutt_istr_cmp (const char *a, const char *b)
 Compare two strings ignoring case, safely.
 
bool mutt_istr_equal (const char *a, const char *b)
 Compare two strings, ignoring case.
 
const char * mutt_istr_find (const char *haystack, const char *needle)
 Find first occurrence of string (ignoring case)
 
int mutt_istr_remall (char *str, const char *target)
 Remove all occurrences of substring, ignoring case.
 
size_t mutt_istr_startswith (const char *str, const char *prefix)
 Check whether a string starts with a prefix, ignoring case.
 
int mutt_str_inbox_cmp (const char *a, const char *b)
 Do two folders share the same path and one is an inbox -.
 
int mutt_istrn_cmp (const char *a, const char *b, size_t num)
 Compare two strings ignoring case (to a maximum), safely.
 
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.
 
const char * mutt_istrn_rfind (const char *haystack, size_t haystack_length, const char *needle)
 Find last instance of a substring, ignoring case.
 
static bool mutt_str_is_email_wsp (char c)
 Is this a whitespace character (for an email header)
 

Detailed Description

String manipulation functions.

Authors
  • Richard Russon
  • Pietro Cerutti

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file string2.h.

Macro Definition Documentation

◆ STR_COMMAND

#define STR_COMMAND   8192

Enough space for a long command line.

Definition at line 41 of file string2.h.

◆ NONULL

#define NONULL ( x)
Value:
((x) ? (x) : "")

Definition at line 43 of file string2.h.

◆ S_ERR

#define S_ERR   127

Definition at line 46 of file string2.h.

◆ S_BKG

#define S_BKG   126

Definition at line 47 of file string2.h.

◆ SKIPWS

#define SKIPWS ( ch)
Value:
while (*(ch) && mutt_isspace(*(ch))) \
ch++;
bool mutt_isspace(int arg)
Wrapper for isspace(3)
Definition ctype.c:95

Definition at line 51 of file string2.h.

51#define SKIPWS(ch) \
52 while (*(ch) && mutt_isspace(*(ch))) \
53 ch++;

◆ terminate_string

#define terminate_string ( str,
strlen,
buflen )
Value:
(str)[MIN((strlen), (buflen))] = '\0'
#define MIN(a, b)
Definition memory.h:37

Definition at line 55 of file string2.h.

55#define terminate_string(str, strlen, buflen) \
56 (str)[MIN((strlen), (buflen))] = '\0'

◆ terminate_buffer

#define terminate_buffer ( str,
strlen )
Value:
terminate_string(str, strlen, sizeof(str) - 1)
#define terminate_string(str, strlen, buflen)
Definition string2.h:55

Definition at line 58 of file string2.h.

58#define terminate_buffer(str, strlen) \
59 terminate_string(str, strlen, sizeof(str) - 1)

Function Documentation

◆ ARRAY_HEAD()

ARRAY_HEAD ( StringArray ,
const char *  )

Useful ARRAY of strings.

◆ string_array_clear()

void string_array_clear ( struct StringArray * arr)

Free all memory of a StringArray.

Parameters
arrArray of text to clear
Note
Array is emptied, but not freed

Definition at line 931 of file string.c.

932{
933 const char **str = NULL;
934 ARRAY_FOREACH(str, arr)
935 {
936 FREE(str);
937 }
938
939 ARRAY_FREE(arr);
940}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:214
#define ARRAY_FREE(head)
Release all memory.
Definition array.h:204
#define FREE(x)
Definition memory.h:62
+ Here is the caller graph for this function:

◆ mutt_str_adjust()

void mutt_str_adjust ( char ** ptr)

Shrink-to-fit a string.

Parameters
[out]ptrString to alter

Take a string which is allocated on the heap, find its length and reallocate the memory to be exactly the right size.

This function alters the pointer of the caller.

Definition at line 301 of file string.c.

302{
303 if (!ptr || !*ptr)
304 return;
305 MUTT_MEM_REALLOC(ptr, strlen(*ptr) + 1, char);
306}
#define MUTT_MEM_REALLOC(pptr, n, type)
Definition memory.h:50
+ Here is the caller graph for this function:

◆ mutt_str_asprintf()

int mutt_str_asprintf ( char ** strp,
const char * fmt,
... )
+ Here is the call graph for this function:

◆ mutt_str_coll()

int int mutt_str_coll ( const char * a,
const char * b )

Collate two strings (compare using locale), safely.

Parameters
aFirst string to compare
bSecond string to compare
Return values
<0a precedes b
0a and b are identical
>0b precedes a

Definition at line 511 of file string.c.

512{
513 return strcoll(NONULL(a), NONULL(b));
514}
#define NONULL(x)
Definition string2.h:43
+ Here is the caller graph for this function:

◆ mutt_str_find_word()

const char * mutt_str_find_word ( const char * src)

Find the end of a word (non-space)

Parameters
srcString to search
Return values
ptrEnd of the word

Skip to the end of the current word. Skip past any whitespace characters.

Note
If there aren't any more words, this will return a pointer to the final NUL character.

Definition at line 706 of file string.c.

707{
708 if (!src)
709 return NULL;
710
711 while (*src && strchr(" \t\n", *src))
712 src++;
713 while (*src && !strchr(" \t\n", *src))
714 src++;
715 return src;
716}
+ Here is the caller graph for this function:

◆ mutt_str_getenv()

const char * mutt_str_getenv ( const char * name)

Get an environment variable.

Parameters
nameEnvironment variable to get
Return values
ptrValue of variable
NULLVariable isn't set, or is empty
Warning
The caller must not free the returned pointer.

Definition at line 726 of file string.c.

727{
728 if (!name)
729 return NULL;
730
731 const char *val = getenv(name);
732 if (val && (val[0] != '\0'))
733 return val;
734
735 return NULL;
736}
+ Here is the caller graph for this function:

◆ mutt_str_hyphenate()

void mutt_str_hyphenate ( char * buf,
size_t buflen,
const char * str )

Hyphenate a snake-case string.

Parameters
bufBuffer for the result
buflenLength of the buffer
strString to convert

Replace underscores (_) with hyphens -`).

Definition at line 849 of file string.c.

850{
851 if (!buf || (buflen == 0) || !str)
852 return;
853
854 mutt_str_copy(buf, str, buflen);
855 for (; *buf != '\0'; buf++)
856 {
857 if (*buf == '_')
858 *buf = '-';
859 }
860}
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_str_is_ascii()

bool mutt_str_is_ascii ( const char * str,
size_t len )

Is a string ASCII (7-bit)?

Parameters
strString to examine
lenLength of string to examine
Return values
trueThere are no 8-bit chars

Definition at line 683 of file string.c.

684{
685 if (!str)
686 return true;
687
688 for (; (*str != '\0') && (len > 0); str++, len--)
689 if ((*str & 0x80) != 0)
690 return false;
691
692 return true;
693}
+ Here is the caller graph for this function:

◆ mutt_str_len()

size_t mutt_str_len ( const char * a)

Calculate the length of a string, safely.

Parameters
aString to measure
Return values
numLength in bytes

Definition at line 498 of file string.c.

499{
500 return a ? strlen(a) : 0;
501}

◆ mutt_str_lower()

char * mutt_str_lower ( char * str)

Convert all characters in the string to lowercase.

Parameters
strString to lowercase
Return values
ptrLowercase string

The string is transformed in place.

Definition at line 315 of file string.c.

316{
317 if (!str)
318 return NULL;
319
320 char *p = str;
321
322 while (*p)
323 {
324 *p = mutt_tolower(*p);
325 p++;
326 }
327
328 return str;
329}
int mutt_tolower(int arg)
Wrapper for tolower(3)
Definition ctype.c:125
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_str_lws_len()

size_t mutt_str_lws_len ( const char * s,
size_t n )

Measure the linear-white-space at the beginning of a string.

Parameters
sString to check
nMaximum number of characters to check
Return values
numCount of whitespace characters

Count the number of whitespace characters at the beginning of a string. They can be <space>, <tab>, <cr> or <lf>.

Definition at line 628 of file string.c.

629{
630 if (!s)
631 return 0;
632
633 const char *p = s;
634 size_t len = n;
635
636 if (n == 0)
637 return 0;
638
639 for (; p < (s + n); p++)
640 {
641 if (!strchr(" \t\r\n", *p))
642 {
643 len = p - s;
644 break;
645 }
646 }
647
648 if ((len != 0) && strchr("\r\n", *(p - 1))) /* LWS doesn't end with CRLF */
649 len = 0;
650 return len;
651}
+ Here is the caller graph for this function:

◆ mutt_str_remove_trailing_ws()

void mutt_str_remove_trailing_ws ( char * s)

Trim trailing whitespace from a string.

Parameters
sString to trim

The string is modified in place.

Definition at line 565 of file string.c.

566{
567 if (!s)
568 return;
569
570 for (char *p = s + mutt_str_len(s) - 1; (p >= s) && mutt_isspace(*p); p--)
571 *p = '\0';
572}
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition string.c:498
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_str_replace()

char * mutt_str_replace ( char ** p,
const char * s )

Replace one string with another.

Parameters
[out]pString to replace
[in]sNew string
Return values
ptrReplaced string

This function free()s the original string, strdup()s the new string and overwrites the pointer to the first string.

This function alters the pointer of the caller.

Note
Free *p afterwards to handle the case that *p and s reference the same memory

Definition at line 282 of file string.c.

283{
284 if (!p)
285 return NULL;
286 const char *tmp = *p;
287 *p = mutt_str_dup(s);
288 FREE(&tmp);
289 return *p;
290}
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition string.c:255
+ Here is the call graph for this function:

◆ mutt_str_sep()

char * mutt_str_sep ( char ** stringp,
const char * delim )

Find first occurrence of any of delim characters in *stringp.

Parameters
stringpPointer to string to search for delim, updated with position of after delim if found else NULL
delimString with characters to search for in *stringp
Return values
ptrInput value of *stringp

Definition at line 188 of file string.c.

189{
190 if (!stringp || !*stringp || !delim)
191 return NULL;
192 return strsep(stringp, delim);
193}
static char * strsep(char **stringp, const char *delim)
Extract a token from a string.
Definition string.c:84
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_str_skip_email_wsp()

char * mutt_str_skip_email_wsp ( const char * s)

Skip over whitespace as defined by RFC5322.

Parameters
sString to search
Return values
ptr
  • First non-whitespace character
  • Terminating NUL character, if the string was entirely whitespace

This is used primarily for parsing header fields.

Definition at line 608 of file string.c.

609{
610 if (!s)
611 return NULL;
612
613 for (; mutt_str_is_email_wsp(*s); s++)
614 ; // Do nothing
615
616 return (char *) s;
617}
static bool mutt_str_is_email_wsp(char c)
Is this a whitespace character (for an email header)
Definition string2.h:110
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_str_skip_whitespace()

char * mutt_str_skip_whitespace ( const char * p)

Find the first non-whitespace character in a string.

Parameters
pString to search
Return values
ptr
  • First non-whitespace character
  • Terminating NUL character, if the string was entirely whitespace

Definition at line 551 of file string.c.

552{
553 if (!p)
554 return NULL;
555 SKIPWS(p);
556 return (char *) p;
557}
#define SKIPWS(ch)
Definition string2.h:51
+ Here is the caller graph for this function:

◆ mutt_str_sysexit()

const char * mutt_str_sysexit ( int err_num)

Return a string matching an error code.

Parameters
err_numError code, e.g. EX_NOPERM
Return values
ptrstring representing the error code

Definition at line 171 of file string.c.

172{
173 for (size_t i = 0; i < countof(SysExits); i++)
174 {
175 if (err_num == SysExits[i].err_num)
176 return SysExits[i].err_str;
177 }
178
179 return NULL;
180}
#define countof(x)
Definition memory.h:44
Lookup table of error messages.
Definition string.c:111
const char * err_str
Human-readable string for error.
Definition string.c:113
+ Here is the caller graph for this function:

◆ mutt_str_upper()

char * mutt_str_upper ( char * str)

Convert all characters in the string to uppercase.

Parameters
strString to uppercase
Return values
ptrUppercase string

The string is transformed in place.

Definition at line 338 of file string.c.

339{
340 if (!str)
341 return NULL;
342
343 char *p = str;
344
345 while (*p)
346 {
347 *p = mutt_toupper(*p);
348 p++;
349 }
350
351 return str;
352}
int mutt_toupper(int arg)
Wrapper for toupper(3)
Definition ctype.c:139
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_str_cmp()

int mutt_str_cmp ( const char * a,
const char * b )

Compare two strings, safely.

Parameters
aFirst string to compare
bSecond string to compare
Return values
-1a precedes b
0a and b are identical
1b precedes a

Definition at line 401 of file string.c.

402{
403 return strcmp(NONULL(a), NONULL(b));
404}
+ Here is the caller graph for this function:

◆ mutt_str_copy()

size_t mutt_str_copy ( char * dest,
const char * src,
size_t dsize )

Copy a string into a buffer (guaranteeing NUL-termination)

Parameters
destBuffer for the result
srcString to copy
dsizeDestination buffer size
Return values
numDestination string length

Definition at line 581 of file string.c.

582{
583 if (!dest || (dsize == 0))
584 return 0;
585 if (!src)
586 {
587 dest[0] = '\0';
588 return 0;
589 }
590
591 char *dest0 = dest;
592 while ((--dsize > 0) && (*src != '\0'))
593 *dest++ = *src++;
594
595 *dest = '\0';
596 return dest - dest0;
597}

◆ mutt_str_dup()

char * mutt_str_dup ( const char * str)

Copy a string, safely.

Parameters
strString to copy
Return values
ptrCopy of the string
NULLstr was NULL or empty

Definition at line 255 of file string.c.

256{
257 if (!str || (*str == '\0'))
258 return NULL;
259
260 char *p = strdup(str);
261 if (!p)
262 {
263 mutt_error("%s", strerror(errno)); // LCOV_EXCL_LINE
264 mutt_exit(1); // LCOV_EXCL_LINE
265 }
266 return p;
267}
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition exit.c:41
#define mutt_error(...)
Definition logging2.h:93
+ Here is the call graph for this function:

◆ mutt_str_equal()

bool mutt_str_equal ( const char * a,
const char * b )

Compare two strings.

Parameters
aFirst string
bSecond string
Return values
trueThe strings are equal
falseThe strings are not equal

Definition at line 660 of file string.c.

661{
662 return (a == b) || (mutt_str_cmp(a, b) == 0);
663}
int mutt_str_cmp(const char *a, const char *b)
Compare two strings, safely.
Definition string.c:401
+ Here is the call graph for this function:

◆ mutt_str_startswith()

size_t mutt_str_startswith ( const char * str,
const char * prefix )

Check whether a string starts with a prefix.

Parameters
strString to check
prefixPrefix to match
Return values
numLength of prefix if str starts with prefix
0str does not start with prefix

Definition at line 232 of file string.c.

233{
234 return startswith(str, prefix, true);
235}
static size_t startswith(const char *str, const char *prefix, bool match_case)
Check whether a string starts with a prefix.
Definition string.c:203
+ Here is the call graph for this function:

◆ mutt_strn_copy()

char * mutt_strn_copy ( char * dest,
const char * src,
size_t len,
size_t dsize )

Copy a sub-string into a buffer.

Parameters
destBuffer for the result
srcStart of the string to copy
lenLength of the string to copy
dsizeDestination buffer size
Return values
ptrDestination buffer

Definition at line 362 of file string.c.

363{
364 if (!src || !dest || (len == 0) || (dsize == 0))
365 return dest;
366
367 if (len > (dsize - 1))
368 len = dsize - 1;
369 memcpy(dest, src, len);
370 dest[len] = '\0';
371 return dest;
372}
+ Here is the caller graph for this function:

◆ mutt_strn_dup()

char * mutt_strn_dup ( const char * begin,
size_t len )

Duplicate a sub-string.

Parameters
beginStart of the string to copy
lenLength of string to copy
Return values
ptrNew string

The caller must free the returned string.

Definition at line 382 of file string.c.

383{
384 if (!begin)
385 return NULL;
386
387 char *p = MUTT_MEM_MALLOC(len + 1, char);
388 memcpy(p, begin, len);
389 p[len] = '\0';
390 return p;
391}
#define MUTT_MEM_MALLOC(n, type)
Definition memory.h:48
+ Here is the caller graph for this function:

◆ mutt_strn_equal()

bool mutt_strn_equal ( const char * a,
const char * b,
size_t num )

Check for equality of two strings (to a maximum), safely.

Parameters
aFirst string to compare
bSecond string to compare
numMaximum number of bytes to compare
Return values
trueFirst num chars of both strings are equal
falseFirst num chars of both strings not equal

Definition at line 427 of file string.c.

428{
429 return strncmp(NONULL(a), NONULL(b), num) == 0;
430}
+ Here is the caller graph for this function:

◆ mutt_istr_cmp()

int mutt_istr_cmp ( const char * a,
const char * b )

Compare two strings ignoring case, safely.

Parameters
aFirst string to compare
bSecond string to compare
Return values
-1a precedes b
0a and b are identical
1b precedes a

Definition at line 414 of file string.c.

415{
416 return strcasecmp(NONULL(a), NONULL(b));
417}
+ Here is the caller graph for this function:

◆ mutt_istr_equal()

bool mutt_istr_equal ( const char * a,
const char * b )

Compare two strings, ignoring case.

Parameters
aFirst string
bSecond string
Return values
trueThe strings are equal
falseThe strings are not equal

Definition at line 672 of file string.c.

673{
674 return (a == b) || (mutt_istr_cmp(a, b) == 0);
675}
int mutt_istr_cmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition string.c:414
+ Here is the call graph for this function:

◆ mutt_istr_find()

const char * mutt_istr_find ( const char * haystack,
const char * needle )

Find first occurrence of string (ignoring case)

Parameters
haystackString to search through
needleString to find
Return values
ptrFirst match of the search string
NULLNo match, or an error

Definition at line 523 of file string.c.

524{
525 if (!haystack)
526 return NULL;
527 if (!needle)
528 return haystack;
529
530 const char *p = NULL, *q = NULL;
531
532 while (*(p = haystack))
533 {
534 for (q = needle; *p && *q && (mutt_tolower(*p) == mutt_tolower(*q)); p++, q++)
535 {
536 }
537 if ((*q == '\0'))
538 return haystack;
539 haystack++;
540 }
541 return NULL;
542}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_istr_remall()

int mutt_istr_remall ( char * str,
const char * target )

Remove all occurrences of substring, ignoring case.

Parameters
strString containing the substring
targetTarget substring for removal
Return values
0String contained substring and substring was removed successfully
1String did not contain substring

Definition at line 745 of file string.c.

746{
747 int rc = 1;
748 if (!str || !target)
749 return rc;
750
751 // Look through an ensure all instances of the substring are gone.
752 while ((str = (char *) strcasestr(str, target)))
753 {
754 size_t target_len = mutt_str_len(target);
755 memmove(str, str + target_len, 1 + strlen(str + target_len));
756 rc = 0; // If we got here, then a substring existed and has been removed.
757 }
758
759 return rc;
760}
static char * strcasestr(const char *haystack, const char *needle)
Find the first occurrence of needle in haystack, ignoring case.
Definition string.c:58
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_istr_startswith()

size_t mutt_istr_startswith ( const char * str,
const char * prefix )

Check whether a string starts with a prefix, ignoring case.

Parameters
strString to check
prefixPrefix to match
Return values
numLength of prefix if str starts with prefix
0str does not start with prefix

Definition at line 244 of file string.c.

245{
246 return startswith(str, prefix, false);
247}
+ Here is the call graph for this function:

◆ mutt_istrn_cmp()

int mutt_istrn_cmp ( const char * a,
const char * b,
size_t num )

Compare two strings ignoring case (to a maximum), safely.

Parameters
aFirst string to compare
bSecond string to compare
numMaximum number of bytes to compare
Return values
-1a precedes b
0a and b are identical
1b precedes a

Definition at line 441 of file string.c.

442{
443 return strncasecmp(NONULL(a), NONULL(b), num);
444}
+ Here is the caller graph for this function:

◆ mutt_istrn_equal()

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.

Parameters
aFirst string to compare
bSecond string to compare
numMaximum number of bytes to compare
Return values
-1a precedes b
trueFirst num chars of both strings are equal, ignoring case
falseFirst num chars of both strings not equal, ignoring case

Definition at line 455 of file string.c.

456{
457 return strncasecmp(NONULL(a), NONULL(b), num) == 0;
458}
+ Here is the caller graph for this function:

◆ mutt_istrn_rfind()

const char * mutt_istrn_rfind ( const char * haystack,
size_t haystack_length,
const char * needle )

Find last instance of a substring, ignoring case.

Parameters
haystackString to search through
haystack_lengthLength of the string
needleString to find
Return values
NULLString not found
ptrLocation of string

Return the last instance of needle in the haystack, or NULL. Like strcasestr(), only backwards, and for a limited haystack length.

Definition at line 471 of file string.c.

472{
473 if (!haystack || (haystack_length == 0) || !needle)
474 return NULL;
475
476 int needle_length = strlen(needle);
477 const char *haystack_end = haystack + haystack_length - needle_length;
478
479 for (const char *p = haystack_end; p >= haystack; p--)
480 {
481 for (size_t i = 0; i < needle_length; i++)
482 {
483 if ((mutt_tolower(p[i]) != mutt_tolower(needle[i])))
484 goto next;
485 }
486 return p;
487
488 next:;
489 }
490 return NULL;
491}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_str_is_email_wsp()

static bool mutt_str_is_email_wsp ( char c)
inlinestatic

Is this a whitespace character (for an email header)

Parameters
cCharacter to test
Return values
trueIt is whitespace

Definition at line 110 of file string2.h.

111{
112 return (c == ' ') || (c == '\t') || (c == '\r') || (c == '\n');
113}
+ Here is the call graph for this function:
+ Here is the caller graph for this function: