17 int main(
int argc ,
const char* argv[] ) {
19 std::cout <<
"test->string_tool() [uUnit.h]" << std::endl;
22 #define exec_TEST(t) void t(); t();
59 std::string ABC123XYZ =
"ABC123XYZ";
68 std::string A =
"A";
tolower(A);
71 std::string ABC123XYZ =
"ABC123XYZ";
75 std::string UP =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
tolower(UP);
76 assertTrue(
"abcdefghijklmnopqrstuvwxyz" == UP );
93 char Astr[
sizeof(Atilde) ];
94 strcpy( Astr, Atilde );
116 char Astr[ 255-192+1 ]; *Astr = 0;
117 strcpy( Astr, Atilde );
122 #ifdef __GNUC__ // Esto es raro ...
136 char Astr[ 255-192+1 ];
137 strcpy( Astr, Atilde );
174 string sAE =
"ABCDE";
175 string s15 =
"12345";
189 string s15 =
"12345"; s15 +=
'.';
210 string s15 =
"12345";
214 string sAE =
"ABCDE"; sAE +=
'.';
229 #define roundUp(n,b) ( (b)==0 ? (n) : ( ((n)+(b)-1) - (((n)-1)%(b)) ) )
278 const char *filename ,*name_cfg;
279 filename =
"yy-VACIO-bt0pp.cfg";
280 name_cfg =
"Xvacio-bt0pp.cfg";
282 filename =
"yy-VACIO-bt0pp.cfg";
283 name_cfg =
"vacio-bt0pp.cfg";
287 const char *filename ,*name_cfg;
288 filename =
"00-bt0pp.cfg";
289 name_cfg =
"bt0pp.cfg";
291 filename =
"00-bt0pp.cfg xxx";
345 char touch[16];
assertTrue( !strcmp(
"abc",
"abc" ) );
362 const char* yo =
"adolfo@di-mare.com";
365 size_t prev = YO.find(
'@');
366 for (
size_t i=0; i<prev; ++i ) {
370 size_t post = prev+1;
371 for (
size_t i=post; i<YO.size(); ++i ) {
382 ln =
" gsec =##-t|##-tpg (mejor peor); ;?-### ;etc." ;
385 [gsec] [=] [##-t] [|] [##-tpg] [(] [mejor] [peor] [)] [;] [;] [?-###] [;] [etc.]
386 1 2 3 4 5 6 7 8 9 10 11 12 13 14
389 std::list< std::string > LLL;
390 std::list< std::string >::const_iterator it;
391 tokens( ln, LLL ,
" =();|" );
394 it = LLL.begin();
assertTrue( *it ==
"gsec" );
398 it = LLL.begin();
for (
int i=1; i<6; ++i,it++) { }
assertTrue( *it ==
"(" );
399 it = LLL.begin();
for (
int i=1; i<10; ++i,it++) { }
assertTrue( *it ==
";" );
400 it = LLL.begin();
for (
int i=1; i<12; ++i,it++) { }
assertTrue( *it ==
"?-###" );
402 std::list< std::string > LLL;
403 std::list< std::string >::const_iterator it;
405 ln =
" " ;
tokens( ln, LLL ,
" ;" );
407 ln =
" ; etc ";
tokens( ln, LLL ,
" ;" );
408 assertTrue( LLL.size()==2 && LLL.front()==
";" );
413 ln =
"gsec=##-t|##-tpg(mejor peor); ;?-###;etc." ;
416 [gsec] [=] [##-t] [|] [##-tpg] [(] [mejor] [peor] [)] [;] [;] [?-###] [;] [etc.]
417 1 2 3 4 5 6 7 8 9 10 11 12 13 14
419 std::list< std::string > LLL;
420 std::list< std::string >::const_iterator it;
421 tokens( ln, LLL ,
" =();|" );
423 assertFalse(
" *** Por que NO detecta '|' ni ')' ??? *** " );
424 for ( it=LLL.begin(); it!=LLL.end(); ++it) {
425 std::cout<<
"[" << *it <<
"] ";
427 std::cout << std::endl;
430 it = LLL.begin();
for (
int i=1; i<6; ++i,it++) { }
assertTrue( *it ==
"(" );
431 it = LLL.begin();
for (
int i=1; i<10; ++i,it++) { }
assertTrue( *it ==
";" );
432 it = LLL.begin();
for (
int i=1; i<12; ++i,it++) { }
assertTrue( *it ==
"?-###" );
438 ln =
"2012.1.ci1101.g04.adolfo..dimare.examen.ex2.1-enunciado.htm" ;
439 std::list< std::string > LLL;
440 std::list< std::string >::const_iterator it;
444 for ( it=LLL.begin(); it!=LLL.end(); ++it,++i) {
445 std::cout<< i <<
"[" << *it <<
"] ";
447 std::cout << std::endl;
450 it = LLL.begin();
for (
int i=0; i<0; ++i,it++) { }
assertTrue( *it ==
"2012" );
451 it = LLL.begin();
for (
int i=0; i<1; ++i,it++) { }
assertTrue( *it ==
"." );
452 it = LLL.begin();
for (
int i=0; i<2; ++i,it++) { }
assertTrue( *it ==
"1" );
454 it = LLL.begin();
for (
int i=0; i<8 ; ++i,it++) { }
assertTrue( *it ==
"adolfo" );
455 it = LLL.begin();
for (
int i=0; i<19 ; ++i,it++) { }
assertTrue( *it ==
"htm" );
457 it = LLL.begin();
for (
int i=0; i<9 ; ++i,it++) { }
assertTrue( *it ==
"." );
458 it = LLL.begin();
for (
int i=0; i<10; ++i,it++) { }
assertTrue( *it ==
"." );
465 ln =
" gsec =##-tarea|##-tpg (enunciado mejor peor) ;?-### ;?### ;etc.;" ;
466 std::list< std::string > LLL;
467 std::list< std::string >::const_iterator it;
468 tokens( ln, LLL ,
" =();|" );
477 std::list< std::string > LLL;
478 std::list< std::string >::const_iterator it;
479 const char* delimiters =
" /";
480 ln =
"SDF/Algor Design";
481 tokens( ln, LLL , delimiters );
492 std::list< std::string > LLL;
493 std::list< std::string >::const_iterator it;
495 ln =
"()=;| ( ) = ; | ( ) = ; |";
496 LLL.clear();
tokens( ln, LLL ,
" =();|" );
499 it = LLL.begin();
for (
int i=1; i<10; ++i,it++) { }
assertTrue( *it ==
"|" );
502 LLL.clear();
tokens( ln, LLL ,
" =();|" );
505 it = LLL.begin();
for (
int i=1; i<10; ++i,it++) { }
assertTrue( *it ==
"|" );
508 LLL.clear();
tokens( ln, LLL ,
" =();|" );
511 it = LLL.begin();
for (
int i=1; i<10; ++i,it++) { }
assertTrue( *it ==
"|" );
514 ln =
"(.).=.;.|..(..)..=..;..|..(..)..=..;..|";
515 LLL.clear();
tokens( ln, LLL ,
" =();|" );
518 it = LLL.begin();
for (
int i=1; i<15; ++i,it++) { }
assertTrue( *it ==
"=" );
521 LLL.clear();
tokens( ln, LLL ,
" =();|" );
524 it = LLL.begin();
for (
int i=1; i<16; ++i,it++) { }
assertTrue( *it ==
"=" );
527 LLL.clear();
tokens( ln, LLL ,
" =();|" );
530 it = LLL.begin();
for (
int i=1; i<16; ++i,it++) { }
assertTrue( *it ==
"=" );
533 ln =
"(:::):::=:::;:::|::::::(::::::)::::::=::::::;::::::|::::::(::::::)::::::=::::::;::::::|";
534 LLL.clear();
tokens( ln, LLL ,
" =();|" );
537 it = LLL.begin();
for (
int i=1; i<15; ++i,it++) { }
assertTrue( *it ==
"=" );
540 LLL.clear();
tokens( ln, LLL ,
" =();|" );
543 it = LLL.begin();
for (
int i=1; i<16; ++i,it++) { }
assertTrue( *it ==
"=" );
546 LLL.clear();
tokens( ln, LLL ,
" =();|" );
549 it = LLL.begin();
for (
int i=1; i<16; ++i,it++) { }
assertTrue( *it ==
"=" );
553 LLL.clear();
tokens( ln, LLL ,
" =();|" );
556 LLL.clear();
tokens( ln, LLL ,
" =();|" );
559 LLL.clear();
tokens( ln, LLL ,
" =();|" );
562 LLL.clear();
tokens( ln, LLL ,
" =();|" );
571 char *
strins(
const char *substr,
char *num,
int n)
573 memmove(&num[n+strlen(substr)],&num[n],strlen(&num[n])+1);
574 memcpy(&num[n],substr,strlen(substr));
585 if (start >= slen)
return str;
586 if (start+len > slen) len = slen-start;
587 memmove(&str[start],&str[start+len],strlen(&str[start+len])+1);
616 while ((*b++ = *p++));
624 char str[] =
"12.==.789";
628 strdel( str, strlen(str), 1 );
631 strdel( str,
size_t(911), 1 );
634 const char base[] =
"123456789.123456789.";
635 char bfast[
sizeof(base) ];
636 char bslow[
sizeof(base) ];
637 char byang[
sizeof(base) ];
638 assertTrue( 20==strlen(base) && 21<=
sizeof(base) );
640 for (
size_t len=0; len<=strlen(base); ++len ) {
641 for (
size_t from=0; from<=strlen(base); ++from ) {
642 strcpy(bfast, base); strcpy( bslow, base );
645 if ( 0==strcmp(bfast,bslow) ) { }
648 std::cout <<
"(len,from)==(" << len <<
',' << from <<
")\n";
651 strcpy(bfast, base); strcpy( byang, base );
654 if ( 0==strcmp(bfast,byang) ) { }
657 std::cout <<
"(len,from)==(" << len <<
',' << from <<
")\n";
658 std::cout << bfast << std::endl;
659 std::cout << byang << std::endl;
669 char str[] =
"12.==.789";
679 const char base[] =
"123456789.123456789.";
680 char bfast[
sizeof(base) ];
681 char bslow[
sizeof(base) ];
682 assertTrue( 20==strlen(base) && 21<=
sizeof(base) );
684 for (
size_t len=0; len<=strlen(base); ++len ) {
685 for (
size_t from=0; from<=strlen(base); ++from ) {
686 strcpy(bfast, base); strcpy(bslow, base);
689 if ( 0==strcmp(bfast,bslow) ) { }
692 std::cout <<
"(len,from)==(" << len <<
',' << from <<
")\n";