andrei Fri Aug 19 18:00:22 2005 EDT Modified files: /php-src/ext/standard string.c Log: Unicode support for ord() and chr(). http://cvs.php.net/diff.php/php-src/ext/standard/string.c?r1=1.468&r2=1.469&ty=u Index: php-src/ext/standard/string.c diff -u php-src/ext/standard/string.c:1.468 php-src/ext/standard/string.c:1.469 --- php-src/ext/standard/string.c:1.468 Fri Aug 19 13:53:03 2005 +++ php-src/ext/standard/string.c Fri Aug 19 18:00:21 2005 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: string.c,v 1.468 2005/08/19 17:53:03 andrei Exp $ */ +/* $Id: string.c,v 1.469 2005/08/19 22:00:21 andrei Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -2835,8 +2835,8 @@ } /* }}} */ -/* {{{ proto int ord(string character) - Returns ASCII value of character */ +/* {{{ proto int ord(text character) + Returns the codepoint value of a character */ PHP_FUNCTION(ord) { zval **str; @@ -2844,14 +2844,18 @@ if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_string_ex(str); + convert_to_text_ex(str); - RETURN_LONG((unsigned char) Z_STRVAL_PP(str)[0]); + if (Z_TYPE_PP(str) == IS_UNICODE) { + RETURN_LONG(zend_get_codepoint_at(Z_USTRVAL_PP(str), Z_USTRLEN_PP(str), 0)); + } else { + RETURN_LONG((unsigned char) Z_STRVAL_PP(str)[0]); + } } /* }}} */ -/* {{{ proto string chr(int ascii) - Converts ASCII code to a character */ +/* {{{ proto text chr(int codepoint) + Converts a codepoint number to a character */ PHP_FUNCTION(chr) { zval **num; @@ -2862,10 +2866,22 @@ } convert_to_long_ex(num); - temp[0] = (char) Z_LVAL_PP(num); - temp[1] = 0; + if (UG(unicode)) { + UChar buf[2]; + int32_t buf_len; - RETVAL_STRINGL(temp, 1, 1); + if (Z_LVAL_PP(num) > UCHAR_MAX_VALUE) { + php_error(E_WARNING, "Codepoint value cannot be greater than %X", UCHAR_MAX_VALUE); + return; + } + buf_len = zend_codepoint_to_uchar((uint32_t)Z_LVAL_PP(num), buf); + RETURN_UNICODEL(buf, buf_len, 1); + } else { + temp[0] = (char) Z_LVAL_PP(num); + temp[1] = 0; + + RETVAL_STRINGL(temp, 1, 1); + } } /* }}} */
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php