1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

ext/intl: migrate C code to C++ step 3. (#19411)

This commit is contained in:
David CARLIER
2025-10-11 14:16:57 +01:00
committed by GitHub
parent c3b66cdb44
commit 7f65512511
19 changed files with 187 additions and 107 deletions

View File

@@ -24,6 +24,9 @@ U_CDECL_END
#ifdef __cplusplus
// TODO once C++ migration done we can drop this workaround
#undef U_SHOW_CPLUSPLUS_API
#define U_SHOW_CPLUSPLUS_API 1
#include <unicode/timezone.h>
using icu::TimeZone;

View File

@@ -18,19 +18,8 @@ if test "$PHP_INTL" != "no"; then
collator/collator_locale.c
collator/collator_sort.c
common/common_error.c
converter/converter.c
dateformat/dateformat_attr.c
dateformat/dateformat_class.c
dateformat/dateformat_data.c
dateformat/dateformat_format.c
dateformat/dateformat_parse.c
dateformat/dateformat.c
formatter/formatter_attr.c
formatter/formatter_class.c
formatter/formatter_data.c
formatter/formatter_format.c
formatter/formatter_main.c
formatter/formatter_parse.c
grapheme/grapheme_string.c
grapheme/grapheme_util.c
intl_convert.c
@@ -53,10 +42,16 @@ if test "$PHP_INTL" != "no"; then
PHP_INTL_CXX_SOURCES="intl_convertcpp.cpp \
common/common_enum.cpp \
common/common_date.cpp \
dateformat/dateformat_format_object.cpp \
dateformat/dateformat_create.cpp \
converter/converter.cpp \
dateformat/dateformat.cpp \
dateformat/dateformat_attr.cpp \
dateformat/dateformat_attrcpp.cpp \
dateformat/dateformat_create.cpp \
dateformat/dateformat_data.cpp \
dateformat/dateformat_format.cpp \
dateformat/dateformat_format_object.cpp \
dateformat/dateformat_helpers.cpp \
dateformat/dateformat_parse.cpp \
dateformat/datepatterngenerator_class.cpp \
dateformat/datepatterngenerator_methods.cpp \
msgformat/msgformat_helpers.cpp \
@@ -66,6 +61,11 @@ if test "$PHP_INTL" != "no"; then
calendar/calendar_class.cpp \
calendar/calendar_methods.cpp \
calendar/gregoriancalendar_methods.cpp \
formatter/formatter_attr.cpp \
formatter/formatter_data.cpp \
formatter/formatter_format.cpp \
formatter/formatter_main.cpp \
formatter/formatter_parse.cpp \
msgformat/msgformat_attr.cpp \
msgformat/msgformat_class.cpp \
msgformat/msgformat_data.cpp \

View File

@@ -29,15 +29,15 @@ if (PHP_INTL != "no") {
common_date.cpp \
", "intl");
ADD_SOURCES(configure_module_dirname + "/converter", "\
converter.c \
converter.cpp \
", "intl");
ADD_SOURCES(configure_module_dirname + "/formatter", "\
formatter_attr.c \
formatter_attr.cpp \
formatter_class.c \
formatter_data.c \
formatter_format.c \
formatter_main.c \
formatter_parse.c \
formatter_data.cpp \
formatter_format.cpp \
formatter_main.cpp \
formatter_parse.cpp \
", "intl");
ADD_SOURCES(configure_module_dirname + "/listformatter", "\
listformatter_class.c \
@@ -67,13 +67,13 @@ if (PHP_INTL != "no") {
rangeformatter_class.cpp \
", "intl");
ADD_SOURCES(configure_module_dirname + "/dateformat", "\
dateformat.c \
dateformat.cpp \
dateformat_class.c \
dateformat_attr.c \
dateformat_format.c \
dateformat_attr.cpp \
dateformat_format.cpp \
dateformat_format_object.cpp \
dateformat_parse.c \
dateformat_data.c \
dateformat_parse.cpp \
dateformat_data.cpp \
dateformat_attrcpp.cpp \
dateformat_helpers.cpp \
dateformat_create.cpp \

View File

@@ -12,7 +12,6 @@
+----------------------------------------------------------------------+
*/
#include "converter.h"
#include "zend_exceptions.h"
#include <unicode/utypes.h>
@@ -21,10 +20,13 @@
#include <unicode/ucnv.h>
#include <unicode/ustring.h>
extern "C" {
#include "converter.h"
#include "php_intl.h"
#include "../intl_error.h"
#include "../intl_common.h"
}
#include "converter_arginfo.h"
#include "php_intl.h"
typedef struct _php_converter_object {
UConverter *src, *dest;
@@ -238,9 +240,9 @@ static void php_converter_to_u_callback(const void *context,
}
if (Z_TYPE(zargs[3]) == IS_LONG) {
*pErrorCode = Z_LVAL(zargs[3]);
*pErrorCode = static_cast<UErrorCode>(Z_LVAL(zargs[3]));
} else if (Z_ISREF(zargs[3]) && Z_TYPE_P(Z_REFVAL(zargs[3])) == IS_LONG) {
*pErrorCode = Z_LVAL_P(Z_REFVAL(zargs[3]));
*pErrorCode = static_cast<UErrorCode>(Z_LVAL_P(Z_REFVAL(zargs[3])));
}
zval_ptr_dtor(&zargs[0]);
@@ -265,7 +267,7 @@ static void php_converter_append_fromUnicode_target(zval *val, UConverterFromUni
{
size_t vallen = Z_STRLEN_P(val);
if (TARGET_CHECK(args, vallen)) {
args->target = zend_mempcpy(args->target, Z_STRVAL_P(val), vallen);
args->target = reinterpret_cast<char *>(zend_mempcpy(args->target, Z_STRVAL_P(val), vallen));
}
return;
}
@@ -315,9 +317,9 @@ static void php_converter_from_u_callback(const void *context,
}
if (Z_TYPE(zargs[3]) == IS_LONG) {
*pErrorCode = Z_LVAL(zargs[3]);
*pErrorCode = static_cast<UErrorCode>(Z_LVAL(zargs[3]));
} else if (Z_ISREF(zargs[3]) && Z_TYPE_P(Z_REFVAL(zargs[3])) == IS_LONG) {
*pErrorCode = Z_LVAL_P(Z_REFVAL(zargs[3]));
*pErrorCode = static_cast<UErrorCode>(Z_LVAL_P(Z_REFVAL(zargs[3])));
}
zval_ptr_dtor(&zargs[0]);
@@ -340,7 +342,7 @@ static inline bool php_converter_set_callbacks(php_converter_object *objval, UCo
}
ucnv_setToUCallBack(cnv, (UConverterToUCallback)php_converter_to_u_callback, (const void*)objval,
NULL, NULL, &error);
nullptr, nullptr, &error);
if (U_FAILURE(error)) {
THROW_UFAILURE(objval, error);
ret = false;
@@ -348,7 +350,7 @@ static inline bool php_converter_set_callbacks(php_converter_object *objval, UCo
error = U_ZERO_ERROR;
ucnv_setFromUCallBack(cnv, (UConverterFromUCallback)php_converter_from_u_callback, (const void*)objval,
NULL, NULL, &error);
nullptr, nullptr, &error);
if (U_FAILURE(error)) {
THROW_UFAILURE(objval, error);
ret = false;
@@ -507,14 +509,14 @@ static void php_converter_resolve_callback(
const char *callback_name,
size_t callback_name_len
) {
zend_function *fn = zend_hash_str_find_ptr_lc(&obj->ce->function_table, callback_name, callback_name_len);
ZEND_ASSERT(fn != NULL);
zend_function *fn = reinterpret_cast<zend_function *>(zend_hash_str_find_ptr_lc(&obj->ce->function_table, callback_name, callback_name_len));
ZEND_ASSERT(fn != nullptr);
fcc->function_handler = fn;
fcc->object = obj;
fcc->called_scope = obj->ce;
fcc->calling_scope = NULL;
fcc->closure = NULL;
fcc->calling_scope = nullptr;
fcc->closure = nullptr;
}
/* }}} */
@@ -635,16 +637,16 @@ static zend_string* php_converter_do_convert(UConverter *dest_cnv,
if (!src_cnv || !dest_cnv) {
php_converter_throw_failure(objval, U_INVALID_STATE_ERROR,
"Internal converters not initialized");
return NULL;
return nullptr;
}
/* Get necessary buffer size first */
temp_len = 1 + ucnv_toUChars(src_cnv, NULL, 0, src, src_len, &error);
if (U_FAILURE(error) && error != U_BUFFER_OVERFLOW_ERROR) {
THROW_UFAILURE(objval, error);
return NULL;
return nullptr;
}
temp = safe_emalloc(sizeof(UChar), temp_len, sizeof(UChar));
temp = reinterpret_cast<UChar *>(safe_emalloc(sizeof(UChar), temp_len, sizeof(UChar)));
/* Convert to intermediate UChar* array */
error = U_ZERO_ERROR;
@@ -652,7 +654,7 @@ static zend_string* php_converter_do_convert(UConverter *dest_cnv,
if (U_FAILURE(error)) {
THROW_UFAILURE(objval, error);
efree(temp);
return NULL;
return nullptr;
}
temp[temp_len] = 0;
@@ -661,7 +663,7 @@ static zend_string* php_converter_do_convert(UConverter *dest_cnv,
if (U_FAILURE(error) && error != U_BUFFER_OVERFLOW_ERROR) {
THROW_UFAILURE(objval, error);
efree(temp);
return NULL;
return nullptr;
}
ret = zend_string_alloc(ret_len, 0);
@@ -673,7 +675,7 @@ static zend_string* php_converter_do_convert(UConverter *dest_cnv,
if (U_FAILURE(error)) {
THROW_UFAILURE(objval, error);
zend_string_efree(ret);
return NULL;
return nullptr;
}
return ret;
@@ -735,8 +737,8 @@ PHP_METHOD(UConverter, convert) {
PHP_METHOD(UConverter, transcode) {
char *str, *src, *dest;
size_t str_len, src_len, dest_len;
zval *options = NULL;
UConverter *src_cnv = NULL, *dest_cnv = NULL;
zval *options = nullptr;
UConverter *src_cnv = nullptr, *dest_cnv = nullptr;
ZEND_PARSE_PARAMETERS_START(3, 4)
Z_PARAM_STRING(str, str_len)
@@ -911,7 +913,7 @@ static void php_converter_free_object(zend_object *obj) {
static zend_object *php_converter_object_ctor(zend_class_entry *ce, php_converter_object **pobjval) {
php_converter_object *objval;
objval = zend_object_alloc(sizeof(php_converter_object), ce);
objval = reinterpret_cast<php_converter_object *>(zend_object_alloc(sizeof(php_converter_object), ce));
zend_object_std_init(&objval->obj, ce);
object_properties_init(&objval->obj, ce);
@@ -923,7 +925,7 @@ static zend_object *php_converter_object_ctor(zend_class_entry *ce, php_converte
}
static zend_object *php_converter_create_object(zend_class_entry *ce) {
php_converter_object *objval = NULL;
php_converter_object *objval = nullptr;
zend_object *retval = php_converter_object_ctor(ce, &objval);
object_properties_init(&(objval->obj), ce);
@@ -968,7 +970,7 @@ static zend_object *php_converter_clone_object(zend_object *object) {
/* }}} */
/* {{{ php_converter_minit */
int php_converter_minit(INIT_FUNC_ARGS) {
U_CFUNC int php_converter_minit(INIT_FUNC_ARGS) {
php_converter_ce = register_class_UConverter();
php_converter_ce->create_object = php_converter_create_object;
php_converter_ce->default_object_handlers = &php_converter_object_handlers;

View File

@@ -21,6 +21,12 @@
#include "php.h"
#ifdef __cplusplus
extern "C" {
#endif
int php_converter_minit(INIT_FUNC_ARGS);
#ifdef __cplusplus
}
#endif
#endif /* PHP_INTL_CONVERTER_H */

View File

@@ -17,12 +17,14 @@
#include <unicode/udat.h>
extern "C" {
#include "php_intl.h"
}
#include "dateformat_class.h"
#include "dateformat.h"
/* {{{ Get formatter's last error code. */
PHP_FUNCTION( datefmt_get_error_code )
U_CFUNC PHP_FUNCTION( datefmt_get_error_code )
{
DATE_FORMAT_METHOD_INIT_VARS;
@@ -41,7 +43,7 @@ PHP_FUNCTION( datefmt_get_error_code )
/* }}} */
/* {{{ Get text description for formatter's last error code. */
PHP_FUNCTION( datefmt_get_error_message )
U_CFUNC PHP_FUNCTION( datefmt_get_error_message )
{
zend_string *message = NULL;
DATE_FORMAT_METHOD_INIT_VARS;

View File

@@ -15,16 +15,18 @@
#include <config.h>
#endif
extern "C" {
#include "../php_intl.h"
#include "dateformat_class.h"
#include "../intl_convert.h"
}
#include "dateformat_class.h"
#include "dateformat_class.h"
#include <unicode/ustring.h>
#include <unicode/udat.h>
/* {{{ Get formatter datetype. */
PHP_FUNCTION( datefmt_get_datetype )
U_CFUNC PHP_FUNCTION( datefmt_get_datetype )
{
DATE_FORMAT_METHOD_INIT_VARS;
@@ -44,7 +46,7 @@ PHP_FUNCTION( datefmt_get_datetype )
/* }}} */
/* {{{ Get formatter timetype. */
PHP_FUNCTION( datefmt_get_timetype )
U_CFUNC PHP_FUNCTION( datefmt_get_timetype )
{
DATE_FORMAT_METHOD_INIT_VARS;
@@ -64,7 +66,7 @@ PHP_FUNCTION( datefmt_get_timetype )
/* }}} */
/* {{{ Get formatter pattern. */
PHP_FUNCTION( datefmt_get_pattern )
U_CFUNC PHP_FUNCTION( datefmt_get_pattern )
{
UChar value_buf[64];
uint32_t length = USIZE( value_buf );
@@ -100,12 +102,12 @@ PHP_FUNCTION( datefmt_get_pattern )
/* }}} */
/* {{{ Set formatter pattern. */
PHP_FUNCTION( datefmt_set_pattern )
U_CFUNC PHP_FUNCTION( datefmt_set_pattern )
{
char* value = NULL;
char* value = nullptr;
size_t value_len = 0;
int32_t slength = 0;
UChar* svalue = NULL;
UChar* svalue = nullptr;
bool is_pattern_localized = false;
@@ -136,9 +138,9 @@ PHP_FUNCTION( datefmt_set_pattern )
/* }}} */
/* {{{ Get formatter locale. */
PHP_FUNCTION( datefmt_get_locale )
U_CFUNC PHP_FUNCTION( datefmt_get_locale )
{
char *loc;
const char *loc;
zend_long loc_type =ULOC_ACTUAL_LOCALE;
DATE_FORMAT_METHOD_INIT_VARS;
@@ -154,14 +156,14 @@ PHP_FUNCTION( datefmt_get_locale )
/* Fetch the object. */
DATE_FORMAT_METHOD_FETCH_OBJECT;
loc = (char *)udat_getLocaleByType(DATE_FORMAT_OBJECT(dfo), loc_type,&INTL_DATA_ERROR_CODE(dfo));
loc = udat_getLocaleByType(DATE_FORMAT_OBJECT(dfo), static_cast<ULocDataLocaleType>(loc_type),&INTL_DATA_ERROR_CODE(dfo));
INTL_METHOD_CHECK_STATUS(dfo, "Error getting locale");
RETURN_STRING(loc);
}
/* }}} */
/* {{{ Get formatter isLenient. */
PHP_FUNCTION( datefmt_is_lenient )
U_CFUNC PHP_FUNCTION( datefmt_is_lenient )
{
DATE_FORMAT_METHOD_INIT_VARS;
@@ -182,7 +184,7 @@ PHP_FUNCTION( datefmt_is_lenient )
/* }}} */
/* {{{ Set formatter lenient. */
PHP_FUNCTION( datefmt_set_lenient )
U_CFUNC PHP_FUNCTION( datefmt_set_lenient )
{
bool isLenient = false;

View File

@@ -35,8 +35,14 @@ static inline IntlDateFormatter_object *php_intl_dateformatter_fetch_object(zend
}
#define Z_INTL_DATEFORMATTER_P(zv) php_intl_dateformatter_fetch_object(Z_OBJ_P(zv))
#ifdef __cplusplus
extern "C" {
#endif
void dateformat_register_IntlDateFormatter_class( void );
extern zend_class_entry *IntlDateFormatter_ce_ptr;
#ifdef __cplusplus
}
#endif
/* Auxiliary macros */

View File

@@ -25,7 +25,7 @@ void dateformat_data_init( dateformat_data* datef_data )
if( !datef_data )
return;
datef_data->udatf = NULL;
datef_data->udatf = nullptr;
intl_error_reset( &datef_data->error );
}
/* }}} */
@@ -41,7 +41,7 @@ void dateformat_data_free( dateformat_data* datef_data )
if( datef_data->udatf )
udat_close( datef_data->udatf );
datef_data->udatf = NULL;
datef_data->udatf = nullptr;
intl_error_reset( &datef_data->error );
}
/* }}} */
@@ -51,7 +51,7 @@ void dateformat_data_free( dateformat_data* datef_data )
*/
dateformat_data* dateformat_data_create( void )
{
dateformat_data* datef_data = ecalloc( 1, sizeof(dateformat_data) );
dateformat_data* datef_data = reinterpret_cast<dateformat_data *>(ecalloc( 1, sizeof(dateformat_data) ));
dateformat_data_init( datef_data );

View File

@@ -18,7 +18,13 @@
#include <unicode/udat.h>
#ifdef __cplusplus
extern "C" {
#endif
#include "intl_error.h"
#ifdef __cplusplus
}
#endif
typedef struct {
// error handling
@@ -28,8 +34,14 @@ typedef struct {
UDateFormat * udatf;
} dateformat_data;
#ifdef __cplusplus
extern "C" {
#endif
dateformat_data* dateformat_data_create( void );
void dateformat_data_init( dateformat_data* datef_data );
void dateformat_data_free( dateformat_data* datef_data );
#ifdef __cplusplus
}
#endif
#endif // DATE_FORMAT_DATA_H

View File

@@ -16,12 +16,14 @@
#include <config.h>
#endif
extern "C" {
#include "../php_intl.h"
#include "../intl_convert.h"
}
#include <unicode/ustring.h>
#include <unicode/ucal.h>
#include "../intl_convert.h"
#include "../common/common_date.h"
#include "dateformat.h"
#include "dateformat_class.h"
@@ -137,7 +139,7 @@ static UDate internal_get_timestamp(IntlDateFormatter_object *dfo,
/* {{{ Format the time value as a string. */
PHP_FUNCTION(datefmt_format)
U_CFUNC PHP_FUNCTION(datefmt_format)
{
UDate timestamp = 0;
HashTable *hash_arr = NULL;

View File

@@ -19,8 +19,10 @@
#include <unicode/ustring.h>
#include <math.h>
extern "C" {
#include "php_intl.h"
#include "intl_convert.h"
}
#include "dateformat.h"
#include "dateformat_class.h"
#include "dateformat_data.h"
@@ -70,7 +72,7 @@ static void internal_parse_to_timestamp(IntlDateFormatter_object *dfo, char* tex
static void add_to_localtime_arr( IntlDateFormatter_object *dfo, zval* return_value, const UCalendar *parsed_calendar, zend_long calendar_field, char* key_name)
{
zend_long calendar_field_val = ucal_get( parsed_calendar, calendar_field, &INTL_DATA_ERROR_CODE(dfo));
zend_long calendar_field_val = ucal_get( parsed_calendar, static_cast<UCalendarDateFields>(calendar_field), &INTL_DATA_ERROR_CODE(dfo));
INTL_METHOD_CHECK_STATUS( dfo, "Date parsing - localtime failed : could not get a field from calendar" );
if( strcmp(key_name, CALENDAR_YEAR )==0 ){
@@ -126,7 +128,7 @@ static void internal_parse_to_localtime(IntlDateFormatter_object *dfo, char* tex
/* {{{ Parse the string $value starting at parse_pos to a Unix timestamp -int */
PHP_FUNCTION(datefmt_parse)
U_CFUNC PHP_FUNCTION(datefmt_parse)
{
char* text_to_parse = NULL;
size_t text_len =0;
@@ -165,7 +167,7 @@ PHP_FUNCTION(datefmt_parse)
}
/* }}} */
PHP_METHOD(IntlDateFormatter, parseToCalendar)
U_CFUNC PHP_METHOD(IntlDateFormatter, parseToCalendar)
{
zend_string *text_to_parse = NULL;
zval* z_parse_pos = NULL;
@@ -208,7 +210,7 @@ PHP_METHOD(IntlDateFormatter, parseToCalendar)
}
/* {{{ Parse the string $value to a localtime array */
PHP_FUNCTION(datefmt_localtime)
U_CFUNC PHP_FUNCTION(datefmt_localtime)
{
char* text_to_parse = NULL;
size_t text_len =0;

View File

@@ -16,25 +16,29 @@
#include <config.h>
#endif
extern "C" {
#include "php_intl.h"
#include "formatter_class.h"
#include "intl_convert.h"
}
#include "formatter_class.h"
#include <unicode/ustring.h>
/* {{{ Get formatter attribute value. */
PHP_FUNCTION( numfmt_get_attribute )
U_CFUNC PHP_FUNCTION( numfmt_get_attribute )
{
zend_long attribute, value;
zend_long lattribute, value;
FORMATTER_METHOD_INIT_VARS;
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Ol",
&object, NumberFormatter_ce_ptr, &attribute ) == FAILURE )
&object, NumberFormatter_ce_ptr, &lattribute ) == FAILURE )
{
RETURN_THROWS();
}
UNumberFormatAttribute attribute = static_cast<UNumberFormatAttribute>(lattribute);
/* Fetch the object. */
FORMATTER_METHOD_FETCH_OBJECT;
@@ -85,9 +89,9 @@ PHP_FUNCTION( numfmt_get_attribute )
/* }}} */
/* {{{ Get formatter attribute value. */
PHP_FUNCTION( numfmt_get_text_attribute )
U_CFUNC PHP_FUNCTION( numfmt_get_text_attribute )
{
zend_long attribute;
zend_long lattribute;
UChar value_buf[64];
int32_t value_buf_size = USIZE( value_buf );
UChar* value = value_buf;
@@ -96,7 +100,7 @@ PHP_FUNCTION( numfmt_get_text_attribute )
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Ol",
&object, NumberFormatter_ce_ptr, &attribute ) == FAILURE )
&object, NumberFormatter_ce_ptr, &lattribute ) == FAILURE )
{
RETURN_THROWS();
}
@@ -104,6 +108,8 @@ PHP_FUNCTION( numfmt_get_text_attribute )
/* Fetch the object. */
FORMATTER_METHOD_FETCH_OBJECT;
UNumberFormatTextAttribute attribute = static_cast<UNumberFormatTextAttribute>(lattribute);
length = unum_getTextAttribute( FORMATTER_OBJECT(nfo), attribute, value, value_buf_size, &INTL_DATA_ERROR_CODE(nfo) );
if(INTL_DATA_ERROR_CODE(nfo) == U_BUFFER_OVERFLOW_ERROR && length >= value_buf_size) {
++length; /* to avoid U_STRING_NOT_TERMINATED_WARNING */
@@ -122,15 +128,15 @@ PHP_FUNCTION( numfmt_get_text_attribute )
/* }}} */
/* {{{ Get formatter attribute value. */
PHP_FUNCTION( numfmt_set_attribute )
U_CFUNC PHP_FUNCTION( numfmt_set_attribute )
{
zend_long attribute;
zend_long lattribute;
zval *value;
FORMATTER_METHOD_INIT_VARS;
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Oln",
&object, NumberFormatter_ce_ptr, &attribute, &value ) == FAILURE)
&object, NumberFormatter_ce_ptr, &lattribute, &value ) == FAILURE)
{
RETURN_THROWS();
}
@@ -138,6 +144,8 @@ PHP_FUNCTION( numfmt_set_attribute )
/* Fetch the object. */
FORMATTER_METHOD_FETCH_OBJECT;
UNumberFormatAttribute attribute = static_cast<UNumberFormatAttribute>(lattribute);
switch(attribute) {
case UNUM_PARSE_INT_ONLY:
case UNUM_GROUPING_USED:
@@ -175,7 +183,7 @@ PHP_FUNCTION( numfmt_set_attribute )
/* }}} */
/* {{{ Get formatter attribute value. */
PHP_FUNCTION( numfmt_set_text_attribute )
U_CFUNC PHP_FUNCTION( numfmt_set_text_attribute )
{
int32_t slength = 0;
UChar *svalue = NULL;
@@ -199,7 +207,7 @@ PHP_FUNCTION( numfmt_set_text_attribute )
INTL_METHOD_CHECK_STATUS( nfo, "Error converting attribute value to UTF-16" );
/* Actually set new attribute value. */
unum_setTextAttribute(FORMATTER_OBJECT(nfo), attribute, svalue, slength, &INTL_DATA_ERROR_CODE(nfo));
unum_setTextAttribute(FORMATTER_OBJECT(nfo), static_cast<UNumberFormatTextAttribute>(attribute), svalue, slength, &INTL_DATA_ERROR_CODE(nfo));
if (svalue) {
efree(svalue);
}
@@ -210,9 +218,9 @@ PHP_FUNCTION( numfmt_set_text_attribute )
/* }}} */
/* {{{ Get formatter symbol value. */
PHP_FUNCTION( numfmt_get_symbol )
U_CFUNC PHP_FUNCTION( numfmt_get_symbol )
{
zend_long symbol;
zend_long lsymbol;
UChar value_buf[4];
UChar *value = value_buf;
uint32_t length = USIZE(value_buf);
@@ -220,11 +228,13 @@ PHP_FUNCTION( numfmt_get_symbol )
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Ol",
&object, NumberFormatter_ce_ptr, &symbol ) == FAILURE )
&object, NumberFormatter_ce_ptr, &lsymbol ) == FAILURE )
{
RETURN_THROWS();
}
UNumberFormatSymbol symbol = static_cast<UNumberFormatSymbol>(lsymbol);
if(symbol >= UNUM_FORMAT_SYMBOL_COUNT || symbol < 0) {
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "invalid symbol value");
RETURN_FALSE;
@@ -251,9 +261,9 @@ PHP_FUNCTION( numfmt_get_symbol )
/* }}} */
/* {{{ Set formatter symbol value. */
PHP_FUNCTION( numfmt_set_symbol )
U_CFUNC PHP_FUNCTION( numfmt_set_symbol )
{
zend_long symbol;
zend_long lsymbol;
char* value = NULL;
size_t value_len = 0;
UChar* svalue = 0;
@@ -262,11 +272,13 @@ PHP_FUNCTION( numfmt_set_symbol )
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Ols",
&object, NumberFormatter_ce_ptr, &symbol, &value, &value_len ) == FAILURE )
&object, NumberFormatter_ce_ptr, &lsymbol, &value, &value_len ) == FAILURE )
{
RETURN_THROWS();
}
UNumberFormatSymbol symbol = static_cast<UNumberFormatSymbol>(lsymbol);
if (symbol >= UNUM_FORMAT_SYMBOL_COUNT || symbol < 0) {
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "invalid symbol value");
RETURN_FALSE;
@@ -291,7 +303,7 @@ PHP_FUNCTION( numfmt_set_symbol )
/* }}} */
/* {{{ Get formatter pattern. */
PHP_FUNCTION( numfmt_get_pattern )
U_CFUNC PHP_FUNCTION( numfmt_get_pattern )
{
UChar value_buf[64];
uint32_t length = USIZE( value_buf );
@@ -326,7 +338,7 @@ PHP_FUNCTION( numfmt_get_pattern )
/* }}} */
/* {{{ Set formatter pattern. */
PHP_FUNCTION( numfmt_set_pattern )
U_CFUNC PHP_FUNCTION( numfmt_set_pattern )
{
char* value = NULL;
size_t value_len = 0;
@@ -365,10 +377,10 @@ PHP_FUNCTION( numfmt_set_pattern )
/* }}} */
/* {{{ Get formatter locale. */
PHP_FUNCTION( numfmt_get_locale )
U_CFUNC PHP_FUNCTION( numfmt_get_locale )
{
zend_long type = ULOC_ACTUAL_LOCALE;
char* loc;
const char* loc;
FORMATTER_METHOD_INIT_VARS;
/* Parse parameters. */
@@ -381,7 +393,7 @@ PHP_FUNCTION( numfmt_get_locale )
/* Fetch the object. */
FORMATTER_METHOD_FETCH_OBJECT;
loc = (char *)unum_getLocaleByType(FORMATTER_OBJECT(nfo), type, &INTL_DATA_ERROR_CODE(nfo));
loc = unum_getLocaleByType(FORMATTER_OBJECT(nfo), static_cast<ULocDataLocaleType>(type), &INTL_DATA_ERROR_CODE(nfo));
INTL_METHOD_CHECK_STATUS( nfo, "Error getting locale" );
RETURN_STRING(loc);
}

View File

@@ -17,9 +17,15 @@
#include <php.h>
#ifdef __cplusplus
extern "C" {
#endif
#include "intl_common.h"
#include "intl_error.h"
#include "intl_data.h"
#ifdef __cplusplus
}
#endif
#include "formatter_data.h"
typedef struct {
@@ -32,8 +38,14 @@ static inline NumberFormatter_object *php_intl_number_format_fetch_object(zend_o
}
#define Z_INTL_NUMBERFORMATTER_P(zv) php_intl_number_format_fetch_object(Z_OBJ_P(zv))
#ifdef __cplusplus
extern "C" {
#endif
void formatter_register_class( void );
extern zend_class_entry *NumberFormatter_ce_ptr;
#ifdef __cplusplus
}
#endif
/* Auxiliary macros */

View File

@@ -52,7 +52,7 @@ void formatter_data_free( formatter_data* nf_data )
*/
formatter_data* formatter_data_create( void )
{
formatter_data* nf_data = ecalloc( 1, sizeof(formatter_data) );
formatter_data* nf_data = reinterpret_cast<formatter_data *>(ecalloc( 1, sizeof(formatter_data) ));
formatter_data_init( nf_data );

View File

@@ -19,7 +19,13 @@
#include <unicode/unum.h>
#ifdef __cplusplus
extern "C" {
#endif
#include "intl_error.h"
#ifdef __cplusplus
}
#endif
typedef struct {
// error hangling
@@ -29,8 +35,14 @@ typedef struct {
UNumberFormat* unum;
} formatter_data;
#ifdef __cplusplus
extern "C" {
#endif
formatter_data* formatter_data_create( void );
void formatter_data_init( formatter_data* nf_data );
void formatter_data_free( formatter_data* nf_data );
#ifdef __cplusplus
}
#endif
#endif // FORMATTER_DATA_H

View File

@@ -16,16 +16,18 @@
#include <config.h>
#endif
extern "C" {
#include "php_intl.h"
#include "intl_convert.h"
}
#include <unicode/ustring.h>
#include "formatter_class.h"
#include "formatter_format.h"
#include "intl_convert.h"
/* {{{ Format a number. */
PHP_FUNCTION( numfmt_format )
U_CFUNC PHP_FUNCTION( numfmt_format )
{
zval *number;
zend_long type = FORMAT_TYPE_DEFAULT;
@@ -123,7 +125,7 @@ PHP_FUNCTION( numfmt_format )
/* }}} */
/* {{{ Format a number as currency. */
PHP_FUNCTION( numfmt_format_currency )
U_CFUNC PHP_FUNCTION( numfmt_format_currency )
{
double number;
UChar format_buf[32];

View File

@@ -19,9 +19,11 @@
#include <unicode/ustring.h>
#include <unicode/uloc.h>
extern "C" {
#include "php_intl.h"
#include "formatter_class.h"
#include "intl_convert.h"
}
#include "formatter_class.h"
/* {{{ */
static int numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
@@ -67,7 +69,8 @@ static int numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
char* canonicalized_locale = canonicalize_locale_string(locale);
const char* final_locale = canonicalized_locale ? canonicalized_locale : locale;
FORMATTER_OBJECT(nfo) = unum_open(style, spattern, spattern_len, final_locale, NULL, &INTL_DATA_ERROR_CODE(nfo));
/* Create an ICU number formatter. */
FORMATTER_OBJECT(nfo) = unum_open(static_cast<UNumberFormatStyle>(style), spattern, spattern_len, final_locale, nullptr, &INTL_DATA_ERROR_CODE(nfo));
if (spattern) {
efree(spattern);
@@ -83,7 +86,7 @@ static int numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
/* }}} */
/* {{{ Create number formatter. */
PHP_FUNCTION( numfmt_create )
U_CFUNC PHP_FUNCTION( numfmt_create )
{
object_init_ex( return_value, NumberFormatter_ce_ptr );
if (numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
@@ -94,7 +97,7 @@ PHP_FUNCTION( numfmt_create )
/* }}} */
/* {{{ NumberFormatter object constructor. */
PHP_METHOD( NumberFormatter, __construct )
U_CFUNC PHP_METHOD( NumberFormatter, __construct )
{
const bool old_use_exception = INTL_G(use_exceptions);
const zend_long old_error_level = INTL_G(error_level);
@@ -111,7 +114,7 @@ PHP_METHOD( NumberFormatter, __construct )
/* }}} */
/* {{{ Get formatter's last error code. */
PHP_FUNCTION( numfmt_get_error_code )
U_CFUNC PHP_FUNCTION( numfmt_get_error_code )
{
FORMATTER_METHOD_INIT_VARS
@@ -130,7 +133,7 @@ PHP_FUNCTION( numfmt_get_error_code )
/* }}} */
/* {{{ Get text description for formatter's last error code. */
PHP_FUNCTION( numfmt_get_error_message )
U_CFUNC PHP_FUNCTION( numfmt_get_error_message )
{
zend_string *message = NULL;
FORMATTER_METHOD_INIT_VARS

View File

@@ -16,19 +16,21 @@
#include <config.h>
#endif
extern "C" {
#include "php_intl.h"
#include "intl_convert.h"
}
#include <unicode/ustring.h>
#include <locale.h>
#include "formatter_class.h"
#include "formatter_format.h"
#include "intl_convert.h"
#define ICU_LOCALE_BUG 1
/* {{{ Parse a number. */
PHP_FUNCTION( numfmt_parse )
U_CFUNC PHP_FUNCTION( numfmt_parse )
{
zend_long type = FORMAT_TYPE_DOUBLE;
UChar* sstr = NULL;
@@ -120,7 +122,7 @@ cleanup:
/* }}} */
/* {{{ Parse a number as currency. */
PHP_FUNCTION( numfmt_parse_currency )
U_CFUNC PHP_FUNCTION( numfmt_parse_currency )
{
double number;
UChar currency[5] = {0};