From a514d68bfb7c0417013cb76e7626fa8c90b5c840 Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Sat, 4 Apr 2009 17:31:54 +0000 Subject: [PATCH] ngx_strlcasestrn() --- src/core/ngx_string.c | 33 +++++++++++++++++++++++++++++++++ src/core/ngx_string.h | 1 + 2 files changed, 34 insertions(+) diff --git a/src/core/ngx_string.c b/src/core/ngx_string.c index 0ad594f82..fbde1c2ce 100644 --- a/src/core/ngx_string.c +++ b/src/core/ngx_string.c @@ -692,6 +692,39 @@ ngx_strcasestrn(u_char *s1, char *s2, size_t n) } +/* + * ngx_strlcasestrn() is intended to search for static substring + * with known length in string until the argument last. The argument n + * must be length of the second substring - 1. + */ + +u_char * +ngx_strlcasestrn(u_char *s1, u_char *last, u_char *s2, size_t n) +{ + ngx_uint_t c1, c2; + + c2 = (ngx_uint_t) *s2++; + c2 = (c2 >= 'A' && c2 <= 'Z') ? (c2 | 0x20) : c2; + last -= n; + + do { + do { + if (s1 == last) { + return NULL; + } + + c1 = (ngx_uint_t) *s1++; + + c1 = (c1 >= 'A' && c1 <= 'Z') ? (c1 | 0x20) : c1; + + } while (c1 != c2); + + } while (ngx_strncasecmp(s1, s2, n) != 0); + + return --s1; +} + + ngx_int_t ngx_rstrncmp(u_char *s1, u_char *s2, size_t n) { diff --git a/src/core/ngx_string.h b/src/core/ngx_string.h index af2818639..0560bd8be 100644 --- a/src/core/ngx_string.h +++ b/src/core/ngx_string.h @@ -149,6 +149,7 @@ u_char *ngx_strnstr(u_char *s1, char *s2, size_t n); u_char *ngx_strstrn(u_char *s1, char *s2, size_t n); u_char *ngx_strcasestrn(u_char *s1, char *s2, size_t n); +u_char *ngx_strlcasestrn(u_char *s1, u_char *last, u_char *s2, size_t n); ngx_int_t ngx_rstrncmp(u_char *s1, u_char *s2, size_t n); ngx_int_t ngx_rstrncasecmp(u_char *s1, u_char *s2, size_t n);