1 #ifdef _MSC_VER
2 #pragma warning(disable : 4786)
3 #endif
4 
5 
6 #include <ctype.h>
7 #include "utility.h"
8 #include "internal.h"
9 
10 
11 namespace audiere {
12 
ParameterList(const char * parameters)13   ParameterList::ParameterList(const char* parameters) {
14     std::string key;
15     std::string value;
16 
17     std::string* current_string = &key;
18 
19     // walk the string and generate the parameter list
20     const char* p = parameters;
21     while (*p) {
22 
23       if (*p == '=') {
24 
25         current_string = &value;
26 
27       } else if (*p == ',') {
28 
29         if (key.length() && value.length()) {
30           m_values[key] = value;
31         }
32         key   = "";
33         value = "";
34         current_string = &key;
35 
36       } else {
37         *current_string += *p;
38       }
39 
40       ++p;
41     }
42 
43     // is there one more parameter without a trailing comma?
44     if (key.length() && value.length()) {
45       m_values[key] = value;
46     }
47   }
48 
49   std::string
getValue(const std::string & key,const std::string & defaultValue) const50   ParameterList::getValue(
51     const std::string& key,
52     const std::string& defaultValue) const
53   {
54     std::map<std::string, std::string>::const_iterator i = m_values.find(key);
55     return (i == m_values.end() ? defaultValue : i->second);
56   }
57 
58   bool
getBoolean(const std::string & key,bool def) const59   ParameterList::getBoolean(const std::string& key, bool def) const {
60     std::string value = getValue(key, (def ? "true" : "false"));
61     return (value == "true" || atoi(value.c_str()) != 0);
62   }
63 
64   int
getInt(const std::string & key,int def) const65   ParameterList::getInt(const std::string& key, int def) const {
66     char str[20];
67     sprintf(str, "%d", def);
68     return atoi(getValue(key, str).c_str());
69   }
70 
71 
strcmp_case(const char * a,const char * b)72   int strcmp_case(const char* a, const char* b) {
73     while (*a && *b) {
74 
75       char c = tolower(*a++);
76       char d = tolower(*b++);
77 
78       if (c != d) {
79         return c - d;
80       }
81     }
82 
83     char c = tolower(*a);
84     char d = tolower(*b);
85     return (c - d);
86   }
87 
88 
AdrGetSampleSize(SampleFormat format)89   ADR_EXPORT(int) AdrGetSampleSize(SampleFormat format) {
90     switch (format) {
91       case SF_U8:  return 1;
92       case SF_S16: return 2;
93       default:     return 0;
94     }
95   }
96 
97 }
98