-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathConvert.cpp
1320 lines (1190 loc) · 29.7 KB
/
Convert.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) 2000,2001 Stefan Duffner
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 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <math.h>
#include <qregexp.h>
#include <qstring.h>
// Added by qt3to4:
#include "Convert.h"
#include "IOInfoASCII.h"
#include "IOInfoList.h"
#include <Q3ValueList>
/**
* Standard constructor.
*/
Convert::Convert() {}
/**
* Converts a string representing a binary number into an integer.
* @param s string to convert
* @return converted value
*/
int Convert::binStrToInt(QString s) {
QChar c;
int count;
int power = 0;
int result = 0;
count = s.length();
if (s.isEmpty())
return 0;
count--;
do {
c = s[count--];
if (c == '1')
result += int(pow(2.0, power));
power++;
} while (count >= 0);
return result;
}
/**
* Converts a string representing a hexadecimal number into an integer.
*
* @param hex String with the hexidecimal number
* @param ires Resulting integer value
* @returns true if successful
*/
bool Convert::hexStrToInt(QString hex, int &ires) {
int len;
QString hexdig = "0123456789ABCDEF";
QString tmp = hex;
int dezdig;
int sum = 0;
int count = 0;
len = hex.length();
for (int i = len - 1; i >= 0; i--) {
dezdig = hexdig.find(tmp[i].upper());
if (dezdig < 0) {
ires = 0;
return false;
}
sum += dezdig * int(pow(16.0, count));
count++;
}
ires = sum;
return true;
}
/**
* Converts an integer into a string representing the binary value of that
* integer.
* @param c integer to convert
* @param len length of resulting string
* @return binary string
*/
QString Convert::intToBinStr(int c, int len) {
if (c > pow(2.0, len) - 1 || len == 0)
return QString::null;
QString result;
int ctmp, cm;
ctmp = c;
for (int i = len - 1; i >= 0; i--) {
cm = ctmp - (1 << (i)); // int(pow(2, i));
if (cm >= 0) {
result += "1";
ctmp = cm;
} else
result += "0";
}
return result;
}
/**
* Converts a string representing a binary value into a binary array.
* A binary array is an array of chars where each char represents one bit. The
* bit with the @a lowest index is the MSB.
* Value of 0 means 0, 1 means 1 and 2 means 'don't care'
* The end of the binary array is marked with a decimal '10'.
* @param num number of bits to convert (lenth of buffer-1)
* @param cs string to convert
* @param buffer binary array
*/
IOInfoBin Convert::binStrToX10(int num, const QString cs, IOType t) {
/*
char* buffer = new char[num+1];
QString s;
int len;
int count=0;
IOInfoBin result(t);
s = cs.right(num);
len = s.length();
memset(buffer, 0, num);
for (int i=num-1; i>=0; i--)
{
if (count<len)
{
switch (s[len-count-1].latin1())
{
case '0': buffer[i]=0; break;
case '1': buffer[i]=1; break;
case 'x': buffer[i]=2; break;
}
}
else
buffer[i]=0;
count++;
}
// if (num>0)
buffer[num]=10;
result.setInfo(buffer);
delete [] buffer;
return result;
*/
IOInfoBin result(t, cs);
return result;
}
/**
* Converts a binary array into an string.
* @param io Object containing binary information
* @return converted string
*/
QString Convert::X10ToBinStr(IOInfoBin io) {
/* QString s;
int num;
char* buffer;
buffer = io.getInfo();
num = io.getLength();
if (!buffer)
return "";
for (int i=0; i<num; i++)
{
switch (buffer[i])
{
case 2:
s = s + "x";
break;
case 1:
s = s + "1";
break;
default:
s = s + "0";
}
}
return s;
*/
return io.getInfo();
}
/**
* Converts a binary string into decimal representation.
*
* @param io Object containing binary information
* @param dec Resulting decimal representation
* @returns true if successful
*/
bool Convert::X10ToDec(IOInfoBin io, int &dec) {
/*
int len = io.getLength();
int count=0;
int sum=0;
int btmp;
char* info = io.getInfo();
while (count<len)
{
btmp = info[count];
if (btmp==1)
sum += (int)pow(2.0, len-count-1);
else if (btmp==2)
return false;
count++;
}
dec = sum;
return true;
*/
QString info = io.getInfo();
dec = 0;
if (!io.isSingle())
return false;
for (int c = info.length() - 1; c >= 0; c--)
if (info[c] == '1')
dec += 1 << c;
return true;
}
/**
* Converts a binary string into ASCII representation.
*
* @param io Object containing binary information
* @param ascii Resulting array of ascii characters
* @param asciiarraylen Length of @a ascii
* @param length Number of characters that have been converted
* @param singlechar If true only a single character is converted
* @returns true if successful
*/
bool Convert::X10ToASCII(IOInfoBin io, unsigned char *ascii, int asciiarraylen,
int &length, bool singlechar /*=true*/) {
/*
int itmp;
bool ok;
IOInfoBin iotmp = io;
iotmp.setInputsSize(8);
ok = X10ToDec(iotmp, itmp);
cres = (char)itmp;
return ok;
*/
QString binstr;
binstr = X10ToBinStr(io);
if (!binStrToASCII(binstr, ascii, asciiarraylen, length, singlechar)) {
length = 0;
return false;
}
return true;
}
/*
* Inverts a binary array.
* @param len number of bits to invert
* @param buffer buffer containing bits to be converted
* @param inverted inverted bits
*/
/*
void Convert::invertX10(int len, char* buffer, char* inverted)
{
for(int i=0; i<len; i++)
inverted[i]=buffer[len-1-i];
inverted[len]=10;
}
*/
/**
* Converts a string representing a hexadecimal number into a binary array.
* @param len number of bits to convert (length of binary array)
* @param hex string containing hexadecimal number
* @param bin buffer for resulting binary data
*/
IOInfoBin Convert::hexStrToX10(int len, const QString hex, IOType t) {
/*
int dezdig;
QString hexdig = "0123456789ABCDEF";
int count=0;
QString actdig;
int slen = hex.length();
int numconv=0; // number of converted bits
char* bintmp = new char[slen*4+1];
int diff1=0, diff2=0;
char* bin = new char[len+1];
IOInfoBin result(t);
memset(bintmp, 0, 4*slen);
memset(bin, 0, len);
count = (slen*4-len)/4; // ignore leading digits
if (count<0)
count=0;
while (count<slen)
{
actdig = hex[count].upper();
dezdig = hexdig.find(actdig);
if (dezdig==-1)
dezdig=0;
for(int i=3; i>=0; i--)
{
// if (numconv+3-i<len)
{
if (dezdig-int(pow(2.0,i)+0.5)>=0)
{
bintmp[numconv+3-i]=1;
dezdig-=int(pow(2.0,i)+0.5);
}
else
bintmp[numconv+3-i]=0;
}
}
count++;
numconv+=4;
}
if (len%4)
diff2=4-len%4;
if (4*slen<len)
diff1=len-4*slen;
if (numconv>len)
numconv=len;
memcpy(bin+diff1, bintmp+diff2, numconv);
bin[len]=10;
// invertX10(len, bininv, bin);
result.setInfo(bin);
delete [] bintmp;
delete [] bin;
return result;
*/
QString binString("");
for (int c = 0; c < hex.length(); c++) {
switch (hex[c].latin1()) {
case '0':
binString += "0000";
break;
case '1':
binString += "0001";
break;
case '2':
binString += "0010";
break;
case '3':
binString += "0011";
break;
case '4':
binString += "0100";
break;
case '5':
binString += "0101";
break;
case '6':
binString += "0110";
break;
case '7':
binString += "0111";
break;
case '8':
binString += "1000";
break;
case '9':
binString += "1001";
break;
case 'A':
binString += "1010";
break;
case 'B':
binString += "1011";
break;
case 'C':
binString += "1100";
break;
case 'D':
binString += "1101";
break;
case 'E':
binString += "1110";
break;
case 'F':
binString += "1111";
break;
}
}
binString.resize(len);
IOInfoBin result(t, binString);
return result;
}
/**
* Converts a binary array into a string containing the corresponding
* hexadecimal value.
* @param len length of binary array
* @param bininv binary data
* @return string with hexadecimal data
*/
QString Convert::X10ToHexStr(/*int len, char* bininv*/ IOInfoBin invio) {
if (!invio.isSingle())
return QString("");
int count = 0;
int dsum = 0;
QString hexdig = "0123456789ABCDEF";
QString bin; //= new char[len+1];
IOInfoBin io(invio.getType());
// Convert conv;
QString hex;
int len;
// conv.invertX10(len, bininv, bin);
io = invio;
io.invertBits();
bin = io.getInfo();
len = bin.length();
while (count < len) {
dsum = 0;
for (int i = 0; i < 4; i++) {
if (count < len)
dsum += int(pow(2.0, i) + 0.5) * (bin[count].toLatin1() - 48);
count++;
}
hex = hexdig[dsum] + hex;
}
// delete [] bin;
return hex;
}
/**
* Converts a binary string into a hexadecimal string.
* @param bin string containing the binary value
* @return string containing the hexadecimal value
*/
QString Convert::binStrToHexStr(const QString bin) {
int len;
int count;
QString hex;
int dsum = 0;
QChar c;
int dig;
len = bin.length();
count = len - 1;
while (count >= 0) {
dsum = 0;
for (int i = 3; i >= 0; i--) {
if (count - i >= 0) {
c = bin[count - i];
dig = c.digitValue();
if (dig < 0)
dig = 0;
dsum += int(pow(2.0, i) + 0.5) * dig;
}
}
switch (dsum) {
case 0:
hex = "0" + hex;
break;
case 1:
hex = "1" + hex;
break;
case 2:
hex = "2" + hex;
break;
case 3:
hex = "3" + hex;
break;
case 4:
hex = "4" + hex;
break;
case 5:
hex = "5" + hex;
break;
case 6:
hex = "6" + hex;
break;
case 7:
hex = "7" + hex;
break;
case 8:
hex = "8" + hex;
break;
case 9:
hex = "9" + hex;
break;
case 10:
hex = "A" + hex;
break;
case 11:
hex = "B" + hex;
break;
case 12:
hex = "C" + hex;
break;
case 13:
hex = "D" + hex;
break;
case 14:
hex = "E" + hex;
break;
case 15:
hex = "F" + hex;
break;
}
count -= 4;
}
return hex;
}
/**
* Converts a string representing a binary number into ASCII representation
*
* @param bin String with the binary number
* @param ascii Array holding the resulting string of ASCII characters
* @param arraymaxlen Length of the array @a ascii
* @param length Number of converted characters
* @param singlechar If true only the first character is converted.
* @returns true if successful
*/
bool Convert::binStrToASCII(const QString bin, unsigned char *ascii,
int arraymaxlen, int &length,
bool singlechar /*=true*/, int arrayoffset /*=0*/) {
if (arraymaxlen == 0)
return false;
int itmp;
int binlen;
length = 0;
int newlen, scanend;
QString rbin, sdiff;
QString bin8;
int count;
int firstxpos;
int tmplength1 = 0, tmplength2 = 0;
rbin = bin;
rbin.replace(QRegExp("\\s"), "");
if (singlechar) {
if (rbin.find(QRegExp("[^01]")) != -1)
return false;
} else {
if (rbin.find(QRegExp("[^01xX]")) != -1)
return false;
}
// cx = rbin.contains("x", false);
firstxpos = rbin.find("x", 0, false);
if (firstxpos != -1) {
rbin.replace(firstxpos, 1, "0");
binStrToASCII(rbin, ascii, arraymaxlen, tmplength1, singlechar,
arrayoffset);
rbin.replace(firstxpos, 1, "1");
// rbin.replace(QRegExp("[xX]"), "0");
binStrToASCII(rbin, ascii, arraymaxlen - tmplength1, tmplength2, singlechar,
arrayoffset + tmplength1);
length = tmplength1 + tmplength2;
} else {
binlen = rbin.length();
newlen = int((double)binlen / 8 + 0.9) * 8;
if (singlechar)
newlen = 8;
if (newlen >= binlen) {
sdiff.fill('0', newlen - binlen);
rbin.prepend(sdiff);
newlen = rbin.length();
} else
rbin = rbin.right(newlen);
length = newlen / 8;
count = length - 1;
scanend = newlen - 1;
while (scanend > 0 && count >= 0 && count < arraymaxlen) {
bin8 = rbin.mid(scanend - 7, 8);
if (bin8.isEmpty())
bin8 = rbin.mid(0, scanend + 1);
if (bin8.isEmpty())
return false;
if (!bin8.isEmpty()) {
itmp = binStrToInt(bin8);
unsigned char ctmp = (unsigned char)itmp;
ascii[arrayoffset + count] = ctmp;
count--;
}
scanend -= 8;
}
}
return true;
}
/**
* Converts a hexadecimal string into a binary string.
* @param maxlen length the binary string will have
* @param hex string containing a hexadecimal number
* @return string containing the binary number
*/
QString Convert::hexStrToBinStr(int maxlen, const QString hex) {
int len;
QString tmp = hex;
QString hexdig = "0123456789ABCDEF";
int dezdig;
QString bin;
len = hex.length();
for (int i = len - 1; i >= 0; i--) {
dezdig = hexdig.find(tmp[i].upper());
if (dezdig < 0)
dezdig = 0;
switch (dezdig) {
case 0:
bin = "0000" + bin;
break;
case 1:
bin = "0001" + bin;
break;
case 2:
bin = "0010" + bin;
break;
case 3:
bin = "0011" + bin;
break;
case 4:
bin = "0100" + bin;
break;
case 5:
bin = "0101" + bin;
break;
case 6:
bin = "0110" + bin;
break;
case 7:
bin = "0111" + bin;
break;
case 8:
bin = "1000" + bin;
break;
case 9:
bin = "1001" + bin;
break;
case 10:
bin = "1010" + bin;
break;
case 11:
bin = "1011" + bin;
break;
case 12:
bin = "1100" + bin;
break;
case 13:
bin = "1101" + bin;
break;
case 14:
bin = "1110" + bin;
break;
case 15:
bin = "1111" + bin;
break;
}
}
bin = bin.right(maxlen);
return bin;
}
/**
* Converts a string representing a hexadecimal number into ASCII representation
*
* @param bin String with the hexadecimal number
* @param ascii Array holding the resulting string of ASCII characters
* @param maxarraylen Length of the array @a ascii
* @param length Number of converted characters
* @param singlechar If true only the first character is converted.
* @returns true if successful
*/
bool Convert::hexStrToASCII(const QString hex, unsigned char *ascii,
int maxarraylen, int &length,
bool singlechar /*=true*/) {
int itmp;
QString rhex;
int count = 0, aindex;
int hexlen;
unsigned char ctmp;
length = 0;
rhex = hex;
rhex.replace(QRegExp("\\s"), "");
if (rhex.find(QRegExp("[^\\da-fA-F]")) != -1)
return false;
hexlen = rhex.length();
if (hexlen % 2)
rhex = "0" + rhex;
if (singlechar)
rhex = rhex.right(2);
hexlen = rhex.length();
aindex = 0;
while (count < hexlen && aindex < maxarraylen) {
if (count + 1 < hexlen) {
if (!hexStrToInt(rhex.mid(count, 2), itmp))
return false;
} else {
if (!hexStrToInt(rhex.mid(count, 1), itmp))
return false;
}
ctmp = (unsigned char)itmp;
ascii[aindex++] = ctmp;
count += 2;
}
length = aindex;
return true;
}
/**
* Converts an ASCII string into a string representing the binary number
*
* @param maxlen Maximum length of the binary string
* @param ascii Array holding the ASCII characters
* @param asciilen Length of the string of ASCII characters
* (can be smaller than the array size)
* @returns The string representing the binary number
*/
QString Convert::asciiToBinStr(int maxlen, const unsigned char *ascii,
int asciilen) {
QString hex, bin;
int newlen;
newlen = (maxlen + 7) / 8;
if (newlen > asciilen)
newlen = asciilen;
hex = asciiToHexStr(ascii, newlen);
// qDebug("hex: %s", hex.latin1());
bin = hexStrToBinStr(maxlen, hex);
// qDebug("bin: %s", bin.latin1());
return bin;
}
/**
* Converts a single ASCII character into a string representing the binary
* number
*
* @param maxlen Maximum length of the binary string
* @param ascii The ASCII character to convert
* @returns The string representing the binary number
*/
QString Convert::asciiToBinStr(int maxlen, const unsigned char ascii) {
return asciiToBinStr(maxlen, &ascii, 1);
}
/**
* Converts an ASCII string into a string representing the hexadecimal number
*
* @param ascii Array holding the ASCII characters
* @param asciilen Length of the string of ASCII characters
* (can be smaller than the array size)
* @returns The string representing the hexadecimal number
*/
QString Convert::asciiToHexStr(const unsigned char *ascii, int asciilen) {
QString hex = "";
int itmp, k;
// char cnext;
for (int i = 0; i < asciilen; i++) {
itmp = (int)(unsigned char)ascii[i];
k = itmp / 16;
// first digit
switch (k) {
case 0:
hex += "0";
break;
case 1:
hex += "1";
break;
case 2:
hex += "2";
break;
case 3:
hex += "3";
break;
case 4:
hex += "4";
break;
case 5:
hex += "5";
break;
case 6:
hex += "6";
break;
case 7:
hex += "7";
break;
case 8:
hex += "8";
break;
case 9:
hex += "9";
break;
case 10:
hex += "A";
break;
case 11:
hex += "B";
break;
case 12:
hex += "C";
break;
case 13:
hex += "D";
break;
case 14:
hex += "E";
break;
case 15:
hex += "F";
break;
}
itmp -= int(16 * k);
// second digit
switch (itmp) {
case 0:
hex += "0";
break;
case 1:
hex += "1";
break;
case 2:
hex += "2";
break;
case 3:
hex += "3";
break;
case 4:
hex += "4";
break;
case 5:
hex += "5";
break;
case 6:
hex += "6";
break;
case 7:
hex += "7";
break;
case 8:
hex += "8";
break;
case 9:
hex += "9";
break;
case 10:
hex += "A";
break;
case 11:
hex += "B";
break;
case 12:
hex += "C";
break;
case 13:
hex += "D";
break;
case 14:
hex += "E";
break;
case 15:
hex += "F";
break;
}
}
return hex;
}
/**
* Converts a single ASCII character into hexadecimal representation
*
* @param ascii ASCII character to convert.
* @returns String representing the hexadecimal number
*/
QString Convert::asciiToHexStr(const unsigned char ascii) {
return asciiToHexStr(&ascii, 1);
}
/**
* Converts a string of ASCII characters into binary representation
*
* @param maxlen Maximum length of the binary string
* @param ascii Array of ASCII characters
* @param asciilen Number of ASCII characters stores in the array
* @returns Object with the binary number
*/
IOInfoBin Convert::asciiToX10(int maxlen, const unsigned char *ascii,
int asciilen, IOType t) {
QString binstr;
binstr = asciiToBinStr(maxlen, ascii, asciilen);
return binStrToX10(maxlen, binstr, t);
}
/**
* Converts a single ASCII character into binary representation
*
* @param maxlen Maximum length of the binary string
* @param ascii ASCII character to convert
* @returns Object with the binary number
*/
IOInfoBin Convert::asciiToX10(int maxlen, const unsigned char ascii, IOType t) {
return asciiToX10(maxlen, &ascii, 1, t);
}
/**
* Resolves the escape symbols in a string of ASCII characters.
*
* Example: \d is resolved into 0123456789 (digit)
*
* @param estr String of characters possibly with escape symbols
* @param cres Resulting array of ascii characters
* @param arraymaxlen Length of the array
* @param length Number characters stores in the array after resolution
*/
void Convert::resolveEscapes(QString estr, unsigned char *cres, int arraymaxlen,
int &length) {
int i = 0;
int len;
unsigned char ctmp, cprev = 0;
bool nextisescape = false;
bool nextisdigit, previsdigit = false;
QString sinf;
Convert conv;
int fc;
length = 0;
len = estr.length();
while (i < len) {
nextisdigit = false;
ctmp = estr[i].latin1();
if (ctmp == '\\') // escape sequence
{
if (i == len - 1)
break;
unsigned char cnext;
cnext = estr[i + 1].latin1();
if (cnext == 'd') // digit
{
for (fc = '0'; fc <= '9'; fc++) {
if (length >= arraymaxlen)
return;
cres[length++] = fc;
}
previsdigit = true;
} else {
if (cnext ==