NeoMutt
2025-12-11-1039-g550ac6
Teaching an old dog new tricks
DOXYGEN
Toggle main menu visibility
Loading...
Searching...
No Matches
mapping.c
Go to the documentation of this file.
1
23
29
30
#include "config.h"
31
#include <stddef.h>
32
#include "
mapping.h
"
33
#include "
string2.h
"
34
42
const
char
*
mutt_map_get_name
(
int
val,
const
struct
Mapping
*map)
43
{
44
if
(!map)
45
return
NULL;
46
47
for
(
size_t
i = 0; map[i].
name
; i++)
48
if
(map[i].value == val)
49
return
map[i].
name
;
50
51
return
NULL;
52
}
53
62
int
mutt_map_get_value_n
(
const
char
*name,
size_t
len,
const
struct
Mapping
*map)
63
{
64
if
(!name || (len == 0) || !map)
65
return
-1;
66
67
for
(
size_t
i = 0; map[i].
name
; i++)
68
{
69
if
(
mutt_istrn_equal
(map[i].name, name, len) && (map[i].name[len] ==
'\0'
))
70
{
71
return
map[i].
value
;
72
}
73
}
74
75
return
-1;
76
}
77
85
int
mutt_map_get_value
(
const
char
*name,
const
struct
Mapping
*map)
86
{
87
return
mutt_map_get_value_n
(name,
mutt_str_len
(name), map);
88
}
mutt_map_get_value_n
int mutt_map_get_value_n(const char *name, size_t len, const struct Mapping *map)
Lookup the constant for a string.
Definition
mapping.c:62
mutt_map_get_value
int mutt_map_get_value(const char *name, const struct Mapping *map)
Lookup the constant for a string.
Definition
mapping.c:85
mutt_map_get_name
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition
mapping.c:42
mapping.h
Store links between a user-readable string and a constant.
mutt_str_len
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition
string.c:503
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.
Definition
string.c:457
string2.h
String manipulation functions.
Mapping
Mapping between user-readable string and a constant.
Definition
mapping.h:33
Mapping::value
int value
Integer value.
Definition
mapping.h:35
Mapping::name
const char * name
String value.
Definition
mapping.h:34