Mon, 17 Jan 2005 22:02:09 +0100
trunk: changeset 1934
Fixed everything that requires locale stuff to check CF_NO_LOCALE.
34 | 1 | /* |
2 | * libtu/map.c | |
3 | * | |
36 | 4 | * Copyright (c) Tuomo Valkonen 1999-2002. |
53 | 5 | * |
6 | * You may distribute and modify this library under the terms of either | |
7 | * the Clarified Artistic License or the GNU LGPL, version 2.1 or later. | |
34 | 8 | */ |
9 | ||
10 | #include <string.h> | |
70 | 11 | #include "map.h" |
34 | 12 | |
13 | ||
14 | int stringintmap_ndx(const StringIntMap *map, const char *str) | |
15 | { | |
16 | int i; | |
62 | 17 | |
18 | for(i=0; map[i].string!=NULL; i++){ | |
19 | if(strcmp(str, map[i].string)==0) | |
20 | return i; | |
21 | } | |
22 | ||
23 | return -1; | |
34 | 24 | } |
25 | ||
51 | 26 | |
27 | int stringintmap_value(const StringIntMap *map, const char *str, int dflt) | |
28 | { | |
29 | int i=stringintmap_ndx(map, str); | |
62 | 30 | return (i==-1 ? dflt : map[i].value); |
51 | 31 | } |
32 | ||
75 | 33 | |
76 | 34 | const char *stringintmap_key(const StringIntMap *map, int value, |
35 | const char *dflt) | |
75 | 36 | { |
37 | int i; | |
38 | ||
39 | for(i=0; map[i].string!=NULL; ++i){ | |
40 | if(map[i].value==value){ | |
41 | return map[i].string; | |
42 | } | |
43 | } | |
44 | ||
45 | return dflt; | |
46 | ||
47 | } |