1 /* Copyright (c) 2006-2014 Jonas Fonseca <jonas.fonseca@gmail.com>
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License as
5 * published by the Free Software Foundation; either version 2 of
6 * the License, or (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
15 #include "tig/types.h"
22 string_enum_compare(const char *str1
, const char *str2
, int len
)
26 #define string_enum_sep(x) ((x) == '-' || (x) == '_')
28 /* Diff-Header == DIFF_HEADER */
29 for (i
= 0; i
< len
; i
++) {
30 if (ascii_toupper(str1
[i
]) == ascii_toupper(str2
[i
]))
33 if (string_enum_sep(str1
[i
]) &&
34 string_enum_sep(str2
[i
]))
37 return str1
[i
] - str2
[i
];
44 enum_name_ncopy(char *buf
, size_t bufsize
, const char *name
, size_t namelen
)
48 for (bufpos
= 0; bufpos
<= namelen
&& bufpos
< bufsize
- 1; bufpos
++) {
49 buf
[bufpos
] = ascii_tolower(name
[bufpos
]);
50 if (buf
[bufpos
] == '_')
55 return bufpos
== namelen
+ 1;
59 enum_name_static(const char *name
, size_t namelen
)
61 static char buf
[SIZEOF_STR
];
63 return enum_name_copy(buf
, name
, namelen
) ? buf
: name
;
68 map_enum_do(const struct enum_map_entry
*map
, size_t map_size
, int *value
, const char *name
)
70 size_t namelen
= strlen(name
);
73 for (i
= 0; i
< map_size
; i
++)
74 if (enum_equals(map
[i
], name
, namelen
)) {
75 *value
= map
[i
].value
;
82 #define DEFINE_ENUM_MAPS(name, macro) DEFINE_ENUM_MAP(name, macro);
83 ENUM_INFO(DEFINE_ENUM_MAPS
);
85 /* vim: set ts=8 sw=8 noexpandtab: */