/[cvs]/api/Classes/String/String.h
ViewVC logotype

Contents of /api/Classes/String/String.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (vendor branch)
Sun Jul 1 20:47:58 2001 UTC (23 years, 4 months ago) by bearsoft
Branch: lazy, MAIN
CVS Tags: start, HEAD
Changes since 1.1: +0 -0 lines
File MIME type: text/plain
First import

1 #ifndef __String_H__
2 #define __String_H__
3
4 #include "../NetWork/NetWorkTools.h"
5 #include "Parse.h"
6 #include "StringTools.h"
7 #include "NewRow.h"
8 #include "../Files/FileTools.h"
9 #include "../DateTime/DateTime.h"
10 #include "../System/SystemDefine.h"
11 #include <iostream>
12
13 class String
14 {
15
16 public:
17
18 String()
19 {
20 buffer=null;
21 length=0;
22 }
23
24 String(const DateTime &dateTime)
25 {
26 char *tempBuffer=dateTime.buffer;
27 buffer=tempBuffer;
28 int tempLength=dateTime.length;
29 length=tempLength;
30 }
31
32 String(float value)
33 {
34 Parse parse;
35 buffer=parse.floatToString(value, &length);
36 }
37
38 String(int value)
39 {
40 Parse parse;
41
42 buffer=parse.intToString(value, &length);
43 }
44
45 String(const NewRow &newRow)
46 {
47 buffer=null;
48 char tempCharacter[3]={10,0};
49 setString(tempCharacter, 1);
50 }
51
52 String(char *iBuffer)
53 {
54 buffer=null;
55 setString(iBuffer);
56 }
57
58 String(const char &iBuffer)
59 {
60 buffer=null;
61 setString((char*)iBuffer);
62 }
63
64 String(const String &string)
65 {
66 buffer=null;
67 setString((char*)string.buffer, string.length);
68 }
69
70 String(String *string)
71 {
72 buffer=null;
73 setString((char*)string->buffer, string->length);
74 }
75
76 String(int intValue, char *buffer2, int buffer2Length)
77 {
78 Parse parse;
79 StringTools stringTools;
80
81 if (buffer2!=null)
82 {
83 char *tempBuffer=parse.intToString(intValue, &length);
84 buffer=stringTools.addStringTwoString((char*)buffer2, buffer2Length, (char*)tempBuffer, length);
85 length+=buffer2Length;
86 free(tempBuffer);
87 }
88 else
89 {
90 buffer=parse.intToString(intValue, &length);
91 }
92 }
93
94 String(float floatValue, char *buffer2, int buffer2Length)
95 {
96 Parse parse;
97 StringTools stringTools;
98
99 if (buffer2!=null)
100 {
101 char *tempBuffer=parse.floatToString(floatValue, &length);
102 buffer=stringTools.addStringTwoString((char*)buffer2, buffer2Length, (char*)tempBuffer, length);
103 length+=buffer2Length;
104 free(tempBuffer);
105 }
106 else
107 {
108 buffer=parse.floatToString(floatValue, &length);
109 }
110 }
111
112 String(const NewRow &newRow, char *buffer2, int buffer2Length)
113 {
114 StringTools stringTools;
115
116 if (buffer2!=null)
117 {
118 char tempCharacter[2]={10,0};
119 buffer=stringTools.addStringTwoString((char*)buffer2, buffer2Length, (char*)tempCharacter, 1);
120 length=buffer2Length + 1;
121 }
122 else
123 {
124 buffer=null;
125 char tempCharacter[2]={10,0};
126 setString(tempCharacter, 1);
127 }
128 }
129
130 String(char *iBuffer, int iBufferLength, char *iBuffer2, int iBuffer2Length)
131 {
132 StringTools stringTools;
133
134 if (iBuffer!=null && iBuffer2!=null)
135 {
136 buffer=stringTools.addStringTwoString((char*)iBuffer2, iBuffer2Length, (char*)iBuffer, iBufferLength);
137 length=iBufferLength+iBuffer2Length;
138 }
139 else
140 {
141 buffer=null;
142 bool statement=false;
143
144 if (iBuffer!=null)
145 {
146 setString(iBuffer, iBufferLength);
147 statement=true;
148 }
149
150 if (iBuffer2!=null)
151 {
152 setString(iBuffer2, iBuffer2Length);
153 statement=true;
154 }
155
156 if (!statement)
157 {
158 buffer=null;
159 length=0;
160 }
161 }
162
163 }
164
165 ~String()
166 {
167 if ( buffer != null )
168 {
169 free(buffer);
170 }
171 }
172
173 String operator+(int value)
174 {
175 return String(value, (char*)buffer, length);
176 }
177
178 String operator+(float value)
179 {
180 return String(value, (char*)buffer, length);
181 }
182
183 String operator+(const String &string)
184 {
185 return String((char*)string.buffer, string.length, (char*)buffer, length);
186 }
187
188 String operator+(String *string)
189 {
190 return String((char*)string->buffer, string->length, (char*)buffer, length);
191 }
192
193 String operator+(char* iBuffer)
194 {
195 StringTools stringTools;
196
197 return String((char*)iBuffer, stringTools.sizeOfStringWithOutEndNull(iBuffer), (char*)buffer, length);
198 }
199
200 String operator+(const NewRow &newRow)
201 {
202 return String(newRow, (char*)buffer, length);
203 }
204
205 String operator+(const char &iBuffer)
206 {
207 StringTools stringTools;
208
209 return String((char*)iBuffer, stringTools.sizeOfStringWithOutEndNull((char*)iBuffer), (char*)buffer, length);
210 }
211
212 void operator+=(int intValue)
213 {
214 Parse parse;
215 StringTools stringTools;
216
217
218 if (buffer!=null)
219 {
220 char *tBuffer=buffer;
221 int intLength=0;
222 char *tempBuffer=parse.intToString(intValue, &intLength);
223 buffer=stringTools.addStringTwoString((char*)buffer, length, (char*)tempBuffer, intLength);
224 length+=intLength;
225 free(tempBuffer);
226 free(tBuffer);
227 }
228 else
229 {
230 buffer=parse.intToString(intValue, &length);
231 }
232 }
233
234 void operator+=(float floatValue)
235 {
236 Parse parse;
237 StringTools stringTools;
238
239 if (buffer!=null)
240 {
241 char *tBuffer=buffer;
242 int floatLength=0;
243 char *tempBuffer=parse.floatToString(floatValue, &floatLength);
244 buffer=stringTools.addStringTwoString((char*)buffer, length, (char*)tempBuffer, floatLength);
245 length+=floatLength;
246 free(tempBuffer);
247 free(tBuffer);
248 }
249 else
250 {
251 buffer=parse.floatToString(floatValue, &length);
252 }
253 }
254
255 void operator+=(const String &string)
256 {
257 copyBuffer(string.buffer, string.length);
258 }
259
260 void operator+=(String * string)
261 {
262 copyBuffer(string->buffer, string->length);
263 }
264
265 void operator+=(char* iBuffer)
266 {
267 StringTools stringTools;
268
269 copyBuffer(iBuffer, stringTools.sizeOfStringWithOutEndNull(iBuffer));
270 }
271
272 void copyBuffer(char *iBuffer, int iBufferLength)
273 {
274 StringTools stringTools;
275
276 if (buffer!=null)
277 {
278 if (iBuffer != null )
279 {
280 char *tBuffer=buffer;
281 buffer=stringTools.addStringTwoString((char*)buffer, length, (char*)iBuffer, iBufferLength);
282 length+=iBufferLength;
283 free(tBuffer);
284 }
285 }
286 else
287 {
288 if (iBuffer != null)
289 {
290 setString(iBuffer, iBufferLength);
291 }
292 }
293 }
294
295 void operator+=(const NewRow &newRow)
296 {
297 StringTools stringTools;
298
299 if (buffer!=null)
300 {
301 char *tBuffer=buffer;
302 char tempCharacter[2]={10,0};
303 buffer=stringTools.addStringTwoString((char*)buffer, length, (char*)tempCharacter, 1);
304 length=1;
305 free(tBuffer);
306 }
307 else
308 {
309 char tempCharacter[2]={10,0};
310 setString(tempCharacter, 1);
311 }
312 }
313
314 void operator+=(const char character)
315 {
316 StringTools stringTools;
317
318 if (buffer!=null)
319 {
320 char *tBuffer=buffer;
321 char tempCharacter[2]={0,0};
322 tempCharacter[0]=character;
323 buffer=stringTools.addStringTwoString((char*)buffer, length, (char*)tempCharacter, 1);
324 length=1;
325 free(tBuffer);
326 }
327 else
328 {
329 char tempCharacter[2]={0,0};
330 tempCharacter[0]=character;
331 setString(tempCharacter, 1);
332 }
333 }
334
335 void removeCharacter(int index)
336 {
337 if (index >= 0 && index < length )
338 {
339 --length;
340
341 if (length > 0)
342 {
343 for ( int i=0; i<length ; i++ )
344 {
345 if ( i >= index )
346 {
347 buffer[i]=buffer[i+1];
348 }
349 }
350 }
351 else
352 {
353 if (buffer!=null)
354 {
355 free(buffer);
356 buffer=null;
357 }
358 }
359 }
360 }
361
362 void replaceCharacter(const char replace, const char remove)
363 {
364 if (buffer!=null)
365 {
366 for ( int i=0; i<length ; i++ )
367 {
368 if (buffer[i]==remove)
369 {
370 buffer[i]=replace;
371 }
372 }
373 }
374 }
375
376 int toInt()
377 {
378 Parse parse;
379
380 return parse.stringToInt(buffer);
381 }
382
383 float toFloat()
384 {
385 Parse parse;
386
387 return parse.stringToFloat(buffer);
388 }
389
390 bool equals(const String &string)
391 {
392 StringTools stringTools;
393
394 return stringTools.compareString(buffer, string.buffer);
395 }
396
397 bool equals(char *iBuffer)
398 {
399 StringTools stringTools;
400
401 return stringTools.compareString(buffer, iBuffer);
402 }
403
404 void setString(const String &string)
405 {
406 setString(string.buffer, string.length);
407 }
408
409 void setString(String *string)
410 {
411 if (string!=null)
412 {
413 setString(string->buffer, string->length);
414 }
415 }
416
417 void setString(char *iBuffer)
418 {
419 StringTools stringTools;
420
421 if (buffer!=null)
422 {
423 free(buffer);
424 buffer=null;
425 }
426
427 if (iBuffer != null)
428 {
429 length=stringTools.sizeOfStringWithOutEndNull(iBuffer);
430 buffer=(char*)malloc((sizeof(char)*length)+sizeof(char));
431 stringTools.copyString(iBuffer, length, buffer);
432 }
433 }
434
435 void setString(char *iBuffer, int iBufferLength)
436 {
437 StringTools stringTools;
438
439 if (buffer!=null)
440 {
441 free(buffer);
442 buffer=null;
443 }
444
445 if (iBuffer != null)
446 {
447 length=iBufferLength;
448 buffer=(char*)malloc(sizeof(char)*length+sizeof(char));
449 stringTools.copyString(iBuffer, length, buffer);
450 }
451 }
452
453 void cutTheBack(char character)
454 {
455 StringTools stringTools;
456
457 buffer=stringTools.cutTheBack(buffer, &length, character);
458 }
459
460 void cutTheBegining(char character)
461 {
462 StringTools stringTools;
463
464 buffer=stringTools.cutTheBegining(buffer, &length, character);
465 }
466
467 int socketSend(int socket)
468 {
469 NetWorkTools netWorkTools;
470 return netWorkTools.sendData(socket,buffer,length);
471 }
472
473 bool isBackPartEqualTo(char *fileFormat)
474 {
475 StringTools stringTools;
476
477 return stringTools.checkBack(buffer,length,fileFormat,stringTools.sizeOfStringWithOutEndNull(fileFormat));
478 }
479
480 bool isFrontPartEqualTo(char *fileFormat)
481 {
482 StringTools stringTools;
483
484 return stringTools.checkFront(buffer, length, fileFormat, stringTools.sizeOfStringWithOutEndNull(fileFormat));
485 }
486
487 int writeToFile(const String &fileName)
488 {
489 return writeToFile(fileName.buffer);
490 }
491
492 int writeToFileEnd(const String &fileName)
493 {
494 return writeToFileEnd(fileName.buffer);
495 }
496
497 int writelnToFileEnd(const String &fileName)
498 {
499 StringTools stringTools;
500
501 int fileStatus=0;
502
503 if (buffer!=null)
504 {
505 char tempCharacter[2]={10,0};
506 char *newBuffer=stringTools.addStringTwoString((char*)buffer, length, (char*)tempCharacter, 1);
507 fileStatus=writeToFileEnd(fileName.buffer,newBuffer, length+1);
508 free(newBuffer);
509 }
510
511 return fileStatus;
512 }
513
514 int writeToFile(char *fileName)
515 {
516 FileTools fileTools;
517
518 int fileStatus=0;
519
520 if (buffer!=null)
521 {
522 fileStatus=fileTools.writeFile(fileName,(char*)buffer,length);
523 }
524
525 return fileStatus;
526 }
527
528 int writeToFileEnd(char *fileName)
529 {
530 FileTools fileTools;
531
532 int fileStatus=0;
533
534 if (buffer!=null)
535 {
536 fileStatus=fileTools.writeToFileEnd(fileName,(char*)buffer,length);
537 }
538
539 return fileStatus;
540 }
541
542 int writeToFileEnd(char *fileName, char *newBuffer, int newLength)
543 {
544 FileTools fileTools;
545
546 int fileStatus=0;
547
548 if (buffer!=null)
549 {
550 fileStatus=fileTools.writeToFileEnd(fileName,(char*)newBuffer,newLength);
551 }
552
553 return fileStatus;
554 }
555
556
557 int readFile(char *fileName)
558 {
559 if (buffer!=null)
560 {
561 free(buffer);
562 buffer=null;
563 }
564
565 int fileBuffer=0;
566
567 FileTools fileTools;
568
569 // int fileStatus=FileTools::readStringFile(fileName,&fileBuffer,&length);
570 int fileStatus=fileTools.readStringFile(fileName,&fileBuffer,&length);
571 buffer=(char*)fileBuffer;
572
573 return fileStatus;
574 }
575
576 bool isNull()
577 {
578 if (buffer==null)
579 {
580 return true;
581 }
582
583 return false;
584 }
585
586 bool theFilePathIsNotUnder(String &filePath)
587 {
588 StringTools stringTools;
589
590 return stringTools.theFilePathIsNotUnder(buffer,length, filePath.buffer, filePath.length);
591 }
592
593
594 char* buffer;
595 String *string;
596 int length;
597
598 private:
599
600 };
601
602
603 #endif

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26