ia2utils.cpp
1.45 KB
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
/*
This file is a part of the NVDA project.
URL: http://www.nvda-project.org/
Copyright 2006-2010 NVDA contributers.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2.0, as published by
the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
This license can be found at:
http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
#include <string>
#include <map>
using namespace std;
void IA2AttribsToMap(const wstring &attribsString, map<wstring, wstring> &attribsMap) {
wstring str, key;
bool inEscape = false;
for (wstring::const_iterator it = attribsString.begin(); it != attribsString.end(); it++) {
if (inEscape) {
str.push_back(*it);
inEscape = false;
} else if (*it == L'\\') {
inEscape = true;
} else if (*it == L':') {
// We're about to move on to the value, so save the key and clear str.
key = str;
str.clear();
} else if (*it == L';') {
// We're about to move on to a new attribute.
// Add this key/value pair to the map.
if (!key.empty())
attribsMap[key] = str;
key.clear();
str.clear();
} else {
str.push_back(*it);
}
}
// If there was no trailing semi-colon, we need to handle the last attribute.
if (!key.empty())
attribsMap[key] = str;
}