-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimp.cpp
More file actions
3790 lines (3378 loc) · 85.5 KB
/
Copy pathtimp.cpp
File metadata and controls
3790 lines (3378 loc) · 85.5 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
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>
#include <math.h>
template <class Type>
class LinkedList {
public:
struct Node {
Type data;
Node *previous,*next;
};
LinkedList();
LinkedList(const LinkedList &source);
~LinkedList();
void operator =(const LinkedList& source);
void operator +=(const LinkedList& source);
void advance(size_t num=1);
void append(const Type& entry);
void attach(const Type& entry);
void backwardFind(const Type& match);
void backwardReplace(const Type& match,const Type& replace);
void clear();
void clearList();
void clearMark() { mark=NULL; }
void forwardFind(const Type& match);
void forwardReplace(const Type& match,const Type& replace);
Type &getCurrent() const;
size_t getLength() const { return list_length; }
void goEnd() { cursor=tail; }
void goMark() { cursor=mark; }
void goStart() { cursor=head; }
void insert(const Type& entry);
bool isAtStart() const { return (cursor == head); }
bool isAtEnd() const { return (cursor == tail); }
bool isCurrent() const { return (cursor != NULL); }
bool isMarked() const { return (mark != NULL); }
void removeCurrent();
void remove(const Type& match);
void retreat(size_t num=1);
void setMark() { mark=cursor; }
void sort(int (*compare)(Type& left,Type& right));
/*
#if defined(__SUNPRO_CC_COMPAT)
template <class Type> friend LinkedList<Type> sublist(const LinkedList<Type>& source,size_t length);
#else
friend LinkedList<Type> sublist<Type>(const LinkedList<Type>& source,size_t length);
#endif
*/
template <class Type1> friend LinkedList<Type> sublist(const LinkedList<Type>& source,size_t length);
private:
size_t listClear(Node*& root);
void listAttach(const Type& entry);
void listForwardFind(const Type& match);
void listBackwardFind(const Type& match);
bool isNode(const Node *node) const { return (node != NULL); }
Node *head,*tail,*cursor,*mark;
size_t list_length;
};
// template begins
template <class Type>
LinkedList<Type>::LinkedList()
{
head=tail=cursor=mark=NULL;
list_length=0;
}
template <class Type>
LinkedList<Type>::LinkedList(const LinkedList &source)
{
head=tail=cursor=mark=NULL;
list_length=0;
*this=source;
}
template <class Type>
LinkedList<Type>::~LinkedList()
{
listClear(head);
head=tail=cursor=mark=NULL;
}
template <class Type>
void LinkedList<Type>::advance(size_t num)
{
size_t n=0;
while (isCurrent() && n < num) {
cursor=cursor->next;
n++;
}
}
template <class Type>
void LinkedList<Type>::retreat(size_t num)
{
size_t n=0;
while (isCurrent() && n < num) {
cursor=cursor->previous;
n++;
}
}
template <class Type>
void LinkedList<Type>::sort(int (*compare)(Type& left,Type& right))
{
Type *array=new Type[list_length];
int n=0,m;
goStart();
while (isCurrent()) {
array[n++]=getCurrent();
advance();
}
clearList();
binarySort(array,n,compare);
for (m=0; m < n; m++)
attach(array[m]);
delete[] array;
}
template <class Type>
void LinkedList<Type>::append(const Type& entry)
{
setMark();
goEnd();
attach(entry);
goMark();
clearMark();
}
template <class Type>
void LinkedList<Type>::attach(const Type& entry)
{
listAttach(entry);
// set up any other necessary links
if (head == NULL && tail == NULL)
// attached to an empty list
head=tail=cursor;
else if (tail->next != NULL)
// attached to end of list
tail=cursor;
else if (cursor->previous == NULL) {
// attached to end of list, but cursor was off end of list
cursor->previous=tail;
tail->next=cursor;
tail=cursor;
}
}
template <class Type>
void LinkedList<Type>::insert(const Type& entry)
{
Node *last_cursor=cursor;
// create and insert a new node to the linked list
if (isCurrent())
cursor=cursor->previous;
listAttach(entry);
if (head == NULL && tail == NULL)
// inserted into an empty list
head=tail=cursor;
else if (last_cursor == head) {
// inserted at head of list
cursor->next=head;
head->previous=cursor;
head=cursor;
}
else if (last_cursor == NULL) {
// inserted at end of list, but cursor was off end of list
cursor->previous=tail;
tail->next=cursor;
tail=cursor;
}
}
template <class Type>
void LinkedList<Type>::removeCurrent()
{
Node *remove=cursor;
if (!isCurrent())
return;
cursor=cursor->next;
// removing head node
if (remove == head) {
head=cursor;
if (isCurrent())
cursor->previous=NULL;
else
tail=NULL;
}
// removing tail node
else if (remove == tail) {
tail=remove->previous;
(remove->previous)->next=NULL;
}
// removing inner node
else {
(remove->previous)->next=cursor;
cursor->previous=remove->previous;
}
delete remove;
list_length--;
}
template <class Type>
void LinkedList<Type>::remove(const Type& match)
{
Node *save=cursor;
cursor=head;
while (isCurrent() && cursor->data != match)
cursor=cursor->next;
if (isCurrent())
LinkedList<Type>::removeCurrent();
else
cursor=save;
}
template <class Type>
void LinkedList<Type>::clear()
{
list_length-=listClear(cursor);
if (isCurrent())
tail=cursor;
else
head=tail=cursor=mark=NULL;
}
template <class Type>
void LinkedList<Type>::clearList()
{
list_length-=listClear(head);
if (list_length != 0) {
std::cerr << "error clearing list" << std::endl;
exit(-1);
}
head=tail=cursor=mark=NULL;
}
template <class Type>
void LinkedList<Type>::forwardFind(const Type& match)
{
// if already at tail, can not go forward
if (!isCurrent())
return;
listForwardFind(match);
}
template <class Type>
void LinkedList<Type>::forwardReplace(const Type& match,const Type& replace)
{
// if already at tail, can not go forward
if (!isCurrent())
return;
listForwardFind(match);
if (isCurrent())
cursor->data=replace;
}
template <class Type>
void LinkedList<Type>::backwardFind(const Type& match)
{
// if already at head, can not go backward
if (cursor == head) {
cursor=NULL;
return;
}
listBackwardFind(match);
}
template <class Type>
void LinkedList<Type>::backwardReplace(const Type& match,const Type& replace)
{
// if already at head, can not go backward
if (cursor == head) {
cursor=NULL;
return;
}
listBackwardFind(match);
if (isCurrent())
cursor->data=replace;
}
template <class Type>
Type &LinkedList<Type>::getCurrent() const
{
if (!isCurrent()) {
std::cerr << "Error: off end of list " << this << std::endl;
exit(1);
}
return cursor->data;
}
template <class Type>
void LinkedList<Type>::operator =(const LinkedList& source)
{
Node *source_cursor,*current=NULL;
// deal with the self-assignment case
if (this == &source)
return;
listClear(head);
head=tail=cursor=mark=NULL;
list_length=0;
source_cursor=source.head;
while (source_cursor != NULL) {
attach(source_cursor->data);
if (source_cursor == source.cursor) current=cursor;
if (source_cursor == source.mark) mark=cursor;
source_cursor=source_cursor->next;
}
cursor=current;
}
template <class Type>
void LinkedList<Type>::operator +=(const LinkedList& source)
{
Node *source_cursor;
source_cursor=source.head;
while (source_cursor != NULL) {
attach(source_cursor->data);
source_cursor=source_cursor->next;
}
}
template <class Type>
void LinkedList<Type>::listAttach(const Type& entry)
{
Node *new_node;
// create new node
if ( (new_node=new Node) == NULL) {
std::cerr << "listAttach: dynamic memory allocation error" << std::endl;
exit(-1);
}
list_length++;
// copy entry to new node
new_node->data=entry;
// attach the new node after the current node in the list
if (isCurrent()) {
new_node->next=cursor->next;
new_node->previous=cursor;
if (isNode(cursor->next))
(cursor->next)->previous=new_node;
cursor->next=new_node;
}
else
new_node->next=new_node->previous=NULL;
// make the new node the current node in the list
cursor=new_node;
}
template <class Type>
size_t LinkedList<Type>::listClear(Node*& root)
{
size_t num_cleared=0;
Node *save,*remove;
if (!isNode(root))
return 0;
save=root->previous;
while (isNode(root)) {
remove=root;
root=root->next;
delete remove;
num_cleared++;
}
root=save;
if (isNode(root))
root->next=NULL;
return num_cleared;
}
template <class Type>
void LinkedList<Type>::listForwardFind(const Type& match)
{
while (isCurrent() && cursor->data != match)
cursor=cursor->next;
}
template <class Type>
void LinkedList<Type>::listBackwardFind(const Type& match)
{
while (isCurrent() && cursor->data != match)
cursor=cursor->previous;
}
template <class Type>
LinkedList<Type> sublist(const LinkedList<Type>& source,size_t length)
{
LinkedList<Type> sub_list;
size_t n=0;
typename LinkedList<Type>::Node *source_cursor;
source_cursor=source.cursor;
while (source_cursor != NULL && n < length) {
sub_list.attach(source_cursor->data);
source_cursor=source_cursor->next;
n++;
}
return sub_list;
}
template <class Type>
bool operator ==(LinkedList<Type>& source1,LinkedList<Type>& source2)
{
if (source1.getLength() != source2.getLength())
return false;
source1.goStart();
source2.goStart();
while (source1.isCurrent()) {
if (source1.getCurrent() != source2.getCurrent())
return false;
source1.advance();
source2.advance();
}
return true;
}
template <class Type>
bool operator !=(LinkedList<Type>& source1,LinkedList<Type>& source2)
{
return !(source1 == source2);
}
class String
{
public:
static const char start_of_header[2];
static const char end_of_text[2];
static const char tab[2];
static const char newline[2];
static const char carriage_return[2];
static const size_t XMLTag;
String();
String(const char *source);
String(const char *source,size_t num_chars);
String(const String& source);
~String();
bool beginsWith(const char *string) const;
bool beginsWith(const String& source) const { return beginsWith(source.toChar()); }
String capitalized() const;
char charAt(size_t index) const;
void chop();
void chop(size_t num_chars);
void chopWhiteSpace();
bool contains(const char *source) const;
bool contains(const String& source) const;
void convertUnicode();
bool endsWith(char character) const;
bool endsWith(const char *string) const;
void fill(const char *source);
void fill(const char *source,size_t num_chars);
void finalizeBuffer() { ptr_to_string[len]='\0'; }
char *getAddressOf(size_t index) const;
char *getBufferReference(const size_t length);
size_t getLength() const { return len; }
int getLengthAsInt() const { return len; }
String getToken(const String separator,size_t token_number);
bool hasNoLetters() const;
bool hasNoVowels() const;
int indexOf(const char *string,int start = 0) const;
void insert(const char *source) { insertAt(0,source); }
void insertAt(size_t index,const char *source);
bool isAlpha() const;
int isAt(const char *string) const;
bool isNumeric() const;
bool isUpperCase() const;
bool lettersAreUpperCase() const;
size_t occurs(const char *source) const;
size_t occurs(const String& source) const;
void operator =(const String& source);
void operator =(const char *source);
void operator +=(const String& source);
// char *operator +=(const char *source);
void operator +=(const char *source);
bool replace(const char *old_string,const char *new_string);
bool replace(const String& old_string,const char *new_string) { return replace(old_string.toChar(),new_string); }
bool replace(const String& old_string,const String& new_string) { return replace(old_string.toChar(),new_string.toChar()); }
String soundex() const;
/*
size_t split(const char *separator,String **array) const;
size_t split(size_t StringType,String **array) const;
size_t split(const String separator,String **array) const { return split(separator.toChar(),array); }
*/
String substitute(const char *old_string,const char *new_string) const;
String substitute(const String& old_string,const char *new_string) const { return substitute(old_string.toChar(),new_string); }
String substitute(const String& old_string,const String& new_string) const { return substitute(old_string.toChar(),new_string.toChar()); }
String substr(size_t start_index,size_t num_chars) const;
String substr(size_t start_index) const { return substr(start_index,len+1); }
String substr(const char *start_with,size_t num_chars) const;
String substr(size_t start_index,const char *end_with) const;
const char *toChar() const;
String toLower() const;
String toLower(size_t start_index,size_t num_chars) const;
String toUpper() const;
String toUpper(size_t start_index,size_t num_chars) const;
void trim();
void trimBack();
void trimFront();
bool truncate(const char from_here_to_end);
friend std::ostream& operator <<(std::ostream& out_stream,const String& source);
friend String operator +(const String& source1,const String& source2);
friend bool operator ==(const String& source1,const String& source2);
friend bool operator !=(const String& source1,const String& source2);
friend bool operator >(const String& source1,const String& source2);
friend bool operator >=(const String& source1,const String& source2);
friend bool operator <(const String& source1,const String& source2);
friend bool operator <=(const String& source1,const String& source2);
protected:
void cat(const char *source);
size_t len;
char *ptr_to_string;
};
class StringBuffer : public String
{
public:
static const size_t buffer_increment;
StringBuffer(size_t initial_capacity = 0);
StringBuffer(const char *source,size_t initial_capacity = 0);
StringBuffer(const String& source,size_t initial_capacity = 0);
void fill(const char *source);
size_t getCapacity() const { return capacity; }
void operator =(const String& source);
void operator =(const char *source);
/*
StringBuffer operator +=(const StringBuffer& source);
StringBuffer operator +=(const String& source);
char *operator +=(const char *source);
*/
void operator +=(const StringBuffer& source);
void operator +=(const String& source);
void operator +=(const char *source);
private:
void cat(const char *source);
size_t capacity;
};
class StringParts
{
public:
StringParts();
StringParts(const String& string,const char *separator = "");
StringParts(const String& string,size_t StringType);
~StringParts();
void fill(const String& string,const char *separator = "");
void fill(const String& string,size_t StringType);
size_t getLength() const { return num_parts; }
size_t getLengthOfPart(size_t part_number) const;
const String& getPart(size_t part_number) const;
private:
size_t capacity,num_parts;
String *parts,empty_part;
};
const char String::start_of_header[2]={0x1,0};
const char String::end_of_text[2]={0x3,0};
const char String::tab[2]={0x9,0};
const char String::newline[2]={0xa,0};
const char String::carriage_return[2]={0xd,0};
const size_t String::XMLTag=1;
String::String()
{
len=0;
ptr_to_string=NULL;
}
String::String(const char *source)
{
len=0;
ptr_to_string=NULL;
fill(source);
}
String::String(const char *source,size_t num_chars)
{
len=0;
ptr_to_string=NULL;
fill(source,num_chars);
}
String::String(const String& source)
{
len=0;
ptr_to_string=NULL;
*this=source;
}
String::~String()
{
if (ptr_to_string != NULL) {
delete[] ptr_to_string;
ptr_to_string=NULL;
}
}
bool String::beginsWith(const char *string) const
{
size_t cmp_len;
if (len == 0 || string == NULL)
return false;
cmp_len=strlen(string);
if (cmp_len > len)
return false;
if (strncmp(ptr_to_string,string,cmp_len) == 0)
return true;
return false;
}
String String::capitalized() const
{
String c=*this;
int index;
if (this->len > 0) {
if (c.ptr_to_string[0] >= 'a' && c.ptr_to_string[0] <= 'z')
c.ptr_to_string[0]-=32;
while (c.contains("_")) {
index=c.isAt("_");
if (index < 0)
break;
c.ptr_to_string[index]=' ';
if ( (size_t)(index+1) < c.len && c.ptr_to_string[index+1] >= 'a' && c.ptr_to_string[index+1] <= 'z')
c.ptr_to_string[index+1]-=32;
}
}
return c;
}
char String::charAt(size_t index) const
{
if (len == 0 || index >= len)
return '\0';
else
return ptr_to_string[index];
}
void String::chop()
{
if (len == 0)
return;
len--;
ptr_to_string[len]='\0';
}
void String::chop(size_t num_chars)
{
size_t n;
for (n=0; n < num_chars; n++)
chop();
}
void String::chopWhiteSpace()
{
while (len > 0 && ptr_to_string[len-1] == ' ')
chop();
}
bool String::contains(const char *source) const
{
size_t cmp_len;
int n,num_cmps;
if (source == NULL)
return false;
cmp_len=strlen(source);
if (len >= cmp_len) {
num_cmps=len-cmp_len+1;
for (n=0; n < num_cmps; n++) {
if (strncmp(source,&ptr_to_string[n],cmp_len) == 0)
return true;
}
return false;
}
else
return false;
}
bool String::contains(const String& source) const
{
return this->contains(source.ptr_to_string);
}
void String::convertUnicode()
{
size_t n;
char *temp;
for (n=0; n < len; n++) {
if ((unsigned char)ptr_to_string[n] == 0xc2 || (unsigned char)ptr_to_string[n] == 0xc3) {
temp=new char[len-n];
strcpy(temp,&ptr_to_string[n+1]);
switch ((unsigned char)ptr_to_string[n+1]) {
case 0x80:
case 0x81:
case 0x82:
case 0x83:
case 0x84:
case 0x85:
temp[0]='A';
break;
case 0x87:
temp[0]='C';
break;
case 0x88:
case 0x89:
case 0x8a:
case 0x8b:
temp[0]='E';
break;
case 0x8c:
case 0x8d:
case 0x8e:
case 0x8f:
temp[0]='I';
break;
case 0x91:
temp[0]='N';
break;
case 0x92:
case 0x93:
case 0x94:
case 0x95:
case 0x96:
case 0x98:
temp[0]='O';
break;
case 0x99:
case 0x9a:
case 0x9b:
case 0x9c:
temp[0]='U';
break;
case 0x9d:
temp[0]='Y';
break;
case 0xa0:
case 0xa1:
case 0xa2:
case 0xa3:
case 0xa4:
case 0xa5:
temp[0]='a';
break;
case 0xa7:
temp[0]='c';
break;
case 0xa8:
case 0xa9:
case 0xaa:
case 0xab:
temp[0]='e';
break;
case 0xac:
case 0xad:
case 0xae:
case 0xaf:
temp[0]='i';
break;
case 0xb1:
temp[0]='n';
break;
case 0xb2:
case 0xb3:
case 0xb4:
case 0xb5:
case 0xb6:
case 0xb8:
temp[0]='o';
break;
case 0xb9:
case 0xba:
case 0xbb:
case 0xbc:
temp[0]='u';
break;
case 0xbd:
case 0xbf:
temp[0]='y';
break;
}
strcpy(&ptr_to_string[n],temp);
len=strlen(ptr_to_string);
}
}
}
bool String::endsWith(char character) const
{
if (len == 0)
return false;
if (ptr_to_string[len-1] == character)
return true;
else
return false;
}
bool String::endsWith(const char *string) const
{
size_t cmp_len;
if (len == 0 || string == NULL)
return false;
cmp_len=strlen(string);
if (cmp_len > len)
return false;
if (strncmp(&ptr_to_string[len-cmp_len],string,cmp_len) == 0)
return true;
return false;
}
void String::fill(const char *source)
{
size_t n;
if (ptr_to_string != NULL)
delete[] ptr_to_string;
if (source == NULL) {
len=0;
ptr_to_string=NULL;
}
else {
len=strlen(source);
if (len > 0) {
ptr_to_string=new char[len+1];
for (n=0; n < len; n++)
ptr_to_string[n]=source[n];
ptr_to_string[len]='\0';
}
else
ptr_to_string=NULL;
}
}
void String::fill(const char *source,size_t num_chars)
{
size_t n;
char *temp;
if (ptr_to_string != NULL)
delete[] ptr_to_string;
if (source == NULL) {
len=0;
ptr_to_string=NULL;
}
else {
// need this because *source could be this string or a subset of it
temp=new char[num_chars+1];
for (n=0; n < num_chars; n++)
temp[n]=source[n];
temp[num_chars]='\0';
len=strlen(temp);
if (len > 0) {
ptr_to_string=new char[len+1];
for (n=0; n < len; n++)
ptr_to_string[n]=temp[n];
ptr_to_string[len]='\0';
}
else
ptr_to_string=NULL;
delete[] temp;
}
}
char *String::getAddressOf(size_t index) const
{
if (index < len)
return &(ptr_to_string[index]);
else
return NULL;
}
String String::getToken(const String separator,size_t token_number)
{
String token;
StringParts sp;
if (len == 0)
return token;
if (separator.getLength() == 0)
sp.fill(*this);
else
sp.fill(*this,separator.toChar());
if (token_number < sp.getLength())
token=sp.getPart(token_number);
return token;
}
bool String::hasNoLetters() const
{
size_t n;
for (n=0; n < len; n++) {
if ((ptr_to_string[n] >= 'A' && ptr_to_string[n] <= 'Z') || (ptr_to_string[n] >= 'a' && ptr_to_string[n] <= 'z'))
return false;
}
return true;
}
bool String::hasNoVowels() const
{
size_t n;
char c;
for (n=0; n < len; n++) {
c=ptr_to_string[n];
if (c == 'a' || c == 'A' || c == 'e' || c == 'E' || c == 'i' || c == 'I' || c == 'o' || c == 'O' || c == 'u' || c == 'U')
return false;
if (ptr_to_string[n] == 'y') {
}
}
return true;
}
int String::indexOf(const char *string,int start) const
{
size_t cmp_len=strlen(string);
int n;
if (start >= 0) {
if ( (start+cmp_len) > len)
return -1;
for (n=start; n <= (int)(len-cmp_len); n++) {
if (strncmp(string,&ptr_to_string[n],cmp_len) == 0)
return n;
}
}
else {
start=-start;
if (start < 0)
return -1;
if (start >= (int)len)
start=len-1;
if ((size_t)start > (len+cmp_len-1))
start=len-cmp_len+1;
for (n=start; n >= 0; n--) {
if (strncmp(string,&ptr_to_string[n],cmp_len) == 0)
return n;
}
}
return -1;
}
void String::insertAt(size_t index,const char *source)
{
char *new_string;
new_string=new char[len+strlen(source)+1];
strncpy(new_string,ptr_to_string,index);
new_string[index]='\0';
strcat(new_string,source);
strcat(new_string,&ptr_to_string[index]);
this->fill(new_string);
delete[] new_string;
}
bool String::isAlpha() const
{
size_t n;
for (n=0; n < len; n++) {
if ((ptr_to_string[n] < 'A' || ptr_to_string[n] > 'Z') && (ptr_to_string[n] < 'a' || ptr_to_string[n] > 'z'))