-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathadvstring.h
More file actions
766 lines (643 loc) · 20.3 KB
/
Copy pathadvstring.h
File metadata and controls
766 lines (643 loc) · 20.3 KB
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
/*
* advstring
*
* Author: Prasaath Viki
* Email: prasaathviki@gmail.com
* Description: advstring is a string class with advance options.
* Place: Chennai.
* Version: 2.0.7
* Date: Tuesday, May 20, 2014.
*/
#ifndef __ADVSTRING_H
#define __ADVSTRING_H
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <assert.h>
#include <memory>
#include <stdarg.h>
#include <stdio.h>
#include <list>
#include <time.h>
#include <algorithm>
using namespace std;
class advstring
{
private:
std::string m_sValue; // Internal value
static std::string IntToString(int nValue);
static std::string FloatToString(float nValue);
static std::string DoubleToString(double nValue);
static int StringToInt(std::string sValue);
static float StringToFloat(std::string sValue);
static double StringToDouble(std::string sValue);
static std::string GetDateTime(std::string sFormatValue);
public:
/*!
* Empty constructor, initialized to ''
*/
advstring();
/*!
* std::string oriented constructor
*/
advstring(std::string sValue);
/*!
* const char* type constructor
*/
advstring(const char *pcchValue);
/*!
* int type constructor
*/
advstring(int nValue);
/*!
* float type constructor
*/
advstring(float nValue);
/*!
* double type constructor
*/
advstring(double nValue);
/*!
* Get The class type in a std::string variable.
* \return "advstring"
*/
std::string GetClass();
/*!
* Display string using cout.
*/
void DispString();
/*!
* Display string using cout with endl.
*/
void DispStringEndl();
/*!
* To change the value with a standard std::string
* \arg value The value to assign
*/
void operator = (std::string sValue);
/*!
* To change the value with a advstring
* \arg value The value to assign
*/
void operator = (advstring asValue);
/*!
*To change the value with a const char *
*\arg value The value to assign
*/
void operator = (const char *pcchValue);
/*!
* Return a advstring which is the concatenation between the current value and the value passed in argument.
* \arg value The value to concatenate
* \return The concatenation between current and argument value.
*/
friend advstring operator+( advstring asValue, const advstring& asValue2);
/*!
* Return a advstring which is the concatenation between the current value and the value passed in argument.
* \arg value The value to concatenate
* \return The concatenation between current and argument value.
*/
friend advstring operator+( const char* pcchValue ,const advstring& asValue2);
/*!
* Return a advstring which is the concatenation between the current value and the value passed in argument.
* \arg value The value to concatenate
* \return The concatenation between current and argument value.
*/
friend advstring operator+( int nValue, const advstring& asValue2);
/*!
* Return a advstring which is the concatenation between the current value and the value passed in argument.
* \arg value The value to concatenate
* \return The concatenation between current and argument value.
*/
friend advstring operator+( float nValue ,const advstring& asValue2);
/*!
* Return a advstring which is the concatenation between the current value and the value passed in argument.
* \arg value The value to concatenate
* \return The concatenation between current and argument value.
*/
friend advstring operator+( double nValue ,const advstring& asValue2);
/*!
* Return a advstring which is the concatenation between the current value and the value passed in argument.
* \arg value The value to concatenate
* \return The concatenation between current and argument value.
*/
advstring operator + (const char *pcchValue);
/*!
* Return a advstring which is the concatenation between the current value and the value passed in argument.
* \arg value The value to concatenate
* \return The concatenation between current and argument value.
*/
advstring operator + (int nValue);
/*!
* Return a advstring which is the concatenation between the current value and the value passed in argument.
* \arg value The value to concatenate
* \return The concatenation between current and argument value.
*/
advstring operator + (float nValue);
/*!
* Return a advstring which is the concatenation between the current value and the value passed in argument.
* \arg value The value to concatenate
* \return The concatenation between current and argument value.
*/
advstring operator + (double nValue);
/*!
* Concatenate current advstring with another advstring (the argument is placed behind the current advstring).
* \arg to_add The string we want to concatenate with.
*/
void operator += (advstring asValue);
/*!
* Return a advstring which is the concatenation between the current value and the value passed in argument.
* \arg value The value to concatenate
* \return The concatenation between current and argument value.
*/
void operator += (const char *pcchValue);
/*!
* Concatenate current advstring with int value.
* \arg to_add The string we want to concatenate with.
*/
void operator += (int nValue);
/*!
* Concatenate current advstring with float value.
* \arg to_add The string we want to concatenate with.
*/
void operator += (float nValue);
/*!
* Concatenate current advstring with double value.
* \arg to_add The string we want to concatenate with.
*/
void operator += (double nValue);
//advstring operator + (advstring asValue,advstring asValue2);
/*!
* Comparison between two advstring.
* \return A boolean : true if the values are the same, false if not.
*/
bool operator == (advstring asValue);
/*!
* Comparison between a advstring and a int.
* \return A boolean : true if the values are the same, false if not.
*/
bool operator == (int nValue);
/*!
* Comparison between a advstring and a float.
* \return A boolean : true if the values are the same, false if not.
*/
bool operator == (float nValue);
/*!
* Comparison between a advstring and a double.
* \return A boolean : true if the values are the same, false if not.
*/
bool operator == (double nValue);
/*!
* Comparison between a advstring and a const char*
* \return A boolean : true if the values are the same, false if not.
*/
bool operator == (const char* pcchValue);
/*!
* Comparison between two advstring.
* \return A boolean : true if the values are different, true if they are the same.
*/
bool operator != (advstring asValue);
/*!
* Comparison between a advstring and a int.
* \return A boolean : true if the values are the same, false if not.
*/
bool operator != (int nValue);
/*!
* Comparison between a advstring and a float.
* \return A boolean : true if the values are the same, false if not.
*/
bool operator != (float nValue);
/*!
* Comparison between a advstring and a double.
* \return A boolean : true if the values are the same, false if not.
*/
bool operator != (double nValue);
/*!
* Comparison between a advstring and a const char*.
* \return A boolean : true if the values are the same, false if not.
*/
bool operator != (const char* pcchValue);
/*!
* Converts to int.
*/
operator int();
/*!
* Converts to float.
*/
operator float();
/*!
* Converts to double.
*/
operator double();
/*!
* Converts to const char *.
*/
operator const char*();
/*!
* Converts to char*.
* Please delete the chNewValue after usage. if not deleted it may cause memory leak.
*/
operator char*();
/*!
* Converts to int.
* \return int
*/
int ToInt();
/*!
* Converts to float.
* \return float
*/
float ToFloat();
/*!
* Converts to double.
* \return double
*/
double ToDouble();
/*!
* Convert the current string to a std::string.
* \return A std::string.
*/
std::string ToStdString();
/*!
* Convert advstring to a const char array (the same way as std::string.c_str()).
* \return A const char* version of the current advstring.
*/
const char* GetBuffer();
/*!
* Convert advstring to a char array.
* \return A char* version of the current advstring.
*/
char* GetNewBuffer();
/*!
* Clear the content of the current advstring (same effect as = "").
*/
void Empty();
/*!
* Return the number of characters in advstring.
* \return length of the advstring.
*/
int GetLength();
/*!
* Maximum size of advstring without reallocation (the same as std::string).
*\return max size without reallocation.
*/
int MaxSize();
/*!
* Ask if the current advstring is empty or not.
* \return A boolean : true = the advstring is empty ; false = the advstring is not empty.
*/
bool IsEmpty();
/*!
* Get char at given Index.
*\arg Index of the letter.
*\return char value.
*\assert if Index below zero and if Index greater than size of the advstring
*/
char GetAt(int nIndex);
/*!
*Set char at given Index and replaces the old value.
*\arg Index of the letter , value.
*\assert if Index below zero and if Index greater than length of the advstring
*/
void SetAt(int nIndex,char chValue);
/*!
* Insert char to respected index.
* \arg: Index the advstring, char value to insert.
* \return: length of the updated advstring.
*/
int Insert(int nIndex,char chValue);
/*!
* Insert advstring to respected index.
* \arg: Index of the advstring, advstring value to insert.
* \return: length of the updated advstring.
*/
int Insert(int nIndex,advstring asValue);
/*!
* Replace all old char with new char.
* \arg old char, new char.
* \return int: replaced char count.
*/
int Replace(char chOldValue,char chNewValue);
/*!
* Replace old advstring with new advstring.
* \arg old advstring , new advstring.
* \return int: replaced advstring count.
*/
int Replace(advstring asOldValue,advstring asNewValue);
/*!
* Remove all given char from advstring.
* \arg char value to remove from the advstring.
*/
void Remove(char chRemValue);
/*!
* Find the given char in advstring.
* \return first given char find index
*/
int Find(char chFindValue,int nIndex = 0);
/*!
* Find the given char in string
* \return first given advstring find index
*/
int Find(advstring asFindValue,int nIndex = 0);
/*!
* Find the position of the first occurrence of one of the elements passed in argument.
* \return reverse find index
*/
int ReverseFind(char chFindValue);
/*!
* Find the position of the first occurrence of one of the elements passed in argument.
* \return reverse find index
*/
int ReverseFind(advstring asFindValue);
/*!
* Extract the substring in the current advstring.
* \arg beginning nIndex we want to start the extraction.
* \arg The length of the advstring we wants to extract.
* \return The extracted advstring.
*/
advstring Mid(int nIndex, int nLength);
/*!
* Compare advstring with current value.
* /return 0 They compare equal
* /return <0 Either the value of the first character that does not match is lower in the compared string, or all compared characters match but the compared string is shorter.
* /return >0 Either the value of the first character that does not match is greater in the compared string, or all compared characters match but the compared string is longer.
*/
int Compare(advstring asCompValue);
/*!
* Format advstring
* \arg format code for string and followed by value.
*/
void Format(const char* pcchValue, ...);
/*!
* Release buffer set to size -1
*/
void ReleaseBuffer();
/*!
* Return the substring consisting of the Leftmost Count characters.
* /arg count to substring from Left.
* /return substring advstring value.
*/
advstring Left(int nLength);
/*!
* Return the substring consisting of the Rightmost Count characters.
* /arg count to substring from right.
* /return substring advstring value.
*/
advstring Right(int nLength);
/*!
* Append current advstring with another advstring .
* \arg asAppString The string we want to Append with.
*/
void Append(advstring asAppString);
/*!
* Append current advstring with char value .
* \arg chApp The char we want to Append with.
*/
void AppendChar(char chApp);
/*!
* Write current advstring value to path specified. If a file with the same name already exists, its contents are discarded and the file is treated as a new empty file.
* \arg asFpath Path with file name.
* \return 1 - success -1 - failure
*/
int FileWrite(advstring asFpath);
/*!
* Write current advstring value to path specified. Open file for output at the end of a file. Output operations always write data at the end of the file, expanding it. The file is created if it does not exist.
* \arg asFpath Path with file name.
* \return 1 - success -1 - failure
*/
int FileAppend(advstring asFpath);
/*!
* Write current advstring value with current date and time to path specified. Open file for output at the end of a file. Output operations always write data at the end of the file, expanding it. The file is created if it does not exist.
* \arg asFpath Path with file name.
* \return 1 - success -1 - failure
*/
int FileAppendWithDateTime(advstring asFpath);
/*!
* Read File from the file path specified and save the current value to current advstring value.
* \arg asFpath Path with file name.
* \return 1 - success -1 - failure
*/
int FileRead(advstring asFpath);
/*!
* Set current time to advstring value.
* \return 1 - success -1 - failure
*/
int SetCurTime();
/*!
* Set current date and time to advstring value.
* \return 1 - success -1 - failure
*/
int SetCurDateTime();
/*!
* Set current date and time stamp to advstring value.
* \return 1 - success -1 - failure
*/
int SetCurDateTimeStamp();
/*!
* Append current time to advstring value.
* \return 1 - success -1 - failure
*/
int AppCurTime();
/*!
* Append current date and time to advstring value.
* \return 1 - success -1 - failure
*/
int AppCurDateTime();
/*!
* Append current date and time stamp to current advstring value.
* \return 1 - success -1 - failure
*/
int AppCurDateTimeStamp();
/*!
* AppendFormat : Append the formated values to current advstring value
* \return (1) - success (-1) - failure
*/
void AppendFormat(const char* pcchValue, ...);
/*!
* Format value with va_list and update the current advstring value
* \arg data and va_list initialized object.
*/
void FormatV(const char* pcchValue,va_list args);
/*!
* Format value with va_list and Append the current advstring value
* \arg data and va_list initialized object.
*/
void AppendFormatV(const char* pcchValue,va_list args);
/*!
* Make current advstring values to Reverse.
* \return return Reversed string.
*/
advstring MakeReverse();
/*!
* Make current advstring values to Lower.
* \return return converted string.
*/
advstring MakeLower();
/*!
* Make current advstring values to Upper.
* \return return converted string.
*/
advstring MakeUpper();
/*!
* Make the given value and current value to Lower and compare the strings.
* /return 0 They compare equal
* /return <0 Either the value of the first character that does not match is lower in the compared string, or all compared characters match but the compared string is shorter.
* /return >0 Either the value of the first character that does not match is greater in the compared string, or all compared characters match but the compared string is longer.
*/
int CompareNoCase(advstring asCompValue);
/*!
* check current advstring values are Lower.
* /return 0 They compare equal
* /return <0 Either the value of the first character that does not match is lower in the compared string, or all compared characters match but the compared string is shorter.
* /return >0 Either the value of the first character that does not match is greater in the compared string, or all compared characters match but the compared string is longer.
*/
int IsLower();
/*!
* check current advstring values are Upper.
* /return 0 They compare equal
* /return <0 Either the value of the first character that does not match is lower in the compared string, or all compared characters match but the compared string is shorter.
* /return >0 Either the value of the first character that does not match is greater in the compared string, or all compared characters match but the compared string is longer.
*/
int IsUpper();
/*!
* Swap the given advstring value to current value and current value to swap string.
*/
void Swap(advstring &asSwap);
/*!
* Get current date and time.
* \return advstring
*/
advstring GetCurDateTime();
/*!
* Set current time.
* \return advstring
*/
advstring GetCurTime();
/*!
* Get current date time stamp.
* \return advstring
*/
advstring GetCurDateTimeStamp();
/*!
* Get current date.
* \return advstring
*/
advstring GetCurDate();
/*!
* Set current date to advstring value.
* \return 1 - success -1 - failure
*/
int SetCurDate();
/*!
* App current date to advstring value.
* \return 1 - success -1 - failure
*/
int AppCurDate();
/*!
* Get XOR Encrypted Data
* XOR Encryption is very simple encryption technique.
* XOR Encryption is very easy to break. Use with care.
* Don't use key with same letters. Key should be same as the length of the text.
* Encryption and Decryption both are same algorithm.
* \return 1 - success -1 - failure
*/
advstring GetXOREncryptedData(advstring asKey);
/*!
* Get XOR Encrypted Data
* XOR Encryption is very simple encryption technique.
* XOR Encryption is very easy to break. Use with care.
* Don't use key with same letters. Key should be same as the length of the text.
* Encryption and Decryption both are same algorithm.
* \return 1 - success -1 - failure
*/
advstring GetXORDecryptedData(advstring asKey);
/*!
* Set XOR Encrypted Data
* XOR Encryption is very simple encryption technique.
* XOR Encryption is very easy to break. Use with care.
* Don't use key with same letters. Key should be same as the length of the text.
* Encryption and Decryption both are same algorithm.
* \return 1 - success -1 - failure
*/
int SetXOREncryptedData(advstring asKey);
/*!
* Set XOR Encrypted Data
* XOR Encryption is very simple encryption technique.
* XOR Encryption is very easy to break. Use with care.
* Don't use key with same letters. Key should be same as the length of the text.
* Encryption and Decryption both are same algorithm.
* \return 1 - success -1 - failure
*/
int SetXORDecryptedData(advstring asKey);
/*!
* Append XOR Encrypted Data
* XOR Encryption is very simple encryption technique.
* XOR Encryption is very easy to break. Use with care.
* Don't use key with same letters. Key should be same as the length of the text.
* Encryption and Decryption both are same algorithm.
* \return 1 - success -1 - failure
*/
int AppXOREncryptedData(advstring asKey);
/*!
* Append XOR Encrypted Data
* XOR Encryption is very simple encryption technique.
* XOR Encryption is very easy to break. Use with care.
* Don't use key with same letters. Key should be same as the length of the text.
* Encryption and Decryption both are same algorithm.
* \return 1 - success -1 - failure
*/
int AppXORDecryptedData(advstring asKey);
/*!
* Get current data of the advstring.
* If you change the values of the std::string* data it also change the data values of the advstring.
* Don't clear this pointer it will cleared automatically when the advstring is cleared.
* \return std::string*
*/
std::string* GetData();
/*!
* Remove all leading and trailing occurrences in the advstring value.
* \return advstring
*/
advstring Trim();
/*!
* Remove all leading and trailing occurrences of any of the char in the advstring value.
* \return advstring
*/
advstring Trim(char chTrim);
/*!
* Remove all leading and trailing occurrences of any of the string in the advstring value.
* \return advstring
*/
advstring Trim(advstring asTrim);
/*!
* Remove all leading occurrences in the advstring value.
* \return advstring
*/
advstring TrimLeft();
/*!
* Remove all leading occurrences of any of the char in the advstring value.
* \return advstring
*/
advstring TrimLeft(char chTrim);
/*!
* Remove all leading occurrences of any of the string in the advstring value.
* \return advstring
*/
advstring TrimLeft(advstring asTrim);
/*!
* Remove all trailing occurrences in the advstring value.
* \return advstring
*/
advstring TrimRight();
/*!
* Remove all trailing occurrences of any of the char in the advstring value.
* \return advstring
*/
advstring TrimRight(char chTrim);
/*!
* Remove all trailing occurrences of any of the string in the advstring value.
* \return advstring
*/
advstring TrimRight(advstring asTrim);
};
#endif