NeoMutt  2024-10-02-37-gfa9146
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
mapping.c
Go to the documentation of this file.
1
30#include "config.h"
31#include <stddef.h>
32#include "mapping.h"
33#include "string2.h"
34
42const 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
62int 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
85int 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}
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
int mutt_map_get_value(const char *name, const struct Mapping *map)
Lookup the constant for a string.
Definition: mapping.c:85
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition: mapping.c:42
Store links between a user-readable string and a constant.
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:496
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
String manipulation functions.
Mapping between user-readable string and a constant.
Definition: mapping.h:33
int value
Integer value.
Definition: mapping.h:35
const char * name
String value.
Definition: mapping.h:34