Angus Leeming <[EMAIL PROTECTED]> writes: | #include <string> | #include <iostream> | | using std::string; | | | namespace { | | struct XPMmap { | char const * key; | char const * value; | }; | | | struct CompareKey { | bool operator()(XPMmap const & lhs, XPMmap const & rhs) { | return strcmp(lhs.key, rhs.key) < 0; | }
| bool operator()(XPMmap const & lhs, string const & rhs) { | return strcmp(lhs.key, rhs.c_str()) < 0; | } We have a compare function in lyx::support for this. lstrings.h | }; | | | XPMmap unsorted_xpm_map[] = { | { "(", "lparen" }, | { ")", "rparen"}, | { "[", "lbracket"}, | { "]", "rbracket"}, | { "{", "lbrace"} | }; sort it. | | size_t const xpm_map_size = sizeof(unsorted_xpm_map) / sizeof(XPMmap); | | XPMmap * build_sorted_map() { Check that the map is sorted, and if not assert. (is_sorted in lyx::support somewhere.) This func could go and the check for is sorted moved to find_xpm. | XPMmap * it = unsorted_xpm_map; | XPMmap * end = it + xpm_map_size; | std::sort(it, end, CompareKey()); | return it; | } | | } // namespace anon | | | string const find_xpm(string const & name) | { | static XPMmap const * const begin = build_sorted_map(); and then you won't need this static. | XPMmap const * const end = begin + xpm_map_size; | XPMmap const * const it = | std::lower_bound(begin, end, name, CompareKey()); | | string xpm_name; | if (it != end) | xpm_name = it->value; | else { | // xpm_name = subst(name, "_", "underscore"); | // xpm_name = subst(xpm_name, ' ', '_'); | } | | // lyxerr[Debug::GUI] << "Looking for math XPM called \"" | // << xpm_name << '"' << std::endl; | | // return LibFileSearch("images/math/", xpm_name, "xpm"); | return xpm_name; | } -- Lgb