From c81d6d6cfd820fef58a79c61a6cb0ad13471d2a0 Mon Sep 17 00:00:00 2001 From: Rolland Santimano Date: Fri, 26 Aug 2005 10:21:07 +0000 Subject: [PATCH] - Updated strrev() to handle base+combining sequences --- ext/standard/string.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/ext/standard/string.c b/ext/standard/string.c index 8aecbccc1d..b64b07b738 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -3222,7 +3222,9 @@ PHP_FUNCTION(strrev) { zval **str; char *s, *e, *n, *p; - UChar *u_s, *u_e, *u_n, *u_p; + int32_t i, x1, x2; + UChar32 ch; + UChar *u_s, *u_n, *u_p; if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &str) == FAILURE) { WRONG_PARAM_COUNT; @@ -3236,15 +3238,22 @@ PHP_FUNCTION(strrev) u_n = eumalloc(Z_USTRLEN_PP(str)+1); u_p = u_n; u_s = Z_USTRVAL_PP(str); - u_e = u_s + Z_USTRLEN_PP(str) - 1; - while (u_e >= u_s) { - if (U16_IS_TRAIL(*u_e)) { - *u_p = *(u_e-1); - *(u_p+1) = *u_e; - u_e -= 2; u_p += 2; + i = Z_USTRLEN_PP(str); + while (i > 0) { + U16_PREV(u_s, 0, i, ch); + if (u_getCombiningClass(ch) == 0) { + u_p += zend_codepoint_to_uchar(ch, u_p); } else { - *u_p++ = *u_e--; + x2 = i; + do { + U16_PREV(u_s, 0, i, ch); + } while (u_getCombiningClass(ch) != 0); + x1 = i; + while (x1 <= x2) { + U16_NEXT(u_s, x1, Z_USTRLEN_PP(str), ch); + u_p += zend_codepoint_to_uchar(ch, u_p); + } } } *u_p = 0; -- 2.40.0