-
Notifications
You must be signed in to change notification settings - Fork 1
/
GCProfile.cpp
9222 lines (6315 loc) · 193 KB
/
GCProfile.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
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
/*
Copyright (C) 2024 BrerDawg
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
//GCProfile.cpp
//---- v1.01 08-09-07 //faster operations
//---- v1.02 29-02-08 //fixed compiler warning messages
//---- v1.03 02-06-09 //added GetPrivateProfileParams,WritePrivateProfileParams
//---- v1.04 27-07-09 //reduced amount of file accesses by using string obj to hold file contents,see Index(),Save()
//---- v1.05 20-02-10 //changed GetPrivateProfileString to GetPrivateProfileStr to avoid clash when compiling in Windows
//changed WritePrivateProfileString to WritePrivateProfileStr to avoid clash when compiling in Windows
//added pathname handling functions for obj my_str works with Linux or Windows
//---- v1.05 05-07-10 //fixed FindReplace() bug causing premature completion - search for 'changed 06-07-10'
//---- v1.06 25-07-10 //fixed WritePrivateProfileStr() bug causing exisiting csKey in follwing csSection to be used
//-if a matching csKey was not found in specified csSection
//---- v1.07 25-07-10 //added mystr ExtractParamVal() and bool,int,float,double param extraction
//---- v1.08 08-08-10 //added mystr (char* s) (strings s) overloadining options, now: mystr m=str; , mystr m="hello"; work
//---- v1.09 19-08-10 //added ExtractElement(int nth,char delimiter,string &element);
//---- v1.10 07-09-10 //added Load2DimArrayEquStr(string sEqu[][2],int max_count,char equ,char delimiter);
//---- v1.11 20-12-10 //added FindNthSeqCharPosEnd(string &csRet,char c,int nth,int iStartPos)
//---- v1.12 22-01-11 //added LoadArrayInts( double array[] , int max_count , char delimiter )
// //added LoadArrayDoubles( double array[] , int max_count , char delimiter )
// //inceased #define cnMaxIniEntrySize 65536
//---- v1.13 15-02-11 //added LoadVectorDoubles( vector<double> &vdoub , char delimiter );
//added LoadVectorInts( vector<double> &vint , char delimiter );
//added LoadVectorFloats( vector<float> &vfloat , char delimiter );
//---- v1.14 19-02-11 //added padstr(string &sret,int pad,int lim);
//edded prepadstr(string &sret,int pad,int lim);
//---- v1.15 14-03-11 //added mystr readfile, writefile and LoadVectorStrings
//---- v1.16 18-03-11 //added mystr padstrchar
//---- v1.17 08-04-11 //added mystr toupper() and tolower()
//---- v1.18 22-07-11 //added unicode conversion functions and "#define _FILE_OFFSET_BITS 64"
//---- v1.19 23-07-11 //fixed FindReplace() bug
//---- v1.20 23-07-11 //added cut_at_first_find(), cut_just_past_first_find()
//---- v1.21 23-12-11 //mystr delay_ms( int ms ) for linux/windows, see also 'delay_us()'
//mystr time_start( unsigned long long int start )
//mystr time_passed( unsigned long long int start ) for linux/windows
//---- v1.22 19-01-12 //fixed mystr::readfile(), now returns an int instead of bool, also calls mbc_fopen
//---- v1.23 26-03-13 //added mystr cut_just_past_first_find_and_keep_right(), cut_at_first_find_and_keep_right()
//---- v1.24 23-04-13 //fixed cut_just_past_first_find_and_keep_right() where cut str becomes empty
//---- v1.25 24-04-13 //added get_time_now(), make_date_str(), make_time_str()
//---- v1.26 01-06-13 //fixed mystr::gets() not return 1 on success, and lockup when trying to erase a line with just one char and that char is a CR
//---- v1.27 18-09-13 //added extract_param_vals()
//---- v1.28 13-10-13 //strpf() - increased storage from 1024 to 1MB, Note: if you make buffer too big it crashes
// // linux allowed 4MB, windows only 1MB
//---- v1.29 16-10-13 //added filesize()
//---- v1.30 22-10-13 //fixed extract_param_vals(), where find was used instead of compare
//---- v1.32 17-11-13 //added extract_param_vals_and_raw()
//---- v1.33 03-12-13 //added count_occurrence_char( char ch, int pos )
//---- v1.34 14-12-13 //make_filesize_str_ulli( string &sret, unsigned long long int bytes )
//---- v1.35 07-01-14 //for extract_param_vals(), extract_param_vals_raw() - added allow_unicode_chars flag
//---- v1.36 31-08-14 //fixed large filesize reporting for Windows int mystr::filesize()
//---- v1.36 31-08-14 //added mystr::appendfile()
//---- v1.36 31-08-14 //added mystr::make_filesize_str_ulli_discrete()
//---- v1.37 01-09-14 //fixed get_time_now( ) bug that was always returning Sunday
//---- v1.38 13-09-14 //added: make_single_folder(..), make_folders(..), check_folder_path_exists((..)
//---- v1.39 09-11-14 //added: time_str_to_tm(..), date_str_to_tm(..)
//added: add_slash_at_end_if_it_does_not_have_one(..)
//added: make_dir_file_list(..)
//added: check_only_contains_2chars(..)
//added: check_only_contains_3chars(..)
//added: check_only_contains_4chars(..)
//---- v1.40 15-nov-14 //added: 'struct stat' like fields to 'st_mystr_make_dir_file_list_tag', used in make_dir_file_list(..)
//added: strip_cr_or_lf(..)
//added: str_to_int(..), int_to_str(..)
//added: str_to_double(..), double_to_str(..)
//added: str_to_long_double(..), long_double_to_str(..)
//---- v1.41 16-nov-14 //fixed bug in tn.tm_mon range check in make_date_str( .. )
//---- v1.42 07-dec-14 //added: find_str_pos_in_list(..), add_str_if_not_in_list(..)
//---- v1.43 11-dec-14 //added: length()
//---- v1.44 16-dec-14 //added: strip_leading_chars(..)
//---- v1.45 23-jan-15 //added: padstr_vector(..)
//---- v1.46 30-jan-15 //changed extract_param_vals_and_raw(..) so vraw captures both whitespaces and CRs, thus ignoring flags: 'skip_whitespace' and 'skip_cr'
//---- v1.47 30-jan-15 //added strip_leading_chars_2(..), strip_any_chars2(..), strip_any_chars3(..), strip_any_chars4(..), strip_any_chars5(..), strip_any_chars6(..)
//---- v1.48 05-feb-15 //added count_occurrence_of_char_up_to_pos(..)
//---- v1.49 14-mar-15 //added StrToEscMostCommon1(..)
//---- v1.50 24-apr-15 //added ExtractParamValNotingUserQuotes(..)
//---- v1.51 02-mar-15 //added LoadVectorStringsNotingUserQuotes(..)
//---- v1.52 03-jun-15 //added strip_trailing_char(..), LoadVectorStrings_str_delimiter()
//---- v1.53 26-sep-16 //fixed LoadVectorInts( vector<double> &vint , char delimiter ), now its LoadVectorInts( vector<int> &vint , char delimiter )
//---- v1.54 10-mar-17 //added high precision WritePrivateProfileDOUBLE_precision(), set 'sprecision' to something like: "%.17g"
//---- v1.55 03-jul-17 //added make_engineering_str()
//---- v1.56 15-sep-17 //added get_pos_of_nth_occurrence(), cut_at_nth_occurrence(), cut_just_past_nth_occurrence(),
//cut_just_passed_nth_occurrence_keep_right()
//---- v1.57 15-oct-17 //added warning comments: '!!! WILL STILL return full string if cut did not happen, this can be tested as it returns 0'
//for xxx_keep_right() functions, like in: cut_just_past_first_find_and_keep_right()
//---- v1.58 20-jan-2018 //moded mystr::EscToStr(), had 'sscanf(szHex,"%x",&c);' now: 'sscanf(szHex,"%x",&iChar);' , did this as later versions of gcc
//were causing memory corruptions and endless loop
//---- v1.59 20-feb-2018 //added: tail( schar delim, int max_delimits )
//---- v1.60 18-mar-2018 //added: cut_at_end_of_first_find_and_keep_right(...)
//---- v1.61 17-apr-2018 //moded LoadVectorStrings() - to handle empty delimiter with no chars, like: abc,def,,ghi,jkl
//---- v1.62 27-apr-2018 //added: merge_path_and_stripped_fname(..)
//added: operator+= for both char and string, e.g: m1 += "hello";
//-----v1.63 05-jul-2018 //added: make_engineering_str_exp()
//-----v1.64 27-jul-2018 //added: appendfile_str(), appendfile_sz()
//-----v1.65 08-jul-2018 //added: LoadArray_hex_uint8_t(), LoadArray_hex_int8_t(),
//-----v1.66 01-dec-2018 //added: delay_us( int usec )
//-----v1.67 16-dec-2018 //added: WritePrivateProfile_uint64_t(), WritePrivateProfile_hex_uint64_t(), GetPrivateProfile_uint64_t(), GetPrivateProfile_hex_uint64_t()
//-----v1.68 28-dec-2018 //added: ExtractParamVal_with_delimit(string param, string delim, string &equ),LoadArray_hex_uint8_t(), LoadArray_hex_int8_t(), LoadArray_hex_uint16_t(), LoadArray_hex_int16_t()
//LoadArray_decimal_uint8_t(), LoadArray_decimal_int8_t(), LoadArray_decimal_uint16_t(), LoadArray_decimal_int16_t()
//array_uint8_t_to_hex_str(), array_int8_t_to_decimal_str(), array_uint16_t_to_hex_str(), array_int16_t_to_decimal_str(), array_uint32_t_to_hex_str(), array_int32_t_to_decimal_str()
//-----v1.69 12-oct-2019 //added: StrToEscMostCommon2() - handles '[' and ']'
//-----v1.70 16-oct-2019 //fixed GetPrivateProfileStr() - was incorrectly specifying 'len'
//-----v1.71 03-dec-2019 //fixed ExtractPath(), now returns 1 on success
//-----v1.72 04-jan-2020 //fixed 'cut_just_past_first_find_and_keep_right()', was only cutting off first char of 'sfind'
//-----v1.73 17-nov-2020 //added missing 'return 1;' in 'ExtractFilename()', was causing crash only when optimization in use, e.g: '-O3', happened inside external function 'get_path_app_params()'
//-----v1.74 15-dec-2020 //added: 'GCProfile::ClearAllProfileEntries()'
//-----v1.75 23-dec-2020 //added: 'GCProfile::bneed_save' flag, now when just reading a profile there will be no save in 'GCProfile::~GCProfile()' destructor, this was
//causing data loss if you inadvertantly tried to open a non '.ini' formatted file, i.e: non 'ini' files were being corrupted when trying to read them
//-----v1.76 07-jan-2021 //added: 'mystr::ExtractLastMostFolderName()'
//-----v1.77 25-jan-2021 //added: 'StrToEscMostCommon3()' which converts 'Equal' symbols
//-----v1.78 29-jan-2021 //moded LoadVectorStrings() - to handle first char being a delimiter, like: ,abc,def,,ghi,jkl
//-----v1.79 14-aug-2022 //moded 'make_dir_file_list()' to include relative path, see :'st_mystr_make_dir_file_list_tag.path_relative' !! this does not included a leading 'dir_sep' '/'
//-----v1.80 27-dec-2023 //moded 'GCProfile::Save()' to fix 'fprintf()' write size limit, now uses 'fwrite()'
//-----v1.81 05-feb-2024 //moded 'ExtractParamVal_with_delimit()' to return 0 if extracted param length is zero, e.g. this would happen when extracting 'events0=' when str contained this 'events0=,'
//-----v1.82 04-mar-2024 //removed unused var in printf which caused compiler warning
#include "GCProfile.h"
//note a line entry cannot be bigger that cnMaxIniEntrySize
mystr::mystr()
{
iPos=0;
iLen=0;
mystr_verbose = 1;
}
mystr::mystr(char *s)
{
csStr=s;
iPos=0;
iLen=strlen(s);
mystr_verbose = 1;
}
mystr::mystr(string s)
{
csStr=s;
iPos=0;
iLen=s.length();
mystr_verbose = 1;
}
void mystr::operator=(string csIn)
{
iPos=0;
csStr=csIn;
iLen=csStr.length();
mystr_verbose = 1;
}
void mystr::operator=(char *ptr)
{
csStr=ptr;
iPos=0;
iLen=strlen(ptr);
mystr_verbose = 1;
}
mystr& mystr::operator=(mystr &x)
{
return x;
}
/*
void mystr::operator+( string &x, string &y )
{
csStr = x + y;
iPos = 0;
iLen = csStr.length();
}
*/
void mystr::operator+=( char c )
{
csStr += c;
iPos = 0;
iLen = csStr.length();
}
void mystr::operator+=( string &x )
{
csStr += x;
iPos = 0;
iLen = csStr.length();
}
//return mystr obj's string
const string mystr::str()
{
return csStr;
}
//return mystr obj's string
const char* mystr::szptr()
{
return csStr.c_str();
}
//v1.58 moded EscToStr(), had 'scanf(szHex,"%x",&c);' now: 'scanf(szHex,"%x",&iChar);' , did this as later versions of gcc were causing memory corruptions and endless loop
//find and convert any occurrence of a 'C like' escaped backslash and hex nums, back to a acsii chars
//e.g. are below
// BackSlash= \5c
// Equal= \3d
// Comma= \2c
// CR= \0d
// LF= \0a
// BS= \08
// ESC= \1b
// BEL= \07
//modifies mystr obj's string
//returns 1, of ok, else 0
bool mystr::EscToStr()
{
string s1;
char szHex[sizeof(int)],c;
int iChar;
szHex[2]=0;
//memset( szHex, 0x20, sizeof( szHex ) ); //clear
if(iLen==0) return 0;
for(int i=0;i<iLen;i++) //process each char
{
c=csStr[i];
if(c=='\\') //if backslash read in next two hex chars
{
i++;
if(i>=iLen) goto FinParam;
szHex[0]=csStr[i];
i++;
if(i>=iLen) goto FinParam;
szHex[1]=csStr[i];
sscanf(szHex,"%x",&iChar); //v1.58 - conv 2 hex char to an ascii char
c = (char) iChar; //v1.58
}
s1+=c;
}
FinParam:
csStr=s1; //modify this obj's string
iLen=csStr.length();
iPos=0;
return 1;
}
//!! see also: StrToEscMostCommon1()
//find and convert char occurrence to a 'C like' escaped backslash followed by char's hex values
//YOU MUST also do a backslash '\' firstly, if you did it other than first, this function will get confused by the previous StrToEsc conversions that use a backslash
//e.g. are below
// BackSlash= \5c --You MUST do this firstly, if you want backslashes
// Equal= \3d
// Comma= \2c
// CR= \0d
// LF= \0a
// BS= \08
// ESC= \1b
// BEL= \07
//e.g:
//m1.StrToEsc( '\\' ); //convert multiline to 'c escaped', NOTE backslash MUST be done first
//m1.StrToEsc( '\n' );
//m1.StrToEsc( '\r' );
//m1.StrToEsc( '\t' );
//m1.StrToEsc( ',' );
//m1.StrToEsc( '/' );
//m1.StrToEsc( '*' );
//NOTE: you need to escape any backslashes firstly
//modifies mystr obj's string
//returns 1, of ok, else 0
bool mystr::StrToEsc(char escape)
{
char szNum[15];
string s1,sfind,sreplace;
if(iLen==0) return 0;
//FindReplace(s1,"\\","\\5c",0); //replace all of any backslashes
sreplace="\\"; //make escape backslash and hex num e.g. \3d
sprintf(szNum,"%02x",escape);
szNum[2]=0; //limit to max of 2 hex chars
sreplace+=szNum;
sfind=escape;
FindReplace(s1,sfind,sreplace,0); //replace all occurences
csStr=s1; //modify this obj's string
iLen=csStr.length();
iPos=0;
return 1;
}
// SEE ---> mystr::StrToEscMostCommon2()
//find and convert any of the below defined char occurrence to a 'C like' escaped backslash followed by char's hex values
//e.g. are below
// BackSlash '\\' becomes \5c
// LF '\n' becomes \0a
// CR= '\r' becomes \0d
// Tab= '\t' becomes \09
// Comma= ',' becomes \2c
// FwdSlash= '/' becomes \2f
// Asterisk= '*' becomes \2a
//modifies mystr obj's string
//returns 1, of ok, else 0
bool mystr::StrToEscMostCommon1()
{
char szNum[ 15 ];
string s1;
if( iLen == 0 ) return 0;
for( int i = 0; i < iLen; i++ )
{
char ch = csStr[ i ];
switch( ch )
{
case '\\':
s1 += "\\5c";
break;
case '\n':
s1 += "\\0a";
break;
case '\r':
s1 += "\\0d";
break;
case '\t':
s1 += "\\09";
break;
case ',':
s1 += "\\2c";
break;
case '/':
s1 += "\\2f";
break;
case '*':
s1 += "\\2a";
break;
default:
s1 += ch;
break;
}
}
csStr = s1; //modify this obj's string
iLen = csStr.length();
iPos = 0;
return 1;
}
//find and convert any of the below defined char occurrence to a 'C like' escaped backslash followed by char's hex values
//e.g. are below
// BackSlash '\\' becomes \5c
// LF '\n' becomes \0a
// CR= '\r' becomes \0d
// Tab= '\t' becomes \09
// Comma= ',' becomes \2c
// FwdSlash= '/' becomes \2f
// Asterisk= '*' becomes \2a
// Bracket Left= '[' becomes \5b
// Bracket Right= ']' becomes \5d
//modifies mystr obj's string
//returns 1, of ok, else 0
bool mystr::StrToEscMostCommon2()
{
char szNum[ 15 ];
string s1;
if( iLen == 0 ) return 0;
for( int i = 0; i < iLen; i++ )
{
char ch = csStr[ i ];
switch( ch )
{
case '\\':
s1 += "\\5c";
break;
case '\n':
s1 += "\\0a";
break;
case '\r':
s1 += "\\0d";
break;
case '\t':
s1 += "\\09";
break;
case ',':
s1 += "\\2c";
break;
case '/':
s1 += "\\2f";
break;
case '*':
s1 += "\\2a";
break;
case '[':
s1 += "\\5b";
break;
case ']':
s1 += "\\5d";
break;
default:
s1 += ch;
break;
}
}
csStr = s1; //modify this obj's string
iLen = csStr.length();
iPos = 0;
return 1;
}
//find and convert any of the below defined char occurrence to a 'C like' escaped backslash followed by char's hex values
//e.g. are below
// BackSlash '\\' becomes \5c
// LF '\n' becomes \0a
// CR= '\r' becomes \0d
// Tab= '\t' becomes \09
// Comma= ',' becomes \2c
// FwdSlash= '/' becomes \2f
// Asterisk= '*' becomes \2a
// Bracket Left= '[' becomes \5b
// Bracket Right= ']' becomes \5d
// Equal= '=' becomes \3d
//modifies mystr obj's string
//returns 1, of ok, else 0
bool mystr::StrToEscMostCommon3()
{
char szNum[ 15 ];
string s1;
if( iLen == 0 ) return 0;
for( int i = 0; i < iLen; i++ )
{
char ch = csStr[ i ];
switch( ch )
{
case '\\':
s1 += "\\5c";
break;
case '\n':
s1 += "\\0a";
break;
case '\r':
s1 += "\\0d";
break;
case '\t':
s1 += "\\09";
break;
case ',':
s1 += "\\2c";
break;
case '/':
s1 += "\\2f";
break;
case '*':
s1 += "\\2a";
break;
case '[':
s1 += "\\5b";
break;
case ']':
s1 += "\\5d";
break;
case '=':
s1 += "\\3d";
break;
default:
s1 += ch;
break;
}
}
csStr = s1; //modify this obj's string
iLen = csStr.length();
iPos = 0;
return 1;
}
//load supplied 8bit uint array with numbers extracted from mystr obj's string.
//a suitable string is similar to: 128,127,3,9,8,7,1
//the user defined char delimiter: would be ','
//the results in 'array' would then be the numbers:
// array[0]=128
// array[1]=127
// array[2]=3
// array[3]=9
// array[4]=8
// array[5]=7
// array[6]=1
//returns number of array items loaded, in this case 7
int mystr::LoadArray_decimal_uint8_t( uint8_t array[], int max_count , char delimiter )
{
string snum;
char c;
bool in_num = 0;
int count = 0;
if(iLen==0) return 0;
if(max_count<=0) return 0;
snum="";
for( int i = 0; i < iLen; i++ )
{
c = csStr[i]; //get char
if( c == delimiter) //delimiter?
{
if( in_num )
{
int iv;
sscanf( snum.c_str() , "%d", &iv ); //conv num into int array
array[count] = iv;
in_num = 0;
snum = "";
count++;
if( count >= max_count ) break;
}
else{
continue;
}
}
else{
in_num = 1;
snum += c; //build number
}
}
if( in_num ) //if there is no ending delimiter
{
int iv;
sscanf( snum.c_str() , "%d", &iv ); //conv num into int array
array[count] = iv;
count++;
}
return count;
}
//load supplied 8bit int array with numbers extracted from mystr obj's string.
//a suitable string is similar to: -128,127,3,9,8,7,-1
//the user defined char delimiter: would be ','
//the results in 'array' would then be the numbers:
// array[0]=-128
// array[1]=127
// array[2]=3
// array[3]=9
// array[4]=8
// array[5]=7
// array[6]=-1
//returns number of array items loaded, in this case 7
int mystr::LoadArray_decimal_int8_t( int8_t array[], int max_count , char delimiter )
{
string snum;
char c;
bool in_num = 0;
int count = 0;
if(iLen==0) return 0;
if(max_count<=0) return 0;
snum="";
for( int i = 0; i < iLen; i++ )
{
c = csStr[i]; //get char
if( c == delimiter) //delimiter?
{
if( in_num )
{
int iv;
sscanf( snum.c_str() , "%d", &iv ); //conv num into int array
array[count] = iv;
in_num = 0;
snum = "";
count++;
if( count >= max_count ) break;
}
else{
continue;
}
}
else{
in_num = 1;
snum += c; //build number
}
}
if( in_num ) //if there is no ending delimiter
{
int iv;
sscanf( snum.c_str() , "%d", &iv ); //conv num into int array
array[count] = iv;
count++;
}
return count;
}
//load supplied 16bit uint array with numbers extracted from mystr obj's string.
//a suitable string is similar to: 1,12,3,9,8,7,2345
//the user defined char delimiter: would be ','
//the results in 'array' would then be the numbers:
// array[0]=1
// array[1]=12
// array[2]=3
// array[3]=9
// array[4]=8
// array[5]=7
// array[6]=2345
//returns number of array items loaded, in this case 7
int mystr::LoadArray_decimal_uint16_t( uint16_t array[], int max_count , char delimiter )
{
string snum;
char c;
bool in_num = 0;
int count = 0;
if(iLen==0) return 0;
if(max_count<=0) return 0;
snum="";
for( int i = 0; i < iLen; i++ )
{
c = csStr[i]; //get char
if( c == delimiter) //delimiter?
{
if( in_num )
{
int iv;
sscanf( snum.c_str() , "%d", &iv ); //conv num into int array
array[count] = iv;
in_num = 0;
snum = "";
count++;
if( count >= max_count ) break;
}
else{
continue;
}
}
else{
in_num = 1;
snum += c; //build number
}
}
if( in_num ) //if there is no ending delimiter
{
int iv;
sscanf( snum.c_str() , "%d", &iv ); //conv num into int array
array[count] = iv;
count++;
}
return count;
}
//load supplied 16bit int array with numbers extracted from mystr obj's string.
//a suitable string is similar to: 1,12,3,9,8,7,-2345
//the user defined char delimiter: would be ','
//the results in 'array' would then be the numbers:
// array[0]=1
// array[1]=12
// array[2]=3
// array[3]=9
// array[4]=8
// array[5]=7
// array[6]=-2345
//returns number of array items loaded, in this case 7
int mystr::LoadArray_decimal_int16_t( int16_t array[], int max_count , char delimiter )
{
string snum;
char c;
bool in_num = 0;
int count = 0;
if(iLen==0) return 0;
if(max_count<=0) return 0;
snum="";
for( int i = 0; i < iLen; i++ )
{
c = csStr[i]; //get char
if( c == delimiter) //delimiter?
{
if( in_num )
{
int iv;
sscanf( snum.c_str() , "%d", &iv ); //conv num into int array
array[count] = iv;
in_num = 0;
snum = "";
count++;
if( count >= max_count ) break;
}
else{
continue;
}
}
else{
in_num = 1;
snum += c; //build number
}
}
if( in_num ) //if there is no ending delimiter
{
int iv;
sscanf( snum.c_str() , "%d", &iv ); //conv num into int array
array[count] = iv;
count++;
}
return count;
}
//load supplied 8bit uint array with numbers extracted from mystr obj's string.
//a suitable string is similar to: 1,12,3,9,8,7,af
//the user defined char delimiter: would be ','
//the results in 'array' would then be the numbers:
// array[0]=1
// array[1]=12
// array[2]=3
// array[3]=9
// array[4]=8
// array[5]=7
// array[6]=af
//returns number of array items loaded, in this case 7
int mystr::LoadArray_hex_uint8_t( uint8_t array[], int max_count , char delimiter )
{
string snum;
char c;
bool in_num = 0;
int count = 0;
if(iLen==0) return 0;
if(max_count<=0) return 0;
snum="";
for( int i = 0; i < iLen; i++ )
{
c = csStr[i]; //get char
if( c == delimiter) //delimiter?
{
if( in_num )
{
int iv;
sscanf( snum.c_str() , "%x", &iv ); //conv num into int array
array[count] = iv;
in_num = 0;
snum = "";
count++;
if( count >= max_count ) break;
}
else{
continue;
}
}
else{
in_num = 1;
snum += c; //build number
}
}
if( in_num ) //if there is no ending delimiter
{
int iv;
sscanf( snum.c_str() , "%x", &iv ); //conv num into int array
array[count] = iv;
count++;
}
return count;
}
//load supplied 8bit int array with numbers extracted from mystr obj's string.
//a suitable string is similar to: 1,12,3,9,8,7,af
//the user defined char delimiter: would be ','
//the results in 'array' would then be the numbers: