-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcstring.cpp
180 lines (165 loc) · 4.22 KB
/
cstring.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/******************************
* Author : YangRongBao
* Date : 2021.4
******************************/
#include "cstring.h"
CString::CString()
{
;
}
CString::~CString()
{
;
}
bool CString::isEmpty()
{
if(this->m_qstring == "")
{
return true;
}
return false;
}
qint16 CString::getSize()
{
return this->m_qstring.size();
}
QString CString::getString()
{
return this->m_qstring;
}
CString::CStringError CString::check(const int index)
{
if(index < 0 || index > this->m_qstring.size() - 1)
{
return Error_NullIndex;
}
QChar targetChar = this->m_qstring[index];
switch (m_checkModel)
{
default:
{
return Error_NullModel;
}
case Model_Account:
{
if(((47 < targetChar) && (targetChar < 58)) || ((64 < targetChar) && (targetChar < 91)) || ((96 < targetChar) && (targetChar < 123)))
{
return Error_None;
}
break;
}
case Model_Password:
{
if(((32 < targetChar) && (targetChar < 91)) || ((96 < targetChar) && (targetChar < 123)))
{
return Error_None;
}
break;
}
case Model_Code:
{
if((31 < targetChar) && (targetChar < 127))
{
return Error_None;
}
break;
}
}
return Error_NullChar;
}
CString::CStringError CString::check(const int beginIndex, const int endIndex)
{
if(beginIndex < 0 || endIndex > this->m_qstring.size() - 1 || beginIndex > endIndex)
{
return Error_NullIndex;
}
for(int i = beginIndex; i <= endIndex; ++i)
{
if(check(beginIndex, endIndex) != Error_None)
{
return Error_NullString;
}
}
return Error_None;
}
CString::CStringError CString::eliminate(const int index)
{
return this->eliminate(index, index);
}
CString::CStringError CString::eliminate(const int beginIndex, const int endIndex)
{
if(beginIndex < 0 || endIndex > this->m_qstring.size() - 1 || beginIndex > endIndex)
{
return Error_NullIndex;
}
QString temporaryString;
for(int i = 0; i < beginIndex; ++i)
{
temporaryString += this->m_qstring[i];
}
for(int i = endIndex + 1; i > endIndex && i < this->m_qstring.size(); ++i)
{
temporaryString += this->m_qstring[i];
}
if(this->m_qstring.size() == temporaryString.size() + (endIndex - beginIndex + 1))
{
this->m_qstring = temporaryString;
return Error_None;
}
return Error_AbortedEliminate;
}
CString::CStringError CString::insert(const int index, const QChar targetChar)
{
QString targetString = QString(targetChar);
return this->insert(index, targetString);
}
CString::CStringError CString::insert(const int index, const QString target)
{
if(index < 0 || index > this->m_qstring.size() - 1)
{
return Error_NullIndex;
}
else if(target == "")
{
return Error_NullString;
}
QString temporaryString;
for(int i = 0; i < index; ++i)
{
temporaryString += this->m_qstring[i];
}
temporaryString += target;
for(int i = index; i < this->m_qstring.size(); ++i)
{
temporaryString += this->m_qstring[i];
}
if(this->m_qstring.size() == temporaryString.size() - target.size())
{
this->m_qstring = temporaryString;
return Error_None;
}
return Error_AbortedInset;
}
CString::CStringError CString::replace(const int index, const QChar targetChar)
{
QString targetString = QString(targetChar);
return this->replace(index, index, targetString);
}
CString::CStringError CString::replace(const int beginIndex, const int endIndex, const QString targetString)
{
CStringError abc = this->eliminate(beginIndex, endIndex);
if(abc == Error_None)
{
return this->insert(beginIndex, targetString);
}
return Error_AbortedReplace;
}
CString::CStringError CString::set(const QString setString)
{
this->m_qstring = setString;
if(this->m_qstring == setString)
{
return Error_None;
}
return Error_AbortedSet;
}