Mercurial > hg > nginx
comparison src/core/ngx_string.c @ 1611:d5db0e96bcc6 stable-0.5
r1542, r1543, r1544, r1549, r1550, r1551, r1555 merge:
*) ngx_strstrn() and ngx_strcasestrn()
*) fix memcached END test
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 29 Oct 2007 14:52:51 +0000 |
parents | bf7814d77484 |
children | d72f8b48dd87 |
comparison
equal
deleted
inserted
replaced
1610:f5e9d597a751 | 1611:d5db0e96bcc6 |
---|---|
440 return buf; | 440 return buf; |
441 } | 441 } |
442 | 442 |
443 | 443 |
444 /* | 444 /* |
445 * We use ngx_strcasecmp()/ngx_strncasecmp() for 7-bit ASCII string only, | 445 * We use ngx_strcasecmp()/ngx_strncasecmp() for 7-bit ASCII strings only, |
446 * and implement our own ngx_strcasecmp()/ngx_strncasecmp() | 446 * and implement our own ngx_strcasecmp()/ngx_strncasecmp() |
447 * to avoid libc locale overhead. Besides, we use the ngx_uint_t's | 447 * to avoid libc locale overhead. Besides, we use the ngx_uint_t's |
448 * instead of the u_char's, because they are slightly faster. | 448 * instead of the u_char's, because they are slightly faster. |
449 */ | 449 */ |
450 | 450 |
498 | 498 |
499 return c1 - c2; | 499 return c1 - c2; |
500 } | 500 } |
501 | 501 |
502 return 0; | 502 return 0; |
503 } | |
504 | |
505 | |
506 /* | |
507 * ngx_strstrn() and ngx_strcasestrn() are intended to search for static | |
508 * substring with known length in null-terminated string. The argument n | |
509 * must be length of the second substring - 1. | |
510 */ | |
511 | |
512 u_char * | |
513 ngx_strstrn(u_char *s1, char *s2, size_t n) | |
514 { | |
515 u_char c1, c2; | |
516 | |
517 c2 = *(u_char *) s2++; | |
518 | |
519 do { | |
520 do { | |
521 c1 = *s1++; | |
522 | |
523 if (c1 == 0) { | |
524 return NULL; | |
525 } | |
526 | |
527 } while (c1 != c2); | |
528 | |
529 } while (ngx_strncmp(s1, (u_char *) s2, n) != 0); | |
530 | |
531 return --s1; | |
532 } | |
533 | |
534 | |
535 u_char * | |
536 ngx_strcasestrn(u_char *s1, char *s2, size_t n) | |
537 { | |
538 ngx_uint_t c1, c2; | |
539 | |
540 c2 = (ngx_uint_t) *s2++; | |
541 c2 = (c2 >= 'A' && c2 <= 'Z') ? (c2 | 0x20) : c2; | |
542 | |
543 do { | |
544 do { | |
545 c1 = (ngx_uint_t) *s1++; | |
546 | |
547 if (c1 == 0) { | |
548 return NULL; | |
549 } | |
550 | |
551 c1 = (c1 >= 'A' && c1 <= 'Z') ? (c1 | 0x20) : c1; | |
552 | |
553 } while (c1 != c2); | |
554 | |
555 } while (ngx_strncasecmp(s1, (u_char *) s2, n) != 0); | |
556 | |
557 return --s1; | |
503 } | 558 } |
504 | 559 |
505 | 560 |
506 ngx_int_t | 561 ngx_int_t |
507 ngx_rstrncmp(u_char *s1, u_char *s2, size_t n) | 562 ngx_rstrncmp(u_char *s1, u_char *s2, size_t n) |