summaryrefslogtreecommitdiff
path: root/xbase64/xbstring.cpp
blob: 419014f57ed5044c3ef5c42fe8373ab36b684703 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
/*  xbstring.cpp
 
    Xbase64 project source code

    This file contains the xbString object methods

    Copyright (C) 1997,2003  Gary A Kunkel
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU Lesser 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 Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser 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


    Contact:
    
     Email:
    
      xdb-devel@lists.sourceforge.net
      xdb-users@lists.sourceforge.net
      
      
     Regular Mail:
     
       XBase Support
       149C South Main St
       Keller Texas, 76248     
       USA

*/

#ifdef __GNU LesserG__
  #pragma implementation "xbstring.h"
#endif

#ifdef __WIN32__
#include <xbase64/xbwincfg.h>
#else
#include <xbase64/xbconfig.h>
#endif

#include <xbase64/xbase64.h>

#include <stdlib.h>
#include <stdio.h>

#ifdef HAVE_STRING_H
#include <string.h>
#endif

#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif

#ifdef STDC_HEADERS
#include <stdarg.h>
#endif

#ifdef HAVE_CTYPE_H
#include <ctype.h>
#endif

#include <xbase64/xbstring.h>
//#include <xbase64/xbexcept.h>

//#define free(x)

/*! \file xbstring.cpp
*/

const char * xbString::NullString = "";

//! Short description.
/*!
*/
xbString::xbString() {
  ctor(NULL);
}

//! Short description.
/*!
  \param size
*/
xbString::xbString(size_t size) {
  data = (char *)calloc(1, size);
  this->size = size;
}

//! Short description.
/*!
  \param c
*/
xbString::xbString(char c) {
  ctor(NULL);
  *this = c;
}

//! Short description.
/*!
  \param s
*/
xbString::xbString(const char *s) {
  ctor(s);
}

//! Short description.
/*!
  \param s
*/
xbString::xbString(const xbString &s) {
  ctor((const char *)s);
}

//! Short description.
/*!
  \param s
  \param maxlen
*/
xbString::xbString(const char *s, size_t maxlen) {
#if 0
  size_t len = strlen(s);
  
  if(len < maxlen)
    maxlen = len;
#endif    

  size = maxlen + 1;
  data = (char *)calloc(1, size);
  strncpy(data, s, maxlen);
  data[maxlen] = 0;
}

//! Short description.
/*!
*/
xbString::~xbString() {
  if (data != NULL)
    free(data);
}

//! Short description.
/*!
  \param s
*/
void xbString::ctor(const char *s) {
  if (s == NULL) {
    data = NULL;
    size = 0;
    return;
  }

  size = strlen(s) + 1;

  data = (char *)calloc(1, size);
  strcpy(data, s);
}

//! Short description.
/*!
  \param s
  \param maxlen
*/
void xbString::ctor(const char *s, size_t maxlen) {

  if (s == NULL) {
    data = NULL;
    size =0;
    return;
  }
  size = maxlen + 1;
  data = (char *)calloc(1, size);
  strncpy(data, s, maxlen);
  data[maxlen] = 0;
}

//! Short description.
/*!
*/
xbString &xbString::operator=(char c) {
  if (data != NULL)
    free(data);

  data = (char *)calloc(1, 2);
  data[0] = c;
  data[1] = 0;

  size = 2;

  return (*this);
}

//! Short description.
/*!
*/
xbString &xbString::operator=(const xbString &s) {
  if (data != NULL)
    free(data);

  const char *sd = s;
  if (sd == NULL) {
    data = NULL;
    size = 0;
    return (*this);
  }

  data = (char *)calloc(1, strlen(s) + 1);
  strcpy(data, s);

  size = strlen(data)+1;
  
  return (*this);
}

//! Short description.
/*!
*/
xbString &xbString::operator=(const char *s) {
  if(data != NULL)
    free(data);

  if(s == NULL) {
    data = NULL;
    size = 0;
    return (*this);
  }
  data = (char *)calloc(1, strlen(s) + 1);
  strcpy(data, s);
  size = strlen(data) + 1;
  return (*this);
}

//! Short description.
/*!
  \param size
*/
void xbString::resize(size_t size) {
  data = (char *)realloc(data, size);
  if( size > 0 )
    data[size-1] = 0;
  this->size = size;
}
     
