-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmystring.h
283 lines (242 loc) · 6.26 KB
/
mystring.h
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#pragma once
#include<vector>
#include"basedefine.h"
#ifdef MY_STEING
#error has been defined 'MY_STRING'
#endif
#define MY_STRING
#define DEFAULT_END_CHAR '\0'
#define NEW_STRING(strptr,len) strptr=new char[len+1];strptr[len]='\0';
#define DEFAULT_END_STRARR nullptr
#define DEFAULT_DIV_CHAR ' '
#define LINE_END_CHAR '\n'
#define CLONE_STRING(str) CloneStr(str)
#define NEW_STRING_ARRAY(arrptr,len) arrptr=new char*[len+1];arrptr[len]=nullptr;
#define DEFAULT_LEN_ADD 1024
#define DEFAULT_LEN_CONSTOR 1024
#define STRING_TYPE_NOT_NUMBER 0x0
#define STRING_TYPE_NAGETIVE 0x01
#define STRING_TYPE_INTEGER 0x02
#define STRING_TYPE_FLOAT 0x04
using namespace My3D;
namespace MyTool
{
typedef char** StrArr; //the array of the string(char*)
class MyString;
class MyStringVector;
/*
fun:get the StrArr's length
*/
_uint StrArrLen(StrArr);
/*
delete all the arr which make by before
*/
void FreeStrArr(const StrArr arr);
/*
@autor mr.yi
fun:clone a string from 'str'
arg:
str:a string
return:
the clone string
*/
char* CloneStr(const char*str);
/*
@atuor mr.yi
fun:
to compare two string is equal or not
arg:
str1: a compare string
str2: a compare string
return:
if str1==str2 return true
else return false
*/
bool StrEqual(const char* str1, const char* str2);
/*
@atuor mr.yi
fun:
to get the string length
arg:
str: a string
return:
the str's length with default end char'\0'
*/
_uint StrLen(const char*str);
/*
@atuor mr.yi
fun: to get the string length
arg:
str: a string that you want to get it's length
endChar: a char to end with 'str'
return:
the str's length with the end char 'endChar'
*/
_uint StrLen(const char*str,char endChar);
/*
@autor mr.yi
fun: get the destination string's position
arg:
sourcStr: the source of the string
dastStr: the destination of the string
return:
the array place(begin with 0) that the dastStr in sourcStr,
if can't find it,return arg is -1
*/
int FindStr(const char*sourcStr, const char*destStr);
/*
@autor mr.yi
fun:fin the 'desStr' postion from 'sourceStr' ,begin with 'begin', end with 'end'
arg:
sourceStr:the source string
destStr:the destion string
bein: find begin with 'begin'
end:find end with 'end'
return:
the 'destStr' postion
*/
int FindStr(_uint begin, _uint end, const char* sourceStr, const char* destStr);
/*
@autor mr.yi
fun:to change some string with anthor string
arg:
sourceStr: the source string
destStr: the destination string that it should find
replaStr: the string that you want to it is the target
return:
the new string
*/
char* ReplaceStr(const char* sourceStr,const char* destStr,const char* replaStr);
/*
@autor mr.yi
fun:to cut the empty char
arg:
sourceStr:the source of the string
return:
the new string
*/
char* Trim(const char* sourceStr);
/*
@autor mr.yi
fun:to get a string witch is from begin position to end position
arg:
sourceStr:ths source of the string
begin:the cut begin position
end:the end begin position
return:
a string form begin to end
*/
char* SubStr(const char* sourceStr, _uint begin, _uint end);
/*
fun:get the string number type
*/
_byte GetStringNumberType(const char*str);
/*
fun:translate string to float,maybe cuse the data lose
*/
float Stof(const char*str);
/*
fun:translate string to in
*/
int Stoi(const char* str);
/*
fun:split the string witht the divchar,get a string array
*/
StrArr Split(const char* str, char divChar);
StrArr GetStrArr(std::vector<char*>&arg);
/*
@autor mr.yi
a class for the string ,just have some simple function
*/
class MyString
{
private:
char* data;
_uint length;
public:
MyString();
MyString(const char*str);
MyString(MyString&str);
MyString(MyStringVector&str);
virtual ~MyString();
void operator=(const char*str);
void operator=(MyString&str);
void operator=(MyStringVector&str);
bool operator==(MyStringVector&str);
bool operator==(MyString&str);
bool operator==(const char*str);
char& operator[](_uint nb);
/*
return the char array's ptr
*/
char* C_Str();
_uint Length();
char* subStr(_uint begin, _uint end);
int findStr(const char*str);
int findStr(_uint begin, _uint end, const char*str);
char* replaceStr(const char* destStr, const char* replaStr);
char* trim();
char* clone();
StrArr split(char divChar);
};
/*
@autor mr.yi
fun: the plus for the class 'MyString',it can do some add memroy operator
*/
class MyStringVector
{
private:
char* data;
_uint strLen;// the length of string
_uint memoryLen;//the length of the memory
_uint addLen;//the length of the add once length while the memory can't save the add string
_uint cnstorLen;//while the class constor ,it will make cnstorLen size memory
/*
//while you out the str,it while dived this string
like:
MyStringVector vt("fuck the world");
MyString str1;
MyString str2;
MyString str3;
//if you set the divChar=' '
vt>>str1>>str2>>str3;
//the str1 =="fuck", str2=="the",str3=="world"
*/
char divChar;
public:
MyStringVector();
MyStringVector(const char*str);
MyStringVector(MyString&str);
MyStringVector(MyStringVector&strv);
MyStringVector(_uint addLen, _uint cnstorLen);
virtual ~MyStringVector();
MyStringVector& operator<<(const char*str);
MyStringVector& operator<<(MyString&str);
MyStringVector& operator<<(MyStringVector&strv);
MyStringVector& operator<<(char ch);
MyStringVector& operator>>(char*str);
MyStringVector& operator>>(MyString&str);
MyStringVector& operator>>(MyStringVector&strv);
MyStringVector& operator>>(int &arg);
MyStringVector& operator>>(float&arg);
MyStringVector& operator>>(char &ch);
bool operator==(MyString&str);
bool operator==(const char*str);
bool operator==(MyStringVector&strv);
void operator=(const char*str);
void operator=(MyString&str);
void operator=(MyStringVector&str);
char& operator[](_uint nb);
void SetDivChar(char divChar);
void Clear();
char* C_Str();
_uint Length();
char* subStr(_uint begin, _uint end);
int findStr(const char*str);
int findStr(_uint begin, _uint end, const char*str);
char* replaceStr(const char* destStr, const char* replaStr);
char* trim();
char* clone();
StrArr split();
};
}