-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathChildNote.cpp
91 lines (78 loc) · 1.88 KB
/
ChildNote.cpp
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
#include "ChildNote.h"
//#include <iostream>
//using namespace std;
ChildNote::ChildNote()
{
Name.clear();
Value.clear();
}
ChildNote::~ChildNote()
{
clear();
}
string ChildNote::get_string(string::iterator begin, string::iterator end)
{
//string get_string(string::iterator begin, string::iterator end)
string s="";
for (; begin != end; begin++)
s += *begin;
//cout << s << endl;
return s;
}
string ChildNote::get_child_note(string& str) //获取 ' '里的内容
{
string::iterator p = str.begin();
for (; p!=str.end()&&*p != '\''; p++);
str = get_string(p, str.end());
if (str == "")return "";
string::iterator p0 = str.begin();
string::iterator p1 = p0 + 1;
while (p1!=str.end()&&*p1 != '\'') p1 = p1 + 1;
if (p1 == str.end())throw 1;//如果只有一个',就抛出异常
string s;
for (string::iterator p = p0 + 1; p != p1; p++) s += *p;
str = get_string(p1 + 1,str.end());
return s;
/*const char* p = str.c_str();
for (; *p != '\''; p++);
str = p;
const char* p0 = str.c_str();
const char* p1 = p0 + 1;
while (*p1 != '\'') p1 = p1 + 1;
string s;
for (const char* p = p0 + 1; p != p1; p++) s += *p;
str = (p1 + 1);
return s;*/
}
void ChildNote::set_note(string str)
{
if (Name.size() == 0 && Value.size() == 0)
{
for (int i = 0; i < 2; i++)
{
string note = get_child_note(str);
if (note == "name")
{
const char* Pstr = str.c_str();
for (; *Pstr != '\''; Pstr++);
str = Pstr;
Name = get_child_note(str);
}
if (note == "value")
{
const char* Pstr = str.c_str();
for (; *Pstr != '\''; Pstr++);
str = Pstr;
Value = get_child_note(str);
}
note.clear();
const char* Pstr = str.c_str();
for (; *Pstr != '\''; Pstr++);
str = Pstr;
}
}
}
bool ChildNote::same_name(const ChildNote& nChildNote)const
{
return nChildNote.Name == Name;
}