//! Short description.
/*!
*/
xbBool xbString::isNull() const {
  return( data == NULL );
}

//! Short description.
/*!
*/
xbBool xbString::isEmpty() const {
  if( data == NULL )
    return true;
  if( data[0] == 0 )
    return true;
  return false;
}

//! Short description.
/*!
*/
size_t xbString::len() const {
  return( data ? strlen(data) : 0 );
}

//! Short description.
/*!
*/
size_t xbString::length() const {
  return len();
}

//! Short description.
/*!
*/
xbString xbString::copy() const {
  return( *this );
}

//! Short description.
/*!
  \param format
*/
xbString &xbString::sprintf(const char *format, ...) {
  va_list ap;
  va_start(ap, format);

  if (size < 256)
    resize(256);              // make string big enough

#ifdef HAVE_VSNPRINTF
  if (vsnprintf(data, size, format, ap) == -1)
    data[size-1] = 0;
#else
#  if HAVE_VSPRINTF
  vsprintf(data, format, ap);
#  else
#      error "You have neither vsprintf nor vsnprintf!!!"
#  endif
#endif

  resize(strlen(data)+1);               // truncate
  va_end(ap);
  return (*this);
}

//! Short description.
/*!
*/
xbString::operator const char *() const {
  return (data != NULL) ? data : NullString;
}

//! Short description.
/*!
*/
xbString &xbString::operator-=(const char *s) {
  if( s == NULL ) return (*this);
  int len = strlen(s);
  int oldlen = this->len();

  data = (char *)realloc(data, oldlen+len+1);
  if( oldlen == 0 ) data[0] = 0;

  // looking for an occurence of space in the first string
  char *lftspc = strchr(data,' ');
  if( lftspc==NULL ) { // left string has no spaces
    strcat(data,s);
  } else { // left string has one or more spaces
    int numspc = strlen(lftspc);
    strcpy(lftspc,s);
    while( numspc-- > 0 ) strcat(lftspc," ");
  }

  size += len;
  return (*this);
}

//! Short description.
/*!
*/
xbString &xbString::operator+=(const char *s) {
  if (s == NULL)
    return (*this);
  int len = strlen(s);
  int oldlen = this->len();

  data = (char *)realloc(data, oldlen+len+1);
   if (oldlen == 0)
      data[0] = 0;
  strcat(data, s);

  size += len;
  return (*this);
}

//! Short description.
/*!
*/
xbString &xbString::operator+=(char c) {
  int len = 1;
  int oldlen = this->len();

  data = (char *)realloc(data, oldlen+len+1);
  data[oldlen] = c;
  data[oldlen+1] = 0;

  size++;

  return (*this);
}

//! Short description.
/*!
*/
const char *xbString::getData() const {
  return data ? data : NullString;
}

//! Short description.
/*!
*/
const char *xbString::c_str() const {
  return data ? data : NullString;
}

//! Short description.
/*!
*/
void xbString::toLowerCase() {
  int len = this->len();
  for (int i=0;i<len;i++)
    data[i] = (char)tolower(data[i]);
}


//! Short description.
/*!
*/
void xbString::toUpperCase() {
  int len = this->len();
  for (int i=0;i<len;i++)
    data[i] = (char)toupper(data[i]);
}


//! Short description.
/*!
  \param c
*/
int xbString::pos(char c) {
  if (data == NULL)
    return (-1);

  const char *p = strchr(data, c);

  if (p == NULL)
    return (-1);

  return p-data;
}

//! Short description.
/*!
  \param s
*/
int xbString::pos(const char* s) {
  if (data == NULL)
    return (-1);

  const char *p = strstr(data, s);

  if (p == NULL)
    return (-1);

  return p-data;
}

//! Short description.
/*!
  \param num
*/
void xbString::setNum(long num) {
  sprintf("%ld", num);
}

//! Short description.
/*!
  \param fmt
  \param num
*/

void xbString::setNum( char * fmt, double num) {
  xbString f;
  f = "%";
  f += fmt;
  f += "f";
  sprintf( f.getData(), num);
}


