andrei Thu May 4 18:37:13 2006 UTC
Modified files:
/php-src/ext/unicode php_property.h property.c unicode.c
Log:
Some more work on property/names stuff.
http://cvs.php.net/viewcvs.cgi/php-src/ext/unicode/php_property.h?r1=1.3&r2=1.4&diff_format=u
Index: php-src/ext/unicode/php_property.h
diff -u php-src/ext/unicode/php_property.h:1.3
php-src/ext/unicode/php_property.h:1.4
--- php-src/ext/unicode/php_property.h:1.3 Thu May 4 00:01:34 2006
+++ php-src/ext/unicode/php_property.h Thu May 4 18:37:12 2006
@@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_property.h,v 1.3 2006/05/04 00:01:34 andrei Exp $ */
+/* $Id: php_property.h,v 1.4 2006/05/04 18:37:12 andrei Exp $ */
#ifndef PHP_PROPERTY_H
#define PHP_PROPERTY_H
@@ -61,6 +61,7 @@
PHP_FUNCTION(char_get_digit_value);
PHP_FUNCTION(char_get_mirrored);
PHP_FUNCTION(char_get_direction);
+PHP_FUNCTION(char_get_age);
PHP_FUNCTION(char_get_type);
PHP_FUNCTION(char_is_valid);
http://cvs.php.net/viewcvs.cgi/php-src/ext/unicode/property.c?r1=1.6&r2=1.7&diff_format=u
Index: php-src/ext/unicode/property.c
diff -u php-src/ext/unicode/property.c:1.6 php-src/ext/unicode/property.c:1.7
--- php-src/ext/unicode/property.c:1.6 Thu May 4 00:01:34 2006
+++ php-src/ext/unicode/property.c Thu May 4 18:37:12 2006
@@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: property.c,v 1.6 2006/05/04 00:01:34 andrei Exp $ */
+/* $Id: property.c,v 1.7 2006/05/04 18:37:12 andrei Exp $ */
#include "php_unicode.h"
@@ -218,10 +218,11 @@
{
UChar *str;
int str_len;
+ int radix = 0;
int offset = 0;
UChar32 ch;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "u", &str,
&str_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "u|l", &str,
&str_len, &radix) == FAILURE) {
return;
}
@@ -230,16 +231,23 @@
}
U16_NEXT(str, offset, str_len, ch);
- RETURN_LONG(u_charDigitValue(ch));
+ if (ZEND_NUM_ARGS() > 1) {
+ if (radix < 2 || radix > 36) {
+ php_error(E_WARNING, "Radix has to be in 2-36 range");
+ return;
+ }
+ RETURN_LONG(u_digit(ch, radix));
+ } else {
+ RETURN_LONG(u_charDigitValue(ch));
+ }
}
PHP_FUNCTION(char_get_mirrored)
{
UChar *str;
int str_len;
- int offset = 0, buf_len;
+ int offset = 0;
UChar32 ch;
- UChar buf[3];
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "u", &str,
&str_len) == FAILURE) {
return;
@@ -249,9 +257,8 @@
RETURN_FALSE;
}
U16_NEXT(str, offset, str_len, ch);
- buf_len = zend_codepoint_to_uchar(u_charMirror(ch), buf);
- RETURN_UNICODEL(buf, buf_len, 1);
+ RETURN_UCHAR32(u_charMirror(ch));
}
PHP_FUNCTION(char_get_direction)
@@ -273,6 +280,30 @@
RETURN_LONG((long)u_charDirection(ch));
}
+PHP_FUNCTION(char_get_age)
+{
+ UChar *str;
+ int str_len;
+ int offset = 0;
+ UChar32 ch;
+ UVersionInfo version;
+ char buf[18] = { 0, };
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "u", &str,
&str_len) == FAILURE) {
+ return;
+ }
+
+ if (str_len == 0) {
+ RETURN_FALSE;
+ }
+ U16_NEXT(str, offset, str_len, ch);
+
+ u_charAge(ch, version);
+ u_versionToString(version, buf);
+
+ RETURN_ASCII_STRING(buf, ZSTR_DUPLICATE);
+}
+
PHP_FUNCTION(char_get_type)
{
UChar *str;
@@ -311,6 +342,75 @@
RETURN_BOOL(U_IS_UNICODE_CHAR(ch));
}
+PHP_FUNCTION(char_from_digit)
+{
+ int digit;
+ int radix = 10;
+ UChar32 ch;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &digit,
&radix) == FAILURE) {
+ return;
+ }
+
+ if (ZEND_NUM_ARGS() > 1) {
+ if (radix < 2 || radix > 36) {
+ php_error(E_WARNING, "Radix has to be in 2-36 range");
+ return;
+ }
+ }
+ ch = u_forDigit(digit, radix);
+
+ if (ch == (UChar32)0) {
+ RETURN_FALSE;
+ }
+
+ RETURN_UCHAR32(ch);
+}
+
+PHP_FUNCTION(char_from_name)
+{
+}
+
+PHP_FUNCTION(char_get_name)
+{
+ UChar *str;
+ int str_len;
+ int offset = 0;
+ UChar32 ch;
+ zend_bool extended = FALSE;
+ UCharNameChoice choice = U_UNICODE_CHAR_NAME;
+ char *buf;
+ int buf_len = 128;
+ UErrorCode status = U_ZERO_ERROR;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "u|b", &str,
&str_len, &extended) == FAILURE) {
+ return;
+ }
+
+ if (str_len == 0) {
+ RETURN_FALSE;
+ }
+
+ if (extended) {
+ choice = U_EXTENDED_CHAR_NAME;
+ }
+
+ U16_NEXT(str, offset, str_len, ch);
+
+ buf = emalloc(buf_len);
+ buf_len = u_charName(ch, choice, buf, buf_len, &status);
+ if (buf_len == 0) {
+ efree(buf);
+ RETURN_FALSE;
+ } else if (status == U_BUFFER_OVERFLOW_ERROR) {
+ status = U_ZERO_ERROR;
+ buf = erealloc(buf, buf_len+1);
+ buf_len = u_charName(ch, choice, buf, buf_len+1, &status);
+ }
+
+ RETURN_ASCII_STRINGL(buf, buf_len, ZSTR_AUTOFREE);
+}
+
/* }}} */
/*
http://cvs.php.net/viewcvs.cgi/php-src/ext/unicode/unicode.c?r1=1.27&r2=1.28&diff_format=u
Index: php-src/ext/unicode/unicode.c
diff -u php-src/ext/unicode/unicode.c:1.27 php-src/ext/unicode/unicode.c:1.28
--- php-src/ext/unicode/unicode.c:1.27 Thu May 4 00:01:34 2006
+++ php-src/ext/unicode/unicode.c Thu May 4 18:37:12 2006
@@ -15,7 +15,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: unicode.c,v 1.27 2006/05/04 00:01:34 andrei Exp $ */
+/* $Id: unicode.c,v 1.28 2006/05/04 18:37:12 andrei Exp $ */
#include "php_unicode.h"
#include "zend_unicode.h"
@@ -231,7 +231,6 @@
}
/* }}} */
-
/* {{{ unicode_functions[] */
zend_function_entry unicode_functions[] = {
PHP_FE(locale_get_default, NULL)
@@ -276,13 +275,18 @@
PHP_FE(char_is_titlecase, NULL)
PHP_FE(char_get_numeric_value, NULL)
- PHP_FE(char_get_combining_class, NULL)
PHP_FE(char_get_digit_value, NULL)
+ PHP_FE(char_get_combining_class, NULL)
PHP_FE(char_get_mirrored, NULL)
PHP_FE(char_get_direction, NULL)
+ PHP_FE(char_get_age, NULL)
PHP_FE(char_get_type, NULL)
PHP_FE(char_is_valid, NULL)
+ PHP_FE(char_from_digit, NULL)
+ PHP_FE(char_from_name, NULL)
+ PHP_FE(char_get_name, NULL)
+
{ NULL, NULL, NULL }
};
/* }}} */
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php