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