From 8fabcf4f760e68e10573efc0ef1da9d6d8453885 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 2 Jan 2007 17:36:38 +0000 Subject: finish use of EnumWriter for saving flags etc. throughout the session file git-svn-id: svn://localhost/ardour2/trunk@1259 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/pbd/enumwriter.cc | 71 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 68 insertions(+), 3 deletions(-) (limited to 'libs/pbd/enumwriter.cc') diff --git a/libs/pbd/enumwriter.cc b/libs/pbd/enumwriter.cc index d6c882e00a..7674410ec9 100644 --- a/libs/pbd/enumwriter.cc +++ b/libs/pbd/enumwriter.cc @@ -18,6 +18,9 @@ $Id$ */ +#include + +#include #include #include @@ -30,6 +33,35 @@ using namespace PBD; #include "i18n.h" EnumWriter* EnumWriter::_instance = 0; +map EnumWriter::hack_table; + +static int +nocase_cmp(const string & s1, const string& s2) +{ + string::const_iterator it1 = s1.begin(); + string::const_iterator it2 = s2.begin(); + + while ((it1 != s1.end()) && (it2 != s2.end())) { + if(::toupper(*it1) != ::toupper(*it2)) {//letters differ? + // return -1 to indicate 'smaller than', 1 otherwise + return (::toupper(*it1) < ::toupper(*it2)) ? -1 : 1; + } + + ++it1; + ++it2; + } + + string::size_type size1 = s1.size(); + string::size_type size2 = s2.size(); + + //return -1,0 or 1 according to strings' lengths + + if (size1 == size2) { + return 0; + } + + return (size1 < size2) ? -1 : 1; +} EnumWriter::EnumWriter () { @@ -157,13 +189,19 @@ EnumWriter::read_bits (EnumRegistration& er, string str) return strtol (str.c_str(), (char **) 0, 16); } + /* catch old style dec numerics */ + + if (strspn (str.c_str(), "0123456789") == str.length()) { + return strtol (str.c_str(), (char **) 0, 10); + } + do { comma = str.find_first_of (','); string segment = str.substr (0, comma); for (i = er.values.begin(), s = er.names.begin(); i != er.values.end(); ++i, ++s) { - if (segment == (*s)) { + if (segment == *s || nocase_cmp (segment, *s) == 0) { result |= (*i); found = true; } @@ -196,13 +234,40 @@ EnumWriter::read_distinct (EnumRegistration& er, string str) return strtol (str.c_str(), (char **) 0, 16); } + /* catch old style dec numerics */ + + if (strspn (str.c_str(), "0123456789") == str.length()) { + return strtol (str.c_str(), (char **) 0, 10); + } + for (i = er.values.begin(), s = er.names.begin(); i != er.values.end(); ++i, ++s) { - if (str == (*s)) { + if (str == (*s) || nocase_cmp (str, *s) == 0) { return (*i); } } + /* failed to find it as-is. check to see if there a hack for the name we're looking up */ + + map::iterator x; + + if ((x = hack_table.find (str)) != hack_table.end()) { + + cerr << "found hack for " << str << " = " << x->second << endl; + + str = x->second; + + for (i = er.values.begin(), s = er.names.begin(); i != er.values.end(); ++i, ++s) { + if (str == (*s) || nocase_cmp (str, *s) == 0) { + return (*i); + } + } + } + throw unknown_enumeration(); } - +void +EnumWriter::add_to_hack_table (string str, string hacked) +{ + hack_table[str] = hacked; +} -- cgit v1.2.3