//! Short description.
/*!
*/
XBDLLEXPORT xbBool operator==(const xbString &s1, const char *s2) {
  if (s2 == NULL) {
    if (s1.getData() == NULL)
      return true;
    return false;
  }

   if ((s2[0] == 0) && s1.getData() == NULL)
      return true;

  if (s1.getData() == NULL)
    return false;

  return (strcmp(s1, s2) == 0);
}

//! Short description.
/*!
*/
XBDLLEXPORT xbBool operator!=(const xbString &s1, const char *s2) {
  if (s2 == NULL) {
    if (s1.getData() == NULL)
      return false;
    return true;
  }

   if ((s2[0] == 0) && s1.getData() == NULL)
      return false;

  if (s1.getData() == NULL)
    return true;

  return (strcmp(s1, s2) != 0);
}

//! Short description.
/*!
*/
xbBool xbString::operator==( const xbString &s2 ) const {
  if( data == NULL || data[0] == 0 ) {
    if( s2.data == NULL || s2.data[0] == 0 ) return true; // NULL == NULL
    return false; // NULL == !NULL
  } else {
    if( s2.data == NULL || s2.data[0] == 0 ) return false; // !NULL == NULL
    return strcmp(data,s2.data) == 0; //!NULL == !NULL
  }
}

//! Short description.
/*!
*/
xbBool xbString::operator!=( const xbString &s2 ) const {
  if( data == NULL || data[0] == 0 ) {
    if( s2.data == NULL || s2.data[0] == 0 ) return false; // NULL != NULL
    return true; // NULL != !NULL
  } else {
    if( s2.data == NULL || s2.data[0] == 0 ) return true; // !NULL != NULL
    return strcmp(data,s2.data) != 0; //!NULL != !NULL
  }
}

//! Short description.
/*!
*/
xbBool xbString::operator< ( const xbString &s2 ) const {
  if( data == NULL || data[0] == 0 ) {
    if( s2.data == NULL || s2.data[0] == 0 ) return false; // NULL < NULL
    return true; // NULL < !NULL
  } else {
    if( s2.data == NULL || s2.data[0] == 0 ) return false; // !NULL < NULL
    return strcmp(data,s2.data) < 0; //!NULL < !NULL
  }
}

//! Short description.
/*!
*/
xbBool xbString::operator> ( const xbString &s2 ) const {
  if( data == NULL || data[0] == 0 ) {
    if( s2.data == NULL || s2.data[0] == 0 ) return false; // NULL > NULL
    return false; // NULL > !NULL
  } else {
    if( s2.data == NULL || s2.data[0] == 0 ) return true; // !NULL > NULL
    return strcmp(data,s2.data) > 0; //!NULL > !NULL
  }
}

//! Short description.
/*!
*/
xbBool xbString::operator<=( const xbString &s2 ) const {
  if( data == NULL || data[0] == 0 ) {
    if( s2.data == NULL || s2.data[0] == 0 ) return true; // NULL <= NULL
    return true; // NULL <= !NULL
  } else {
    if( s2.data == NULL || s2.data[0] == 0 ) return false; // !NULL <= NULL
    return strcmp(data,s2.data) <= 0; //!NULL <= !NULL
  }
}

//! Short description.
/*!
*/
xbBool xbString::operator>=( const xbString &s2 ) const {
  if( data == NULL || data[0] == 0 ) {
    if( s2.data == NULL || s2.data[0] == 0 ) return true; // NULL >= NULL
    return false; // NULL >= !NULL
  } else {
    if( s2.data == NULL || s2.data[0] == 0 ) return true; // !NULL >= NULL
    return strcmp(data,s2.data) >= 0; //!NULL >= !NULL
  }
}

//! Short description.
/*!
*/
XBDLLEXPORT std::ostream& operator<< ( std::ostream& os,
                                       const xbString& xbs ) {
  return os << xbs.data;
}

//! Short description.
/*!
*/
XBDLLEXPORT xbString operator-(const xbString &s1, const xbString &s2) {
   xbString tmp(s1.getData());
   tmp -= s2;
   return tmp;
}

//! Short description.
/*!
*/
XBDLLEXPORT xbString operator+(const xbString &s1, const xbString &s2) {
   xbString tmp(s1.getData());
   tmp += s2;
   return tmp;
}

