|
@@ -535,18 +535,24 @@ cmChar_t* cmTextReplaceS( cmChar_t* s, const cmChar_t* t, unsigned tn, const cmC
|
535
|
535
|
cmChar_t* _cmTextReplace( cmChar_t* s, const cmChar_t* t, const cmChar_t* u, unsigned n )
|
536
|
536
|
{
|
537
|
537
|
// we will go into an endless loop if 't' is contained in 'u' and n > 1.
|
538
|
|
- assert( s!= NULL && t!=NULL && u!=NULL && (n==1 || strstr(u,t) == NULL) );
|
|
538
|
+ //assert( s!= NULL && t!=NULL && u!=NULL && (n==1 || strstr(u,t) == NULL) );
|
|
539
|
+
|
|
540
|
+ assert( s!= NULL && t!=NULL && u!=NULL );
|
539
|
541
|
|
540
|
542
|
int tn = strlen(t);
|
541
|
543
|
cmChar_t* c = NULL;
|
542
|
544
|
unsigned i = 0;
|
|
545
|
+ cmChar_t* s0 = s;
|
543
|
546
|
|
544
|
|
- while( (c = strstr(s,t)) != NULL )
|
|
547
|
+ while( (c = strstr(s0,t)) != NULL )
|
545
|
548
|
{
|
|
549
|
+ int offs = c - s;
|
546
|
550
|
s = cmTextReplaceS(s,c,tn,u);
|
547
|
551
|
|
548
|
552
|
assert(s!=NULL);
|
549
|
553
|
|
|
554
|
+ s0 = s + offs + tn;
|
|
555
|
+
|
550
|
556
|
++i;
|
551
|
557
|
if( n!=cmInvalidCnt && i>=n)
|
552
|
558
|
break;
|
|
@@ -599,6 +605,26 @@ cmChar_t* cmTextAppendSNZ( cmChar_t* s, const cmChar_t* u, unsigned un )
|
599
|
605
|
cmChar_t* cmTextAppendSS( cmChar_t* s, const cmChar_t* u )
|
600
|
606
|
{ return cmTextAppendSN(s,u,strlen(u)); }
|
601
|
607
|
|
|
608
|
+cmChar_t* cmTextVAppendSS( cmChar_t* s, ... )
|
|
609
|
+{
|
|
610
|
+ va_list vl;
|
|
611
|
+ va_start(vl,s);
|
|
612
|
+ do
|
|
613
|
+ {
|
|
614
|
+ cmChar_t* s0 = va_arg(vl,cmChar_t*);
|
|
615
|
+ if( s0 == NULL )
|
|
616
|
+ break;
|
|
617
|
+
|
|
618
|
+ s = cmTextAppendSS(s,s0);
|
|
619
|
+
|
|
620
|
+ }while(1);
|
|
621
|
+
|
|
622
|
+ va_end(vl);
|
|
623
|
+
|
|
624
|
+ return s;
|
|
625
|
+}
|
|
626
|
+
|
|
627
|
+
|
602
|
628
|
|
603
|
629
|
cmChar_t* cmTextAppendChar( cmChar_t* s, cmChar_t c, unsigned n )
|
604
|
630
|
{
|
|
@@ -623,6 +649,14 @@ bool cmTextIsEmpty( const cmChar_t* s )
|
623
|
649
|
bool cmTextIsNotEmpty( const cmChar_t* s )
|
624
|
650
|
{ return !cmTextIsEmpty(s); }
|
625
|
651
|
|
|
652
|
+
|
|
653
|
+unsigned cmTextLength( const cmChar_t* s0 )
|
|
654
|
+{
|
|
655
|
+ if( s0 == NULL )
|
|
656
|
+ return 0;
|
|
657
|
+ return strlen(s0);
|
|
658
|
+}
|
|
659
|
+
|
626
|
660
|
int cmTextCmp( const cmChar_t* s0, const cmChar_t* s1 )
|
627
|
661
|
{
|
628
|
662
|
if( s0 == NULL && s1 == NULL )
|
|
@@ -638,6 +672,46 @@ int cmTextCmp( const cmChar_t* s0, const cmChar_t* s1 )
|
638
|
672
|
return strcmp(s0,s1);
|
639
|
673
|
}
|
640
|
674
|
|
|
675
|
+int cmTextCmpN( const cmChar_t* s0, const cmChar_t* s1, unsigned n )
|
|
676
|
+{
|
|
677
|
+ if( s0 == NULL && s1 == NULL )
|
|
678
|
+ return 0;
|
|
679
|
+
|
|
680
|
+ if( s0 == NULL || s1 == NULL )
|
|
681
|
+ {
|
|
682
|
+ if( s0 == NULL )
|
|
683
|
+ return -1;
|
|
684
|
+ return 1;
|
|
685
|
+ }
|
|
686
|
+
|
|
687
|
+ return strncmp(s0,s1,n);
|
|
688
|
+}
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+void cmTextToLower( const cmChar_t* s0, cmChar_t* s1 )
|
|
692
|
+{
|
|
693
|
+ if( s0 == NULL || s1==NULL )
|
|
694
|
+ return;
|
|
695
|
+
|
|
696
|
+ for(; *s0; ++s0,++s1)
|
|
697
|
+ *s1 = tolower(*s0);
|
|
698
|
+
|
|
699
|
+ *s1 = 0;
|
|
700
|
+ return;
|
|
701
|
+}
|
|
702
|
+
|
|
703
|
+void cmTextToUpper( const cmChar_t* s0, cmChar_t* s1 )
|
|
704
|
+{
|
|
705
|
+ if( s0 == NULL || s1==NULL )
|
|
706
|
+ return;
|
|
707
|
+
|
|
708
|
+ for(; *s0; ++s0,++s1)
|
|
709
|
+ *s1 = toupper(*s0);
|
|
710
|
+
|
|
711
|
+ *s1 = 0;
|
|
712
|
+ return;
|
|
713
|
+}
|
|
714
|
+
|
641
|
715
|
cmChar_t* cmTextLine( cmChar_t* s, unsigned line )
|
642
|
716
|
{
|
643
|
717
|
assert( line>0);
|