src/string.c

changeset 1071
028cb6d22197
parent 1063
e453e717876e
child 1073
13c8a92625d4
equal deleted inserted replaced
1070:0a5a356a4486 1071:028cb6d22197
461 461
462 int cx_strcmp( 462 int cx_strcmp(
463 cxstring s1, 463 cxstring s1,
464 cxstring s2 464 cxstring s2
465 ) { 465 ) {
466 int r = strncmp(s1.ptr, s2.ptr, s1.length);
467 if (r != 0) return r;
466 if (s1.length == s2.length) { 468 if (s1.length == s2.length) {
467 return memcmp(s1.ptr, s2.ptr, s1.length); 469 return 0;
468 } else if (s1.length > s2.length) { 470 } else if (s1.length > s2.length) {
469 return 1; 471 return 1;
470 } else { 472 } else {
471 return -1; 473 return -1;
472 } 474 }
474 476
475 int cx_strcasecmp( 477 int cx_strcasecmp(
476 cxstring s1, 478 cxstring s1,
477 cxstring s2 479 cxstring s2
478 ) { 480 ) {
481 #ifdef _WIN32
482 int r = _strnicmp(s1.ptr, s2.ptr, s1.length);
483 #else
484 int r = strncasecmp(s1.ptr, s2.ptr, s1.length);
485 #endif
486 if (r != 0) return r;
479 if (s1.length == s2.length) { 487 if (s1.length == s2.length) {
480 #ifdef _WIN32 488 return 0;
481 return _strnicmp(s1.ptr, s2.ptr, s1.length);
482 #else
483 return strncasecmp(s1.ptr, s2.ptr, s1.length);
484 #endif
485 } else if (s1.length > s2.length) { 489 } else if (s1.length > s2.length) {
486 return 1; 490 return 1;
487 } else { 491 } else {
488 return -1; 492 return -1;
489 } 493 }

mercurial