enhanced index and match
This commit is contained in:
		| @ -1,5 +1,5 @@ | ||||
| /* | ||||
|  * $Id: fnc.c 288 2009-09-15 14:03:15Z hyunghwan.chung $ | ||||
|  * $Id: fnc.c 289 2009-09-16 06:35:29Z hyunghwan.chung $ | ||||
|  * | ||||
|     Copyright 2006-2009 Chung, Hyung-Hwan. | ||||
|     This file is part of QSE. | ||||
| @ -462,7 +462,6 @@ static int fnc_index (qse_awk_rtx_t* rtx, const qse_cstr_t* fnm) | ||||
| 		n = qse_awk_rtx_valtonum (rtx, a2, &start, &rv); | ||||
| 		if (n <= -1) return -1; | ||||
| 		if (n >= 1) start = (qse_long_t)rv; | ||||
| 		if (start < 1) start = 1; | ||||
| 	} | ||||
|  | ||||
| 	if (a0->type == QSE_AWK_VAL_STR) | ||||
| @ -492,9 +491,14 @@ static int fnc_index (qse_awk_rtx_t* rtx, const qse_cstr_t* fnm) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	ptr = (start > len0)?  | ||||
| /* TODO: ignorecase... */ | ||||
| 	if (start == 0) start = 1; | ||||
| 	else if (start < 0) start = len0 + start + 1; | ||||
|  | ||||
| 	ptr = (start > len0 || start <= 0)?  | ||||
| 		QSE_NULL: | ||||
| 		qse_strxnstr (&str0[start-1], len0-start+1, str1, len1); | ||||
|  | ||||
| 	idx = (ptr == QSE_NULL)? 0: ((qse_long_t)(ptr-str0) + 1); | ||||
|  | ||||
| 	if (a0->type != QSE_AWK_VAL_STR) QSE_AWK_FREE (rtx->awk, str0); | ||||
| @ -1305,10 +1309,8 @@ static int fnc_match (qse_awk_rtx_t* rtx, const qse_cstr_t* fnm) | ||||
| 		n = qse_awk_rtx_valtonum (rtx, a2, &start, &rv); | ||||
| 		if (n <= -1) return -1; | ||||
| 		if (n >= 1) start = (qse_long_t)rv; | ||||
| 		if (start < 1) start = 1; | ||||
| 	} | ||||
|  | ||||
|  | ||||
| 	if (a0->type == QSE_AWK_VAL_STR) | ||||
| 	{ | ||||
| 		str0 = ((qse_awk_val_str_t*)a0)->ptr; | ||||
| @ -1356,7 +1358,10 @@ static int fnc_match (qse_awk_rtx_t* rtx, const qse_cstr_t* fnm) | ||||
| 		if (a1->type != QSE_AWK_VAL_STR) QSE_AWK_FREE (rtx->awk, str1); | ||||
| 	} | ||||
|  | ||||
| 	if (start > len0) n = 0; | ||||
| 	if (start == 0) start = 1; | ||||
| 	else if (start < 0) start = len0 + start + 1; | ||||
|  | ||||
| 	if (start > len0 || start <= 0) n = 0; | ||||
| 	else | ||||
| 	{ | ||||
| 		n = QSE_AWK_MATCHREX ( | ||||
|  | ||||
| @ -1,5 +1,5 @@ | ||||
| /* | ||||
|  * $Id: map.c 287 2009-09-15 10:01:02Z hyunghwan.chung $ | ||||
|  * $Id: map.c 289 2009-09-16 06:35:29Z hyunghwan.chung $ | ||||
|  * | ||||
|     Copyright 2006-2009 Chung, Hyung-Hwan. | ||||
|     This file is part of QSE. | ||||
| @ -57,17 +57,20 @@ static int reorganize (map_t* map); | ||||
|  | ||||
| static size_t hash_key (map_t* map, const void* kptr, size_t klen) | ||||
| { | ||||
| 	size_t n = 0; | ||||
| 	/*size_t h = 2166136261;*/ | ||||
| 	/*size_t h = 0;*/ | ||||
| 	size_t h = 5381; | ||||
| 	const byte_t* p = (const byte_t*)kptr; | ||||
| 	const byte_t* bound = p + klen; | ||||
|  | ||||
| 	while (p < bound) | ||||
| 	{ | ||||
| 		n = n * 31 + *p++; | ||||
| 		p++; | ||||
| 		/*h = (h * 16777619) ^ *p++;*/ | ||||
| 		/*h = h * 31 + *p++;*/ | ||||
| 		h = ((h << 5) + h) + *p++; | ||||
| 	}	 | ||||
|  | ||||
| 	return n; | ||||
| 	return h ;  | ||||
| } | ||||
|  | ||||
| static int comp_key (map_t* map,  | ||||
|  | ||||
| @ -1,5 +1,5 @@ | ||||
| /* | ||||
|  * $Id: str_bas.c 287 2009-09-15 10:01:02Z hyunghwan.chung $ | ||||
|  * $Id: str_bas.c 289 2009-09-16 06:35:29Z hyunghwan.chung $ | ||||
|  * | ||||
|     Copyright 2006-2009 Chung, Hyung-Hwan. | ||||
|     This file is part of QSE. | ||||
| @ -543,6 +543,47 @@ qse_char_t* qse_strxnstr ( | ||||
| 	return QSE_NULL; | ||||
| } | ||||
|  | ||||
| qse_char_t* qse_strrstr (const qse_char_t* str, const qse_char_t* sub) | ||||
| { | ||||
| 	return qse_strxnrstr (str, qse_strlen(str), sub, qse_strlen(sub)); | ||||
| } | ||||
|  | ||||
| qse_char_t* qse_strxrstr ( | ||||
| 	const qse_char_t* str, qse_size_t size, const qse_char_t* sub) | ||||
| { | ||||
| 	return qse_strxnrstr (str, size, sub, qse_strlen(sub)); | ||||
| } | ||||
|  | ||||
| qse_char_t* qse_strxnrstr ( | ||||
| 	const qse_char_t* str, qse_size_t strsz,  | ||||
| 	const qse_char_t* sub, qse_size_t subsz) | ||||
| { | ||||
| 	const qse_char_t* p = str + strsz; | ||||
| 	const qse_char_t* subp = sub + subsz; | ||||
|  | ||||
| 	if (subsz == 0) return (qse_char_t*)p; | ||||
| 	if (strsz < subsz) return QSE_NULL; | ||||
|  | ||||
| 	p = p - subsz; | ||||
|  | ||||
| 	while (p >= str)  | ||||
| 	{ | ||||
| 		const qse_char_t* x = p; | ||||
| 		const qse_char_t* y = sub; | ||||
|  | ||||
| 		while (1)  | ||||
| 		{ | ||||
| 			if (y >= subp) return (qse_char_t*)p; | ||||
| 			if (*x != *y) break; | ||||
| 			x++; y++; | ||||
| 		}	 | ||||
|  | ||||
| 		p--; | ||||
| 	} | ||||
|  | ||||
| 	return QSE_NULL; | ||||
| } | ||||
|  | ||||
| qse_char_t* qse_strchr (const qse_char_t* str, qse_cint_t c) | ||||
| { | ||||
| 	while (*str != QSE_T('\0'))  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user