Thanks to visit codestin.com
Credit goes to code.neomutt.org

NeoMutt  2025-12-11-189-gceedb6
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
  • Thomas Klausner

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 42 of file string2.h.

◆ NONULL

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

Definition at line 44 of file string2.h.

◆ S_ERR

#define S_ERR   127

Definition at line 47 of file string2.h.

◆ S_BKG

#define S_BKG   126

Definition at line 48 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:96

Definition at line 52 of file string2.h.

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

◆ terminate_string

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

Definition at line 56 of file string2.h.

56#define terminate_string(str, strlen, buflen) \
57 (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:56

Definition at line 59 of file string2.h.

59#define terminate_buffer(str, strlen) \
60 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 933 of file string.c.

934{
935 const char **str = NULL;
936 ARRAY_FOREACH(str, arr)
937 {
938 FREE(str);
939 }
940
941 ARRAY_FREE(arr);
942}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
#define ARRAY_FREE(head)
Release all memory.
Definition array.h:209
#define FREE(x)
Definition memory.h:63
+ 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 303 of file string.c.

304{
305 if (!ptr || !*ptr)
306 return;
307 MUTT_MEM_REALLOC(ptr, strlen(*ptr) + 1, char);
308}
#define MUTT_MEM_REALLOC(pptr, n, type)
Definition memory.h:51
+ 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 513 of file string.c.

514{
515 return strcoll(NONULL(a), NONULL(b));
516}
#define NONULL(x)
Definition string2.h:44
+ 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 708 of file string.c.

709{
710 if (!src)
711 return NULL;
712
713 while (*src && strchr(" \t\n", *src))
714 src++;
715 while (*src && !strchr(" \t\n", *src))
716 src++;
717 return src;
718}
+ 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 728 of file string.c.

729{
730 if (!name)
731 return NULL;
732
733 const char *val = getenv(name);
734 if (val && (val[0] != '\0'))
735 return val;
736
737 return NULL;
738}
+ 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 851 of file string.c.

852{
853 if (!buf || (buflen == 0) || !str)
854 return;
855
856 mutt_str_copy(buf, str, buflen);
857 for (; *buf != '\0'; buf++)
858 {
859 if (*buf == '_')
860 *buf = '-';
861 }
862}
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:583
+ 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 685 of file string.c.

686{
687 if (!str)
688 return true;
689
690 for (; (*str != '\0') && (len > 0); str++, len--)
691 if ((*str & 0x80) != 0)
692 return false;
693
694 return true;
695}
+ 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 500 of file string.c.

501{
502 return a ? strlen(a) : 0;
503}

◆ 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 317 of file string.c.

318{
319 if (!str)
320 return NULL;
321
322 char *p = str;
323
324 while (*p)
325 {
326 *p = mutt_tolower(*p);
327 p++;
328 }
329
330 return str;
331}
int mutt_tolower(int arg)
Wrapper for tolower(3)
Definition ctype.c:126
+ 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 630 of file string.c.

631{
632 if (!s)
633 return 0;
634
635 const char *p = s;
636 size_t len = n;
637
638 if (n == 0)
639 return 0;
640
641 for (; p < (s + n); p++)
642 {
643 if (!strchr(" \t\r\n", *p))
644 {
645 len = p - s;
646 break;
647 }
648 }
649
650 if ((len != 0) && strchr("\r\n", *(p - 1))) /* LWS doesn't end with CRLF */
651 len = 0;
652 return len;
653}
+ 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 567 of file string.c.

568{
569 if (!s)
570 return;
571
572 for (char *p = s + mutt_str_len(s) - 1; (p >= s) && mutt_isspace(*p); p--)
573 *p = '\0';
574}
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition string.c:500
+ 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 284 of file string.c.

285{
286 if (!p)
287 return NULL;
288 const char *tmp = *p;
289 *p = mutt_str_dup(s);
290 FREE(&tmp);
291 return *p;
292}
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition string.c:257
+ 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 190 of file string.c.

191{
192 if (!stringp || !*stringp || !delim)
193 return NULL;
194 return strsep(stringp, delim);
195}
static char * strsep(char **stringp, const char *delim)
Extract a token from a string.
Definition string.c:86
+ 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 610 of file string.c.

611{
612 if (!s)
613 return NULL;
614
615 for (; mutt_str_is_email_wsp(*s); s++)
616 ; // Do nothing
617
618 return (char *) s;
619}
static bool mutt_str_is_email_wsp(char c)
Is this a whitespace character (for an email header)
Definition string2.h:111
+ 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 553 of file string.c.

554{
555 if (!p)
556 return NULL;
557 SKIPWS(p);
558 return (char *) p;
559}
#define SKIPWS(ch)
Definition string2.h:52
+ 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 173 of file string.c.

174{
175 for (size_t i = 0; i < countof(SysExits); i++)
176 {
177 if (err_num == SysExits[i].err_num)
178 return SysExits[i].err_str;
179 }
180
181 return NULL;
182}
#define countof(x)
Definition memory.h:45
Lookup table of error messages.
Definition string.c:113
const char * err_str
Human-readable string for error.
Definition string.c:115
+ 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 340 of file string.c.

341{
342 if (!str)
343 return NULL;
344
345 char *p = str;
346
347 while (*p)
348 {
349 *p = mutt_toupper(*p);
350 p++;
351 }
352
353 return str;
354}
int mutt_toupper(int arg)
Wrapper for toupper(3)
Definition ctype.c:140
+ 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 403 of file string.c.

404{
405 return strcmp(NONULL(a), NONULL(b));
406}
+ 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 583 of file string.c.

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

◆ 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 257 of file string.c.

258{
259 if (!str || (*str == '\0'))
260 return NULL;
261
262 char *p = strdup(str);
263 if (!p)
264 {
265 mutt_error("%s", strerror(errno)); // LCOV_EXCL_LINE
266 mutt_exit(1); // LCOV_EXCL_LINE
267 }
268 return p;
269}
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition exit.c:41
#define mutt_error(...)
Definition logging2.h:94
+ 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 662 of file string.c.

663{
664 return (a == b) || (mutt_str_cmp(a, b) == 0);
665}
int mutt_str_cmp(const char *a, const char *b)
Compare two strings, safely.
Definition string.c:403
+ 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 234 of file string.c.

235{
236 return startswith(str, prefix, true);
237}
static size_t startswith(const char *str, const char *prefix, bool match_case)
Check whether a string starts with a prefix.
Definition string.c:205
+ 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 364 of file string.c.

365{
366 if (!src || !dest || (len == 0) || (dsize == 0))
367 return dest;
368
369 if (len > (dsize - 1))
370 len = dsize - 1;
371 memcpy(dest, src, len);
372 dest[len] = '\0';
373 return dest;
374}
+ 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 384 of file string.c.

385{
386 if (!begin)
387 return NULL;
388
389 char *p = MUTT_MEM_MALLOC(len + 1, char);
390 memcpy(p, begin, len);
391 p[len] = '\0';
392 return p;
393}
#define MUTT_MEM_MALLOC(n, type)
Definition memory.h:49
+ 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 429 of file string.c.

430{
431 return strncmp(NONULL(a), NONULL(b), num) == 0;
432}
+ 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 416 of file string.c.

417{
418 return strcasecmp(NONULL(a), NONULL(b));
419}
+ 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 674 of file string.c.

675{
676 return (a == b) || (mutt_istr_cmp(a, b) == 0);
677}
int mutt_istr_cmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition string.c:416
+ 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 525 of file string.c.

526{
527 if (!haystack)
528 return NULL;
529 if (!needle)
530 return haystack;
531
532 const char *p = NULL, *q = NULL;
533
534 while (*(p = haystack))
535 {
536 for (q = needle; *p && *q && (mutt_tolower(*p) == mutt_tolower(*q)); p++, q++)
537 {
538 }
539 if ((*q == '\0'))
540 return haystack;
541 haystack++;
542 }
543 return NULL;
544}
+ 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 747 of file string.c.

748{
749 int rc = 1;
750 if (!str || !target)
751 return rc;
752
753 // Look through an ensure all instances of the substring are gone.
754 while ((str = (char *) strcasestr(str, target)))
755 {
756 size_t target_len = mutt_str_len(target);
757 memmove(str, str + target_len, 1 + strlen(str + target_len));
758 rc = 0; // If we got here, then a substring existed and has been removed.
759 }
760
761 return rc;
762}
static char * strcasestr(const char *haystack, const char *needle)
Find the first occurrence of needle in haystack, ignoring case.
Definition string.c:60
+ 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 246 of file string.c.

247{
248 return startswith(str, prefix, false);
249}
+ 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 443 of file string.c.

444{
445 return strncasecmp(NONULL(a), NONULL(b), num);
446}
+ 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 457 of file string.c.

458{
459 return strncasecmp(NONULL(a), NONULL(b), num) == 0;
460}
+ 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 473 of file string.c.

474{
475 if (!haystack || (haystack_length == 0) || !needle)
476 return NULL;
477
478 int needle_length = strlen(needle);
479 const char *haystack_end = haystack + haystack_length - needle_length;
480
481 for (const char *p = haystack_end; p >= haystack; p--)
482 {
483 for (size_t i = 0; i < needle_length; i++)
484 {
485 if ((mutt_tolower(p[i]) != mutt_tolower(needle[i])))
486 goto next;
487 }
488 return p;
489
490 next:;
491 }
492 return NULL;
493}
+ 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 111 of file string2.h.

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