//! Short description.
/*!
*/
XBDLLEXPORT xbString operator+(const xbString &s1, const char *s2) {
   xbString tmp(s1.getData());
   tmp += s2;
   return tmp;
}

//! Short description.
/*!
*/
XBDLLEXPORT xbString operator+(const char *s1, const xbString &s2) {
   xbString tmp(s1);
   tmp += s2;
   return tmp;
}

//! Short description.
/*!
*/
XBDLLEXPORT xbString operator+(const xbString &s1, char c2) {
   xbString tmp(s1.getData());
   tmp += c2;
   return tmp;
}

//! Short description.
/*!
*/
XBDLLEXPORT xbString operator+(char c1, const xbString &s2) {
   xbString tmp(c1);
   tmp += s2;
   return tmp;
}

//! Short description.
/*!
  \param pos
  \param c
*/
void xbString::putAt(size_t pos, char c) {
   if (pos>len())
      return;

   data[pos] = c;
}

//! Short description.
/*!
  \param str
  \param pos
  \param n
*/
xbString& xbString::assign(const xbString& str, size_t pos, int n)
{
  if(data){
    free(data);
    data = 0;
  }

  if(str.len() <= pos){
    size = 0;
    return (*this);
  }

  if(str.len() < pos + n){
    n = str.len() - pos;
  }

  const char *d = str;

  if (n == -1){
//        data = (char *)malloc(str.len()-pos+1); ms win/nt bug fix
    data = (char *)calloc(str.len()-pos+1, sizeof( char ));
    strcpy(data, d+pos);
    size = str.len()-pos+1;
  }
  else
  {
//   data = (char *)malloc(n);  ms win/nt bug fix
// boundschecker flags the next line as a memory leak
// but this is a valid memory allocation
    data = (char *)calloc(n + 1, sizeof(char));
    strncpy(data, d + pos, n);
    data[n] = '\0';
    size = n + 1;
  }

  return (*this);
}

//! Short description.
/*!
  \param str
  \param n
*/
xbString& xbString::assign(char* str, int n)
{
  if(data)
  {
    free(data);
    data = 0;
  }

  data = (char *)calloc(n + 1, sizeof(char));
  strncpy(data, str, n);
  data[n] = 0;
  size = n + 1;

  return (*this);
}

//! Short description.
/*!
*/
void xbString::trim() {
  int l = len()-1;

   for (;;) {
      if (data[l] != ' ')
         break;
      data[l] = 0;
      if (l == 0)
         break;
      l--;
   }
}

//! Short description.
/*!
  \param pos
  \param n
*/
xbString &xbString::remove(size_t pos, int n) {
  if (data == NULL)
    return (*this);
  if (data[0] == 0)
    return (*this);

  size_t l = len();

  if (pos>l)
    return (*this);
  if (n == 0)
    return (*this);
  if (n > int(l-pos))
    n = l-pos;
  if (n<0)
    n = l-pos;
  memcpy(data+pos, data+pos+n, l-pos-n+1);

  return (*this);
}

//! Short description.
/*!
  \param pos
  \param n
*/
xbString xbString::mid(size_t pos, int n) const {
  if (data == NULL)
    return (*this);
  if (data[0] == 0)
    return (*this);

  size_t l = len();

  if (pos>l)
    return (*this);
  if (n == 0)
    return (*this);
  if (n > int(l-pos))
    n = l-pos;
  if (n<0)
    n = l-pos;

  xbString s;
  s.data = (char *)malloc(n+1);
  strncpy(s.data, data+pos, n);
  s.data[n] = 0;

  return s;
}

//! Short description.
/*!
  \param from
  \param to
*/
void xbString::swapChars( char from, char to )
{
  size_t i;
  for( i = 0; i < size; i++ )
    if( data[i] == from )
       data[i] = to;
} 

//! Short description.
/*!
  \param c
*/
void xbString::zapChar( char c )
{
  /* routine zaps every occurrence of a given character from the string */
  int p;
  size_t s;
  p = pos( c );
  while( p != -1 ){
    for( s = (size_t) p; s < size; s++ )
      putAt( s, data[s+1]);
    resize( size-1 );
    p = pos( c );
  }
}

