-
Notifications
You must be signed in to change notification settings - Fork 2
/
qString.cpp
1012 lines (824 loc) · 23.8 KB
/
qString.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
/*
* omnis.xcomp.framework
* =====================
*
* qString.cpp
* Our own version of a string object based on qchar, variable lenght NOT
* limited to 256 characters like Omnis' own str255..
*
* Bastiaan Olij
*
* https://github.com/BastiaanOlij/omnis.xcomp.framework
*/
#include "qString.h"
/********************************************************************************************************************************
* Construct/copy/delete
********************************************************************************************************************************/
// initialise members
void qstring::init() {
mBuffer = 0;
mMaxSize = 0;
#ifdef isunicode
mReturnStr = 0;
#endif
};
// Initialize as empty string
qstring::qstring() {
init();
};
// Initialize as empty string with a buffer of size pSize
qstring::qstring(qlong pSize) {
init();
redim(pSize);
};
// Initialize and copy from another qstring
qstring::qstring(const qstring &pCopy) {
init();
*this = pCopy;
};
#ifdef isunicode
// On non-unicode qchar and char are the same thing so these are not needed
// Initialize and copy from a UTF-8 string (zero terminated)
qstring::qstring(const char *pString) {
init();
copy(pString);
};
// Initialize and copy from a native platform string (usually UTF-16, zero
// terminated)
qstring::qstring(const qoschar *pString) {
init();
copy(pString);
};
#endif
// Initialize and copy from an omnis string (zero terminated)
qstring::qstring(const qchar *pString) {
init();
copy(pString);
};
// Initialize and copy from an omnis string with specific length
qstring::qstring(const qchar *pString, qlong pSize) {
init();
copy(pString, pSize);
};
// Initialize and copy an omnis field value
qstring::qstring(const EXTfldval &pExtFld) {
init();
copy(pExtFld);
};
// Free up memory and destruct
qstring::~qstring() {
if (mBuffer != 0) {
MEMfree(mBuffer);
mBuffer = 0;
mMaxSize = 0;
};
#ifdef isunicode
if (mReturnStr != 0) {
MEMfree(mReturnStr);
mReturnStr = 0;
};
#endif
};
// Create a new qstring instance based on a formatted string
qstring *qstring::newStringFromFormat(const char *pFormat, ...) {
qstring *retString;
va_list arglist;
va_start(arglist, pFormat);
#ifdef isunicode
qstring format(pFormat);
retString = new qstring();
qstring::vAppendFormattedString(*retString, &format, arglist);
#else
char tmpBuffer[2048]; // hopefully 2048 is large enough...
vsprintf(tmpBuffer, pFormat, arglist);
retString = new qstring((qchar *)tmpBuffer); // qchar = char
#endif
va_end(arglist);
return retString;
};
#ifdef isunicode
// This is a simplified version of vprintf but then for qstring/qchar
// We'll build on this eventually
void qstring::vAppendFormattedString(qstring &appendTo, const qstring *pFormat,
va_list pArgList) {
qlong lvPos = 0;
qlong lvLen = pFormat->length();
while (lvPos < lvLen) {
qchar lvChar = (*pFormat)[lvPos];
if (lvChar == '%') {
lvPos++;
lvChar = (*pFormat)[lvPos];
if ((lvChar == '%') || (lvChar == ' ') || (lvPos == lvLen)) {
appendTo += lvChar;
lvPos++;
} else {
qstring lvFormat("%");
// should really change this to a regex or something.. poor mans
// implementation to detect %[flags][width][.precision][length]specifier
// we do NOT support * (multi parameter formatted strings)!
bool lvIsPrefix = true;
bool lvIsFirst = true;
while (lvPos < lvLen) {
if (lvIsFirst && ((lvChar == '-') || (lvChar == '+') ||
(lvChar == ' ') || (lvChar == '#'))) {
// first character is a flag? that is allowed!
lvFormat += lvChar;
} else if (lvIsPrefix && lvChar == '.') {
lvFormat += lvChar;
} else if (lvIsPrefix && lvChar >= '0' && lvChar <= '9') {
lvFormat += lvChar;
} else if (lvChar >= 'a' && lvChar <= 'z') {
lvFormat += lvChar;
lvIsPrefix = false;
} else if (lvChar >= 'A' && lvChar <= 'Z') {
lvFormat += lvChar;
lvIsPrefix = false;
} else {
// we found the end
break;
};
// on to the next character
lvIsFirst = false;
lvPos++;
lvChar = (*pFormat)[lvPos];
};
switch (lvFormat[lvFormat.length() - 1]) {
case 'i': {
char lvBuffer[256];
qlong lvVal;
if (lvFormat[lvFormat.length() - 2] == 'l') {
lvVal = va_arg(pArgList, qlong);
} else {
lvVal = va_arg(pArgList, int);
}
sprintf(lvBuffer, lvFormat.c_str(), lvVal); // cheat, use sprintf.. appendTo += lvBuffer;
appendTo += lvBuffer;
}; break;
case 'f': {
char lvBuffer[256];
double lvVal = va_arg(pArgList, double);
sprintf(lvBuffer, lvFormat.c_str(), lvVal); // cheat, use sprintf.. appendTo += lvBuffer;
appendTo += lvBuffer;
}; break;
case 'c': { // no need for any overhead for characters
char lvVal = va_arg(pArgList, int);
if (lvVal != 0) {
appendTo += lvVal;
};
}; break;
case 's': { // and we can handle strings just fine too
if (lvFormat[lvFormat.length() - 2] == 'q') {
qstring *lvVal = va_arg(pArgList, qstring *);
if (lvVal != 0) {
appendTo += *lvVal;
};
} else {
char *lvVal = va_arg(pArgList, char *);
if (lvVal != 0) {
appendTo += lvVal;
};
};
}; break;
default: { // anything else, leave it up to vsprintf to handle this
// properly...
char lvBuffer[1024 * 16];
vsprintf(lvBuffer, lvFormat.c_str(), pArgList);
appendTo += lvBuffer;
// and discard it for ourselves
int discard = va_arg(pArgList, int);
}; break;
};
};
} else {
// just add
appendTo += lvChar;
lvPos++;
};
};
};
// Create a new qstring instance based on a formatted string
qstring *qstring::newStringFromFormat(const qoschar *pFormat, ...) {
qstring *retString = new qstring();
qstring format(pFormat);
va_list arglist;
va_start(arglist, pFormat);
qstring::vAppendFormattedString(*retString, &format, arglist);
va_end(arglist);
return retString;
};
// Create a new qstring instance based on a formatted string
qstring *newStringFromFormat(const qstring *pFormat, ...) {
qstring *retString = new qstring();
va_list arglist;
va_start(arglist, pFormat);
qstring::vAppendFormattedString(*retString, pFormat, arglist);
va_end(arglist);
return retString;
};
#endif
// Get the length of a qoschar string (UTF-16)
qlong qstring::qosstrlen(const qoschar *pString) {
qlong len = 0;
if (pString != 0) { // ignore NULL pointers
while (pString[len] != 0x00) {
len++;
};
};
return len;
};
// Get the length of an omnis string
qlong qstring::qstrlen(const qchar *pString) {
qlong len = 0;
if (pString != 0) { // ignore NULL pointers
while (pString[len] != 0x00) {
len++;
};
};
return len;
};
// Compare two omnis strings
qshort qstring::qstrcmp(const qchar *pA, const qchar *pB) {
qlong pos = 0;
// protect against NULL pointers
if ((pA == 0) && (pB == 0)) {
return 0;
} else if (pA == 0) {
return -1;
} else if (pB == 0) {
return 1;
}
while (pA[pos] == pB[pos]) {
if (pA[pos] == 0x00) {
return 0; // strings match
};
pos++;
};
// note, if one of the strings is shorter 0x00 will be smaller then whatever
// is in the other string:)
if (pA[pos] < pB[pos]) {
return -1;
} else {
return 1;
};
};
/********************************************************************************************************************************
* Info
********************************************************************************************************************************/
// return a pointer to our string (UTF-32)
const qchar *qstring::cString() const {
if (mBuffer != 0) {
return mBuffer;
} else {
static qchar emptyString[1];
emptyString[0] = 0;
return emptyString;
};
};
// return a pointer to our string (UTF-8)
const char *qstring::c_str() {
if (mBuffer != 0) {
#ifdef isunicode
if (mReturnStr != 0) {
MEMfree(mReturnStr);
mReturnStr = 0;
};
long tmpLen = length();
mReturnStr = (qbyte *)MEMmalloc(UTF8_MAX_BYTES_PER_CHAR * (tmpLen + 1));
if (mReturnStr == 0) {
static char emptyString[] = "";
return emptyString;
} else if (tmpLen == 0) {
mReturnStr[0] = '\0'; // Make sure we zero terminate the string!
} else {
// a UTF8 string can be up to 6 bytes per character so we may be
// allocating WAY to much memory here...
long tmpRealLen = CHRunicode::charToUtf8(mBuffer, tmpLen, mReturnStr);
mReturnStr[tmpRealLen] = '\0'; // Make sure we zero terminate the string!
};
return (char *)mReturnStr;
#else
return (char *)mBuffer; // it's already a c string...
#endif
} else {
static char emptyString[] = "";
return emptyString;
};
};
// return the length our our string in characters
qulong qstring::length() const {
if (mBuffer != 0) {
return qstring::qstrlen(mBuffer);
} else {
return 0;
};
};
/********************************************************************************************************************************
* Modifications
********************************************************************************************************************************/
// resize the buffer
void qstring::redim(qlong pSize, qbool pKeepData) {
if (pSize == 0) {
// Nothing to store?? free up our memory!
if (mBuffer != 0) {
MEMfree(mBuffer);
mBuffer = 0;
mMaxSize = 0;
};
} else {
qchar *newBuffer;
qulong bufferSize = sizeof(qchar) * pSize;
newBuffer = (qchar *)MEMmalloc(bufferSize);
if (newBuffer != 0) { // valid new buffer? Only then we'll recycle our old!
memset(newBuffer, 0,
bufferSize); /* zero out the buffer, lets play nice */
if (mBuffer != 0) {
// Do we need to copy our old data?
if (pKeepData) {
qlong len = this->length() + 1; /* +1, include zero terminator */
len = len > pSize ? pSize : len;
memcpy(newBuffer, mBuffer, sizeof(qchar) * len);
newBuffer[len - 1] =
0; /* make sure we have a zero terminator, this only applies if we
made our buffer smaller */
};
// Now its time to throw away our old buffer...
MEMfree(mBuffer);
};
mBuffer = newBuffer;
mMaxSize = pSize;
};
};
};
#ifdef isunicode
// on non-unicode char and qchar are the same so we don't need this...
// copy a UTF-8 string (zero terminated)
void qstring::copy(const char *pString) {
qlong len = 0;
if (pString != NULL) {
len = strlen(pString);
}
if (len == 0) {
if (mBuffer != 0) {
mBuffer[0] = 0;
};
} else {
/*
on unicode we need to convert our 8bit string!
Use CHRconvFromBytes, assumes UTF-8 content
*/
CHRconvFromBytes newString((qbyte *)pString, len);
copy(newString.dataPtr(), newString.len());
};
};
// copy a native platform string (usually UTF-16, zero terminated)
void qstring::copy(const qoschar *pString) {
qlong len = qstring::qosstrlen(pString);
if (len == 0) {
if (mBuffer != 0) {
mBuffer[0] = 0;
};
} else {
/*
on unicode we need to convert our platform string!
Use CHRconvFromOs, assumes UTF-16 content
*/
CHRconvFromOs newString((qoschar *)pString, len);
copy(newString.dataPtr(), newString.len());
};
};
#endif
// copy an omnis string (zero terminated)
void qstring::copy(const qchar *pString) {
qlong len = qstring::qstrlen(pString); // could have used OMstrlen...
if (len == 0) {
if (mBuffer != 0) {
mBuffer[0] = 0;
};
} else {
if ((len + 1) > mMaxSize) { /* not enough space? Redim! */
redim(len + 1);
};
OMstrcpy(mBuffer, pString);
};
};
// copy an omnis string of specific length
void qstring::copy(const qchar *pString, qlong pSize) {
if (pString == mBuffer) {
// Copying ourselves into ourselves? ignore!
} else if (pSize == 0) {
if (mBuffer != 0) {
mBuffer[0] = 0;
};
} else {
if ((pSize + 1) > mMaxSize) { /* not enough space? Redim! */
redim(pSize + 1);
};
if ((pSize + 1) <=
mMaxSize) { /* double check just in case the redim failed... */
memcpy(mBuffer, pString, pSize * sizeof(qchar));
mBuffer[pSize] = 0; // zero terminate
};
};
};
// copy an omnis field value
void qstring::copy(const EXTfldval &pExtFld) {
qlong tmpLen, tmpRealLen;
// ignore const warnings on value, we are not doing any modifications, need to
// fix this.. note, we assume our fldval contains a character string
// create a buffer large enough for our data
tmpLen = const_cast<EXTfldval &>(pExtFld).getCharLen() +
12; // getBinLen won't modify our object, Tigerlogic should mark this
// as a const function
if (tmpLen > mMaxSize) {
redim(tmpLen, qtrue);
};
if (tmpLen <= mMaxSize) { // always double check in case redim failed
const_cast<EXTfldval &>(pExtFld).getChar(
tmpLen, mBuffer, tmpRealLen,
qtrue); // getChar won't modify our object, Tigerlogic should mark this
// as a const function
tmpLen = tmpRealLen;
mBuffer[tmpLen] = 0; // zero terminate
};
};
// find position of character within string (returns -1 if not found)
qlong qstring::pos(qchar pChar) const {
qlong pos = 0;
if (mBuffer != 0) {
while (mBuffer[pos] != 0) {
if (mBuffer[pos] == pChar) {
return pos;
};
pos++;
};
};
return -1;
};
// get the substring (pLen <= 0 is from end)
qstring qstring::mid(qlong pFrom, qlong pLen) const {
qstring newstring;
if (mBuffer != 0) {
if (pLen <= 0) {
pLen = length() - pFrom - pLen;
};
if (pLen > 0) {
newstring.redim(pLen + 1, false);
while ((mBuffer[pFrom] != 0) && (pLen > 0)) {
newstring += mBuffer[pFrom];
pFrom++;
pLen--;
};
};
};
return newstring;
};
// replace one string with another
void qstring::replace(const char &pWhat, char &pWith) {
replace(qstring(pWhat), qstring(pWith));
};
// replace one string with another
void qstring::replace(const qstring &pWhat, const qstring &pWith) {
qlong ourlen = this->length();
qstring newstring(ourlen);
qlong whatlen = pWhat.length();
qlong pos = 0;
while (pos < ourlen) {
if (pos > ourlen - whatlen) {
newstring += mBuffer[pos];
pos++;
} else if (memcmp(&mBuffer[pos], pWhat.cString(),
whatlen * sizeof(qchar)) == 0) {
newstring += pWith;
pos += whatlen;
} else {
newstring += mBuffer[pos];
pos++;
};
};
// and copy our new string in place
*this = newstring;
};
// Sets the contents of our string to a formatted string
qstring &qstring::setFormattedString(const char *pFormat, ...) {
char tmpBuffer[2048]; // hopefully 2048 is large enough...
va_list arglist;
va_start(arglist, pFormat);
vsprintf(tmpBuffer, pFormat, arglist);
va_end(arglist);
#ifdef isunicode
*this = tmpBuffer;
#else
*this = (qchar *)tmpBuffer;
#endif
return *this; // return ourselves
};
// append an omnis string of specific length
qstring &qstring::appendString(const qchar *pString, qlong pSize) {
qlong ourLen = this->length();
if (pSize == 0) {
// ignore, there is nothing to add..
} else if (ourLen == 0) {
// just copy...
copy(pString, pSize);
} else {
// Append together
if ((ourLen + pSize + 1) > mMaxSize) {
// make space for our complete buffer
redim(ourLen + pSize + 1, qtrue);
};
if ((ourLen + pSize + 1) <=
mMaxSize) { /* always verify if our redim succeeded */
// we use copy mem, this should also be safe if we're adding ourselves to
// ourselves..
memcpy(&mBuffer[ourLen], pString, pSize * sizeof(qchar));
mBuffer[ourLen + pSize] = 0x00;
};
};
return *this;
};
// Adds an Omnis style character into our string (like style(...) in omnis)
qstring &qstring::appendStyle(qchar pStyle, qulong pValue) {
qlong len = this->length();
if ((len + 12) > mMaxSize) {
// redim our buffer but copy the existing contents!
redim(len + 12, qtrue);
};
if ((len + 12) <= mMaxSize) { // always double check in case redim failed
// Code based on sample code in Omnis SDK, note that we start at index 0 not
// index 1 as in the sample code!
mBuffer[len] = txtEsc;
mBuffer[len + 1] = pStyle;
qchar lookup[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
qchar *add = &mBuffer[len + 9];
for (qlong cnt = 1; cnt <= 8; cnt++) {
*add = lookup[pValue & 0x0000000F];
add--;
pValue = pValue >> 4;
};
mBuffer[len + 10] = txtAsciiEnd;
mBuffer[len + 11] = 0; // zero terminate
};
return *this; // return ourselves
};
// Append a formatted string to our string
qstring &qstring::appendFormattedString(const char *pFormat, ...) {
qstring format(pFormat);
va_list arglist;
va_start(arglist, pFormat);
#ifdef isunicode
qstring::vAppendFormattedString(*this, &format, arglist);
#else
char tmpBuffer[2048]; // hopefully 2048 is large enough...
vsprintf(tmpBuffer, pFormat, arglist);
*this += (qchar *)tmpBuffer;
#endif
va_end(arglist);
return *this; // return ourselves
};
#ifdef isunicode
// Append a formatted string to our string
qstring &qstring::appendFormattedString(const qoschar *pFormat, ...) {
qstring format(pFormat);
va_list arglist;
va_start(arglist, pFormat);
qstring::vAppendFormattedString(*this, &format, arglist);
va_end(arglist);
return *this; // return ourselves
};
// Append a formatted string to our string
qstring &qstring::appendFormattedString(const qstring *pFormat, ...) {
va_list arglist;
va_start(arglist, pFormat);
qstring::vAppendFormattedString(*this, pFormat, arglist);
va_end(arglist);
return *this; // return ourselves
};
#endif
// Append a binary to our string (as 0x0123456789ABCDEF)
qstring &qstring::appendBinary(const qbyte *pBuffer, qlong pLen) {
char hex[10];
for (qlong i = 0; i < pLen; i++) {
qbyte byte = pBuffer[i];
sprintf(hex, "%02X", byte);
#ifdef isunicode
*this += hex;
#else
*this += (qchar *)hex;
#endif
};
return *this;
};
// Append an omnis field value to our string
qstring &qstring::appendFldVal(const EXTfldval &value) {
qbyte *tmpBuffer;
qchar data[2048];
qlong len, intvalue;
ffttype valueType;
qshort valueSubtype;
// ignore const warnings on value, we are not doing any modifications, need to
// fix this..
const_cast<EXTfldval &>(value).getType(
valueType, &valueSubtype); // getType won't modify our object, Tigerlogic
// should mark this as a const function
switch (valueType) {
case fftCharacter:
const_cast<EXTfldval &>(value).getChar(
sizeof(data), data, len,
qfalse); // getChar won't modify our object, Tigerlogic should mark this
// as a const function
data[len / sizeof(qchar)] = 0x00;
*this += data;
break;
case fftInteger:
intvalue = const_cast<EXTfldval &>(value)
.getLong(); // getLong won't modify our object, Tigerlogic
// should mark this as a const function
this->appendFormattedString("%i", intvalue);
break;
case fftBinary:
len = const_cast<EXTfldval &>(value)
.getBinLen(); // getBinLen won't modify our object, Tigerlogic
// should mark this as a const function
if (len > 0) {
tmpBuffer = (qbyte *)MEMmalloc(len + 1);
if (tmpBuffer != 0) {
const_cast<EXTfldval &>(value).getBinary(
len, tmpBuffer,
len); // getBinary won't modify our object, Tigerlogic should mark
// this as a const function
this->appendBinary(tmpBuffer, len);
MEMfree(tmpBuffer);
} else {
*this += QTEXT("???");
};
};
break;
default:
// need to implement!!
break;
};
return *this;
};
/********************************************************************************************************************************
* Operators
********************************************************************************************************************************/
// Get access to character at a specific location
qchar &qstring::operator[](qlong pIndex) {
static qchar
returnChar; // we return this only if our index is out of bounds. Protects
// against crashes, does nothing against bugs :)
if (mBuffer == 0) {
returnChar = 0;
return returnChar;
} else {
// We allow access to any character within our buffer, even those after the
// end of our string
if (pIndex < mMaxSize) {
return mBuffer[pIndex];
} else {
returnChar = 0;
return returnChar;
};
};
};
// Get a pointer to character at a specific location
const qchar &qstring::operator[](qlong pIndex) const {
static qchar
returnChar; // we return this only if our index is out of bounds. Protects
// against crashes, does nothing against bugs :)
if (mBuffer == 0) {
returnChar = 0;
return returnChar;
} else {
// We allow access to any character within our buffer, even those after the
// end of our string
if (pIndex < mMaxSize) {
return mBuffer[pIndex];
} else {
returnChar = 0;
return returnChar;
};
};
};
// Copy a string into our string
qstring &qstring::operator=(const qstring &pCopy) {
if (this != &pCopy) {
// no need to copy ourselves...
copy(pCopy.cString(), pCopy.length());
};
return *this;
};
#ifdef isunicode
// Copy a UTF-8 string into our string
qstring &qstring::operator=(const char *pCopy) {
copy(pCopy);
return *this;
};
// Copy a platform string into our string
qstring &qstring::operator=(const qoschar *pCopy) {
copy(pCopy);
return *this;
};
#endif
// Copy an Omnis string into our string
qstring &qstring::operator=(const qchar *pCopy) {
copy(pCopy, qstring::qstrlen(pCopy));
return *this;
};
// Copy an Omnis field value to our string
qstring &qstring::operator=(const EXTfldval &pCopy) {
copy(pCopy);
return *this;
};
// Append a string to our string
qstring &qstring::operator+=(const qstring &pAdd) {
appendString(pAdd.cString(), pAdd.length());
return *this;
};
// Append a character to our string
qstring &qstring::operator+=(const qchar pAdd) {
appendString(&pAdd, 1);
return *this;
};
#ifdef isunicode
// Append a UTF-8 string to our string
qstring &qstring::operator+=(const char *pAdd) {
qstring addstring(pAdd);
appendString(addstring.cString(), addstring.length());
return *this;
};
// Append a platform string to our string
qstring &qstring::operator+=(const qoschar *pAdd) {
qstring addstring(pAdd);
appendString(addstring.cString(), addstring.length());
return *this;
};
#endif
// Append an omnis string to our string
qstring &qstring::operator+=(const qchar *pAdd) {
qlong addLen = qstring::qstrlen(pAdd);
appendString(pAdd, addLen);
return *this;
};
// Append an omnis field value to our string
qstring &qstring::operator+=(const EXTfldval &pAdd) {
appendFldVal(pAdd);
return *this;
};
// Compare if our string is the same as an omnis string
bool qstring::operator==(const qchar *pCompare) const {
const qchar *strA = this->cString();
qlong cmp;
if ((strA == 0) && (pCompare == 0)) {
cmp = 0;
} else if (strA == 0) {
cmp = 1;
} else if (pCompare == 0) {
cmp = -1;
} else {
cmp = qstring::qstrcmp(strA, pCompare);
};
return cmp == 0;
};
// Compare if our string is the same as another string
bool qstring::operator==(const qstring &pCompare) const {
const qchar *strA = this->cString();
const qchar *strB = pCompare.cString();
qlong cmp;
if ((strA == 0) && (strB == 0)) {
cmp = 0;
} else if (strA == 0) {
cmp = 1;
} else if (strB == 0) {
cmp = -1;
} else {
cmp = qstring::qstrcmp(strA, strB);
};
return cmp == 0;
};
// Compare if our string isn't the same as another string
bool qstring::operator!=(const qstring &pCompare) const {
qlong cmp = qstring::qstrcmp(this->cString(), pCompare.cString());
return cmp != 0;
};
// Compare if our string is "smaller" then or the same as another string
bool qstring::operator<=(const qstring &pCompare) const {
qlong cmp = qstring::qstrcmp(this->cString(), pCompare.cString());
return cmp <= 0;
};
// Compare if our string is "bigger" then or the same as another string
bool qstring::operator>=(const qstring &pCompare) const {
qlong cmp = qstring::qstrcmp(this->cString(), pCompare.cString());
return cmp < 0;
};
// Compare if our string is "smaller" then another string