Sat, 05 Apr 2003 22:32:55 +0200
trunk: changeset 55
stringintmap_value added
34 | 1 | /* |
2 | * libtu/map.c | |
3 | * | |
36 | 4 | * Copyright (c) Tuomo Valkonen 1999-2002. |
34 | 5 | * See the included file LICENSE for details. |
6 | */ | |
7 | ||
8 | #include <string.h> | |
9 | #include <libtu/map.h> | |
10 | ||
11 | ||
12 | int stringintmap_ndx(const StringIntMap *map, const char *str) | |
13 | { | |
14 | int i; | |
15 | ||
16 | for(i=0; map[i].string!=NULL; i++){ | |
17 | if(strcmp(str, map[i].string)==0) | |
51 | 18 | return i; |
34 | 19 | } |
20 | ||
21 | return -1; | |
22 | } | |
23 | ||
51 | 24 | |
25 | int stringintmap_value(const StringIntMap *map, const char *str, int dflt) | |
26 | { | |
27 | int i=stringintmap_ndx(map, str); | |
28 | return (i==-1 ? dflt : map[i].value); | |
29 | } | |
30 |