blob: 97dc7fa4af91a60a2d8dd4332598268d6151aa7f (
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
|
--- a/snapper/AsciiFile.cc.orig
+++ b/snapper/AsciiFile.cc
@@ -211,7 +211,7 @@
string line = key + "=\"" + value + "\"";
- Regex rx('^' + Regex::ws + key + '=' + "(['\"]?)([^'\"]*)\\1" + Regex::ws + '$');
+ Regex rx('^' + Regex::ws + key + '=' + "(\"[^'\"]*\"|'[^'\"]*'|[^'\"]*)" + Regex::ws + '$');
vector<string>::iterator it = find_if(lines(), regex_matches(rx));
if (it == lines().end())
@@ -226,12 +226,15 @@
bool
SysconfigFile::getValue(const string& key, string& value) const
{
- Regex rx('^' + Regex::ws + key + '=' + "(['\"]?)([^'\"]*)\\1" + Regex::ws + '$');
+ Regex rx('^' + Regex::ws + key + '=' + "(\"[^'\"]*\"|'[^'\"]*'|[^'\"]*)" + Regex::ws + '$');
if (find_if(lines(), regex_matches(rx)) == lines().end())
return false;
- value = rx.cap(2);
+ value = rx.cap(1);
+ if (!value.empty() && (value.front() == '"' || value.front() == '\'')) {
+ value = std::string(value.begin() + 1, value.end() - 1);
+ }
y2mil("key:" << key << " value:" << value);
return true;
}
@@ -295,12 +298,18 @@
{
map<string, string> ret;
- Regex rx('^' + Regex::ws + "([0-9A-Z_]+)" + '=' + "(['\"]?)([^'\"]*)\\2" + Regex::ws + '$');
+ Regex rx('^' + Regex::ws + "([0-9A-Z_]+)" + '=' + "(\"[^'\"]*\"|'[^'\"]*'|[^'\"]*)" + Regex::ws + '$');
for (vector<string>::const_iterator it = Lines_C.begin(); it != Lines_C.end(); ++it)
{
if (rx.match(*it))
- ret[rx.cap(1)] = rx.cap(3);
+ {
+ string value = rx.cap(2);
+ if (!value.empty() && (value.front() == '"' || value.front() == '\'')) {
+ value = std::string(value.begin() + 1, value.end() - 1);
+ }
+ ret[rx.cap(1)] = value;
+ }
}
return ret;
|