9
9
#include " hfile.h"
10
10
#include " hbase.h"
11
11
12
+ using namespace hv ;
13
+
12
14
/* *********************************
13
15
# div
14
16
@@ -29,8 +31,8 @@ class IniNode {
29
31
INI_NODE_TYPE_DIV,
30
32
INI_NODE_TYPE_SPAN,
31
33
} type;
32
- string label; // section|key|comment
33
- string value;
34
+ std:: string label; // section|key|comment
35
+ std:: string value;
34
36
std::list<IniNode*> children;
35
37
36
38
virtual ~IniNode () {
@@ -56,7 +58,7 @@ class IniNode {
56
58
}
57
59
}
58
60
59
- IniNode* Get (const string& label, Type type = INI_NODE_TYPE_KEY_VALUE) {
61
+ IniNode* Get (const std:: string& label, Type type = INI_NODE_TYPE_KEY_VALUE) {
60
62
for (auto pNode : children) {
61
63
if (pNode->type == type && pNode->label == label) {
62
64
return pNode;
@@ -71,22 +73,22 @@ class IniSection : public IniNode {
71
73
IniSection () : IniNode(), section(label) {
72
74
type = INI_NODE_TYPE_SECTION;
73
75
}
74
- string §ion;
76
+ std:: string §ion;
75
77
};
76
78
77
79
class IniKeyValue : public IniNode {
78
80
public:
79
81
IniKeyValue () : IniNode(), key(label) {
80
82
type = INI_NODE_TYPE_KEY_VALUE;
81
83
}
82
- string &key;
84
+ std:: string &key;
83
85
};
84
86
85
87
class IniComment : public IniNode {
86
88
public:
87
89
IniComment () : IniNode(), comment(label) {
88
90
}
89
- string &comment;
91
+ std:: string &comment;
90
92
};
91
93
92
94
IniParser::IniParser () {
@@ -131,11 +133,9 @@ int IniParser::LoadFromMem(const char* data) {
131
133
ss << data;
132
134
std::string strLine;
133
135
int line = 0 ;
134
- string::size_type pos;
136
+ std:: string::size_type pos;
135
137
136
- string content;
137
- string comment;
138
- string strDiv;
138
+ std::string content, comment, strDiv;
139
139
IniNode* pScopeNode = root_;
140
140
IniNode* pNewNode = NULL ;
141
141
while (std::getline (ss, strLine)) {
@@ -151,7 +151,7 @@ int IniParser::LoadFromMem(const char* data) {
151
151
// trim_comment
152
152
comment = " " ;
153
153
pos = content.find_first_of (_comment);
154
- if (pos != string::npos) {
154
+ if (pos != std:: string::npos) {
155
155
comment = content.substr (pos);
156
156
content = content.substr (0 , pos);
157
157
}
@@ -184,7 +184,7 @@ int IniParser::LoadFromMem(const char* data) {
184
184
}
185
185
} else {
186
186
pos = content.find_first_of (_delim);
187
- if (pos != string::npos) {
187
+ if (pos != std:: string::npos) {
188
188
// key-value
189
189
pNewNode = new IniNode;
190
190
pNewNode->type = IniNode::INI_NODE_TYPE_KEY_VALUE;
@@ -218,7 +218,7 @@ int IniParser::LoadFromMem(const char* data) {
218
218
return 0 ;
219
219
}
220
220
221
- void IniParser::DumpString (IniNode* pNode, string& str) {
221
+ void IniParser::DumpString (IniNode* pNode, std:: string& str) {
222
222
if (pNode == NULL ) return ;
223
223
224
224
if (pNode->type != IniNode::INI_NODE_TYPE_SPAN) {
@@ -256,8 +256,8 @@ void IniParser::DumpString(IniNode* pNode, string& str) {
256
256
}
257
257
}
258
258
259
- string IniParser::DumpString () {
260
- string str;
259
+ std:: string IniParser::DumpString () {
260
+ std:: string str;
261
261
DumpString (root_, str);
262
262
return str;
263
263
}
@@ -267,7 +267,7 @@ int IniParser::Save() {
267
267
}
268
268
269
269
int IniParser::SaveAs (const char * filepath) {
270
- string str = DumpString ();
270
+ std:: string str = DumpString ();
271
271
if (str.length () == 0 ) {
272
272
return 0 ;
273
273
}
@@ -281,7 +281,7 @@ int IniParser::SaveAs(const char* filepath) {
281
281
return 0 ;
282
282
}
283
283
284
- string IniParser::GetValue (const string& key, const string& section) {
284
+ std:: string IniParser::GetValue (const std:: string& key, const std:: string& section) {
285
285
if (root_ == NULL ) return " " ;
286
286
287
287
IniNode* pSection = root_;
@@ -296,7 +296,7 @@ string IniParser::GetValue(const string& key, const string& section) {
296
296
return pKV->value ;
297
297
}
298
298
299
- void IniParser::SetValue (const string& key, const string& value, const string& section) {
299
+ void IniParser::SetValue (const std:: string& key, const std:: string& value, const std:: string& section) {
300
300
if (root_ == NULL ) {
301
301
root_ = new IniNode;
302
302
}
@@ -323,35 +323,34 @@ void IniParser::SetValue(const string& key, const string& value, const string& s
323
323
}
324
324
325
325
template <>
326
- HV_EXPORT bool IniParser::Get (const string& key, const string& section, bool defvalue) {
327
- string str = GetValue (key, section);
326
+ HV_EXPORT bool IniParser::Get (const std:: string& key, const std:: string& section, bool defvalue) {
327
+ std:: string str = GetValue (key, section);
328
328
return str.empty () ? defvalue : getboolean (str.c_str ());
329
329
}
330
330
331
331
template <>
332
- HV_EXPORT int IniParser::Get (const string& key, const string& section, int defvalue) {
333
- string str = GetValue (key, section);
332
+ HV_EXPORT int IniParser::Get (const std:: string& key, const std:: string& section, int defvalue) {
333
+ std:: string str = GetValue (key, section);
334
334
return str.empty () ? defvalue : atoi (str.c_str ());
335
335
}
336
336
337
337
template <>
338
- HV_EXPORT float IniParser::Get (const string& key, const string& section, float defvalue) {
339
- string str = GetValue (key, section);
338
+ HV_EXPORT float IniParser::Get (const std:: string& key, const std:: string& section, float defvalue) {
339
+ std:: string str = GetValue (key, section);
340
340
return str.empty () ? defvalue : atof (str.c_str ());
341
341
}
342
342
343
343
template <>
344
- HV_EXPORT void IniParser::Set (const string& key, const bool & value, const string& section) {
344
+ HV_EXPORT void IniParser::Set (const std:: string& key, const bool & value, const std:: string& section) {
345
345
SetValue (key, value ? " true" : " false" , section);
346
346
}
347
347
348
348
template <>
349
- HV_EXPORT void IniParser::Set (const string& key, const int & value, const string& section) {
349
+ HV_EXPORT void IniParser::Set (const std:: string& key, const int & value, const std:: string& section) {
350
350
SetValue (key, asprintf (" %d" , value), section);
351
351
}
352
352
353
353
template <>
354
- HV_EXPORT void IniParser::Set (const string& key, const float & value, const string& section) {
354
+ HV_EXPORT void IniParser::Set (const std:: string& key, const float & value, const std:: string& section) {
355
355
SetValue (key, asprintf (" %f" , value), section);
356
356
}
357
-
0 commit comments