//! Short description.
/*!
  \param c
*/
int xbString::countChar( char c ) const
{
  int i,j;
  
  for( i = 0,j = 0; i < (int) size; i++ )
    if( data[i] == c )
      j++;

  return j;
}


//! Short description.
/*!
  \param c
*/

void xbString::addBackSlash( char c )
{
 /* prefixes all char "c" with a backslash */
 int i, t, cnt;
 xbString ws;
  
  cnt = countChar( c );
  if( !cnt )
    return;
    
  ws.resize( size+cnt );
  for( i = 0, t = 0; i < (int)size; i++ ){
    if( data[i] == c )
      ws.putAt( t++, '\\' );
    ws.putAt( t++, data[i] );
  }
  ws.putAt( t, 0 );
  *this = ws.getData();
}

//! Short description.
/*!
  \param cnt
*/
void xbString::lTrunc( size_t cnt )
{
  /* left truncate cnt butes */

  char * ndata;
  char * p;
  if( cnt >= size ){
    ctor(0);
    return;
  }
  ndata = (char *) malloc( size - cnt );
  p = data;
  p += cnt;
  strcpy( ndata, p );
  free( data );
  data = ndata;
  size = size - cnt;
}


//! Short description.
/*!
  \param c
*/
void xbString::zapLeadingChar( char c )
{
  /* left truncate all of character c */

  int len = 0;
  char *p;
  p = data;
  while( *p && *p == c ){
    len++;
    p++;
  }
  if( len )
    lTrunc( len );
}


//! Short description.
/*!
*/
xbBool xbString::hasAlphaChars() const
{
  for( int i = 0; i < (int) size; i++ )
    if( isalpha( data[i] ))
      return 1;
  return 0;
}


//! Short description.
/*!
  \param out
*/

int xbString::cvtHexChar( char & out )
{
  /* this routine converts a four byte string in the format of 0x00 
     to a one byte char value 
     
     the first four bytes of the string must be in the format 0x00
     anything past the first four bytes is disregarded
     
     returns -1 on error
              0 on success 
  */

  int  j, k;
  char c;
    
  if( len() < 4 || data[0] != '0' || (data[1]!='X' && data[1]!='x' ))
    return -1;

  c = toupper( data[2] );
  j = ( c > '9' ? c - 'A' + 10 : c - '0' );
  c = toupper( data[3] );
  k = ( c > '9' ? c - 'A' + 10 : c - '0' );
  j = ( j << 4 ) + k;
    
  out = ( char ) j; 
  return 0;
} 

//! Short description.
/*!
  \param out
*/
int xbString::cvtHexString( xbString & out )
{
  /* this routine converts a string of four byte format of 0x00 
     to a string of one byte chars 
     
     returns -1 on error
              0 on success 
  */

  char c;
  xbString ws;
  ws = data;
  out = "";
  while( ws.len()){
    if( ws.cvtHexChar( c ))
      return -1;
    out += c;
    ws.lTrunc( 4 );
  }
  return 0;
}
//! Short description.
/*!
  \param src
  \param delim
  \param skipcnt
  \param opt
*/
int xbString::setFromDelimitedInput( const char * src, 
                char delim, int skipcnt, int opt )
{
  /* opt values

     1 - ignore delimiters between quotes
     2 - treat crlf characters as delimters
     3 - both options 1 and 2 
  */
 
  int len;
  int curpos = 0;
  int quotesw = 0;
  const char * s;
  const char * anchor;

  /* skip past skipcnt delimiters */
  s = src;
  while( *s && curpos < skipcnt ){ 
    if( *s == delim && !quotesw )
      curpos++;
    else if (( opt == 1 || opt == 3 ) &&  *s == '"' )
      quotesw = (quotesw) ? 0 : 1;
    s++;
  }
  /* at the beginning of the field */
  anchor = s;
  while( *s && ( *s != delim || ( *s == delim && quotesw ))){
    if( *s == '"' )
      quotesw = (quotesw) ? 0 : 1;
    s++;
  }
  len = s - anchor;

  /* copy data */
  data = (char *) realloc( data, len+1 );
  memcpy( data, anchor, len );
  data[len] = 0;
  this->size = len+1;

  if( opt == 2 || opt == 3 ){
    zapChar( 0x0a );
    zapChar( 0x0c );
    zapChar( 0x0d );
  }

  return len;
}