NeoMutt  2020-11-20
Teaching an old dog new tricks
DOXYGEN
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 
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 }
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
Store links between a user-readable string and a constant.
int value
Definition: mapping.h:34
String manipulation functions.
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
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition: mapping.c:42
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:631
Mapping between user-readable string and a constant.
Definition: mapping.h:31
const char * name
Definition: mapping.h:33
int mutt_map_get_value(const char *name, const struct Mapping *map)
Lookup the constant for a string.
Definition: mapping.c:85