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 4. (#20170)

This commit is contained in:
David CARLIER
2025-11-02 21:10:03 +00:00
committed by GitHub
parent 8d1a42fd10
commit 83e3a6d903
22 changed files with 370 additions and 244 deletions

View File

@@ -17,14 +17,21 @@
#include <config.h>
#endif
#if __cplusplus >= 201703L
#include <string_view>
#include <unicode/unistr.h>
#endif
extern "C" {
#include "php_intl.h"
}
#include "collator_class.h"
#include "collator_convert.h"
#include <unicode/ustring.h>
/* {{{ Get collation attribute value. */
PHP_FUNCTION( collator_get_attribute )
U_CFUNC PHP_FUNCTION( collator_get_attribute )
{
zend_long attribute, value;
@@ -40,7 +47,7 @@ PHP_FUNCTION( collator_get_attribute )
/* Fetch the object. */
COLLATOR_METHOD_FETCH_OBJECT;
value = ucol_getAttribute( co->ucoll, attribute, COLLATOR_ERROR_CODE_P( co ) );
value = ucol_getAttribute( co->ucoll, static_cast<UColAttribute>(attribute), COLLATOR_ERROR_CODE_P( co ) );
COLLATOR_CHECK_STATUS( co, "Error getting attribute value" );
RETURN_LONG( value );
@@ -48,7 +55,7 @@ PHP_FUNCTION( collator_get_attribute )
/* }}} */
/* {{{ Set collation attribute. */
PHP_FUNCTION( collator_set_attribute )
U_CFUNC PHP_FUNCTION( collator_set_attribute )
{
zend_long attribute, value;
COLLATOR_METHOD_INIT_VARS
@@ -65,7 +72,7 @@ PHP_FUNCTION( collator_set_attribute )
COLLATOR_METHOD_FETCH_OBJECT;
/* Set new value for the given attribute. */
ucol_setAttribute( co->ucoll, attribute, value, COLLATOR_ERROR_CODE_P( co ) );
ucol_setAttribute( co->ucoll, static_cast<UColAttribute>(attribute), static_cast<UColAttributeValue>(value), COLLATOR_ERROR_CODE_P( co ) );
COLLATOR_CHECK_STATUS( co, "Error setting attribute value" );
RETURN_TRUE;
@@ -73,7 +80,7 @@ PHP_FUNCTION( collator_set_attribute )
/* }}} */
/* {{{ Returns the current collation strength. */
PHP_FUNCTION( collator_get_strength )
U_CFUNC PHP_FUNCTION( collator_get_strength )
{
COLLATOR_METHOD_INIT_VARS
@@ -93,7 +100,7 @@ PHP_FUNCTION( collator_get_strength )
/* }}} */
/* {{{ Set the collation strength. */
PHP_FUNCTION( collator_set_strength )
U_CFUNC PHP_FUNCTION( collator_set_strength )
{
zend_long strength;
@@ -110,7 +117,7 @@ PHP_FUNCTION( collator_set_strength )
COLLATOR_METHOD_FETCH_OBJECT;
/* Set given strength. */
ucol_setStrength( co->ucoll, strength );
ucol_setStrength( co->ucoll, static_cast<UColAttributeValue>(strength) );
RETURN_TRUE;
}

View File

@@ -15,16 +15,18 @@
#include "collator.h"
#include "collator_class.h"
extern "C" {
#include "php_intl.h"
#include "intl_error.h"
#include "collator_arginfo.h"
}
#include "collator_sort.h"
#include "collator_convert.h"
#include "intl_error.h"
#include <unicode/ucol.h>
#include "collator_arginfo.h"
zend_class_entry *Collator_ce_ptr = NULL;
zend_class_entry *Collator_ce_ptr = nullptr;
static zend_object_handlers Collator_handlers;
/*
@@ -43,9 +45,9 @@ void Collator_objects_free(zend_object *object )
/* }}} */
/* {{{ Collator_object_create */
zend_object *Collator_object_create(zend_class_entry *ce )
U_CFUNC zend_object *Collator_object_create(zend_class_entry *ce )
{
Collator_object *intern = zend_object_alloc(sizeof(Collator_object), ce);
Collator_object *intern = reinterpret_cast<Collator_object *>(zend_object_alloc(sizeof(Collator_object), ce));
intl_error_init(COLLATOR_ERROR_P(intern));
zend_object_std_init(&intern->zo, ce );
object_properties_init(&intern->zo, ce);
@@ -61,7 +63,7 @@ zend_object *Collator_object_create(zend_class_entry *ce )
/* {{{ collator_register_Collator_symbols
* Initialize 'Collator' class
*/
void collator_register_Collator_symbols(int module_number)
U_CFUNC void collator_register_Collator_symbols(int module_number)
{
register_collator_symbols(module_number);
@@ -75,7 +77,7 @@ void collator_register_Collator_symbols(int module_number)
/* Collator has no usable clone semantics - ucol_cloneBinary/ucol_openBinary require binary buffer
for which we don't have the place to keep */
Collator_handlers.offset = XtOffsetOf(Collator_object, zo);
Collator_handlers.clone_obj = NULL;
Collator_handlers.clone_obj = nullptr;
Collator_handlers.free_obj = Collator_objects_free;
}
/* }}} */
@@ -84,7 +86,7 @@ void collator_register_Collator_symbols(int module_number)
* Initialize internals of Collator_object.
* Must be called before any other call to 'collator_object_...' functions.
*/
void collator_object_init( Collator_object* co )
U_CFUNC void collator_object_init( Collator_object* co )
{
if( !co )
return;
@@ -96,7 +98,7 @@ void collator_object_init( Collator_object* co )
/* {{{ void collator_object_destroy( Collator_object* co )
* Clean up mem allocted by internals of Collator_object
*/
void collator_object_destroy( Collator_object* co )
U_CFUNC void collator_object_destroy( Collator_object* co )
{
if( !co )
return;
@@ -104,7 +106,7 @@ void collator_object_destroy( Collator_object* co )
if( co->ucoll )
{
ucol_close( co->ucoll );
co->ucoll = NULL;
co->ucoll = nullptr;
}
intl_error_reset( COLLATOR_ERROR_P( co ) );

View File

@@ -18,9 +18,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 <unicode/ucol.h>
@@ -46,9 +52,15 @@ static inline Collator_object *php_intl_collator_fetch_object(zend_object *obj)
}
#define Z_INTL_COLLATOR_P(zv) php_intl_collator_fetch_object(Z_OBJ_P(zv))
#ifdef __cplusplus
extern "C" {
#endif
void collator_register_Collator_symbols(int module_number);
void collator_object_init( Collator_object* co );
void collator_object_destroy( Collator_object* co );
#ifdef __cplusplus
}
#endif
extern zend_class_entry *Collator_ce_ptr;

View File

@@ -17,12 +17,19 @@
#include <config.h>
#endif
#if __cplusplus >= 201703L
#include <string_view>
#include <unicode/unistr.h>
#endif
extern "C" {
#include "php_intl.h"
#include "collator_class.h"
#include "intl_convert.h"
}
#include "collator_class.h"
/* {{{ Compare two strings. */
PHP_FUNCTION( collator_compare )
U_CFUNC PHP_FUNCTION( collator_compare )
{
char* str1 = NULL;
char* str2 = NULL;

View File

@@ -17,11 +17,18 @@
#include <config.h>
#endif
#if __cplusplus >= 201703L
#include <string_view>
#include <unicode/unistr.h>
#endif
extern "C" {
#include "php_intl.h"
#include "intl_convert.h"
}
#include "collator_class.h"
#include "collator_is_numeric.h"
#include "collator_convert.h"
#include "intl_convert.h"
#include <unicode/ustring.h>
#include <php.h>
@@ -106,7 +113,7 @@ static void collator_convert_hash_item_from_utf16_to_utf8(
/* {{{ collator_convert_hash_from_utf8_to_utf16
* Convert values of the given hash from UTF-8 encoding to UTF-16LE.
*/
void collator_convert_hash_from_utf8_to_utf16( HashTable* hash, UErrorCode* status )
U_CFUNC void collator_convert_hash_from_utf8_to_utf16( HashTable* hash, UErrorCode* status )
{
zend_ulong hashIndex;
zval *hashData;
@@ -125,7 +132,7 @@ void collator_convert_hash_from_utf8_to_utf16( HashTable* hash, UErrorCode* stat
/* {{{ collator_convert_hash_from_utf16_to_utf8
* Convert values of the given hash from UTF-16LE encoding to UTF-8.
*/
void collator_convert_hash_from_utf16_to_utf8( HashTable* hash, UErrorCode* status )
U_CFUNC void collator_convert_hash_from_utf16_to_utf8( HashTable* hash, UErrorCode* status )
{
zend_ulong hashIndex;
zend_string *hashKey;
@@ -150,7 +157,7 @@ void collator_convert_hash_from_utf16_to_utf8( HashTable* hash, UErrorCode* stat
*
* @return zval* Converted string.
*/
zval* collator_convert_zstr_utf16_to_utf8( zval* utf16_zval, zval *rv )
U_CFUNC zval* collator_convert_zstr_utf16_to_utf8( zval* utf16_zval, zval *rv )
{
zend_string* u8str;
UErrorCode status = U_ZERO_ERROR;
@@ -168,7 +175,7 @@ zval* collator_convert_zstr_utf16_to_utf8( zval* utf16_zval, zval *rv )
}
/* }}} */
zend_string *collator_convert_zstr_utf8_to_utf16(zend_string *utf8_str)
U_CFUNC zend_string *collator_convert_zstr_utf8_to_utf16(zend_string *utf8_str)
{
UErrorCode status = U_ZERO_ERROR;
@@ -189,9 +196,9 @@ zend_string *collator_convert_zstr_utf8_to_utf16(zend_string *utf8_str)
/* {{{ collator_convert_object_to_string
* Convert object to UTF16-encoded string.
*/
zval* collator_convert_object_to_string( zval* obj, zval *rv )
U_CFUNC zval* collator_convert_object_to_string( zval* obj, zval *rv )
{
zval* zstr = NULL;
zval* zstr = nullptr;
UErrorCode status = U_ZERO_ERROR;
/* Bail out if it's not an object. */
@@ -211,7 +218,7 @@ zval* collator_convert_object_to_string( zval* obj, zval *rv )
}
/* Object wasn't successfully converted => bail out. */
if( zstr == NULL )
if( zstr == nullptr )
{
COLLATOR_CONVERT_RETURN_FAILED( obj );
}
@@ -244,7 +251,7 @@ zval* collator_convert_object_to_string( zval* obj, zval *rv )
*
* @return zval* Number. If str is not numeric string return number zero.
*/
zval* collator_convert_string_to_number( zval* str, zval *rv )
U_CFUNC zval* collator_convert_string_to_number( zval* str, zval *rv )
{
zval* num = collator_convert_string_to_number_if_possible( str, rv );
if( num == str )
@@ -268,7 +275,7 @@ zval* collator_convert_string_to_number( zval* str, zval *rv )
*
* @return zval* Number. If str is not numeric string return number zero.
*/
zval* collator_convert_string_to_double( zval* str, zval *rv )
U_CFUNC zval* collator_convert_string_to_double( zval* str, zval *rv )
{
zval* num = collator_convert_string_to_number( str, rv );
if( Z_TYPE_P(num) == IS_LONG )
@@ -289,7 +296,7 @@ zval* collator_convert_string_to_double( zval* str, zval *rv )
* @return zval* Number if str is numeric string. Otherwise
* original str param.
*/
zval* collator_convert_string_to_number_if_possible( zval* str, zval *rv )
U_CFUNC zval* collator_convert_string_to_number_if_possible( zval* str, zval *rv )
{
uint8_t is_numeric = 0;
zend_long lval = 0;
@@ -323,7 +330,7 @@ zval* collator_convert_string_to_number_if_possible( zval* str, zval *rv )
*
* @return zend_string* UTF16 string.
*/
zend_string *collator_zval_to_string(zval *arg)
U_CFUNC zend_string *collator_zval_to_string(zval *arg)
{
// TODO: This is extremely weird in that it leaves pre-existing strings alone and does not
// perform a UTF-8 to UTF-16 conversion for them. The assumption is that values that are
@@ -347,9 +354,9 @@ zend_string *collator_zval_to_string(zval *arg)
* @return zval* Normalized copy of arg or unmodified arg
* if normalization is not needed.
*/
zval* collator_normalize_sort_argument( zval* arg, zval *rv )
U_CFUNC zval* collator_normalize_sort_argument( zval* arg, zval *rv )
{
zval* n_arg = NULL;
zval* n_arg = nullptr;
if( Z_TYPE_P( arg ) != IS_STRING )
{

View File

@@ -19,6 +19,9 @@
#include <php.h>
#include <unicode/utypes.h>
#ifdef __cplusplus
extern "C" {
#endif
void collator_convert_hash_from_utf8_to_utf16( HashTable* hash, UErrorCode* status );
void collator_convert_hash_from_utf16_to_utf8( HashTable* hash, UErrorCode* status );
@@ -32,5 +35,8 @@ zval* collator_convert_string_to_number_if_possible( zval* str, zval *rv );
zval* collator_convert_string_to_double( zval* str, zval *rv );
zend_string *collator_zval_to_string(zval *arg);
#ifdef __cplusplus
}
#endif
#endif // COLLATOR_CONVERT_H

View File

@@ -17,7 +17,14 @@
#include <config.h>
#endif
#if __cplusplus >= 201703L
#include <string_view>
#include <unicode/unistr.h>
#endif
extern "C" {
#include "php_intl.h"
}
#include "collator_class.h"
#include "intl_data.h"
@@ -29,7 +36,7 @@ static int collator_ctor(INTERNAL_FUNCTION_PARAMETERS)
zval* object;
Collator_object* co;
intl_error_reset( NULL );
intl_error_reset( nullptr );
object = return_value;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STRING(locale, locale_len)
@@ -50,7 +57,7 @@ static int collator_ctor(INTERNAL_FUNCTION_PARAMETERS)
/* }}} */
/* {{{ Create collator. */
PHP_FUNCTION( collator_create )
U_CFUNC PHP_FUNCTION( collator_create )
{
object_init_ex( return_value, Collator_ce_ptr );
if (collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
@@ -61,7 +68,7 @@ PHP_FUNCTION( collator_create )
/* }}} */
/* {{{ Collator object constructor. */
PHP_METHOD( Collator, __construct )
U_CFUNC PHP_METHOD( Collator, __construct )
{
const bool old_use_exception = INTL_G(use_exceptions);
const zend_long old_error_level = INTL_G(error_level);

View File

@@ -17,11 +17,18 @@
#include <config.h>
#endif
#if __cplusplus >= 201703L
#include <string_view>
#include <unicode/unistr.h>
#endif
extern "C" {
#include "php_intl.h"
}
#include "collator_class.h"
/* {{{ Get collator's last error code. */
PHP_FUNCTION( collator_get_error_code )
U_CFUNC PHP_FUNCTION( collator_get_error_code )
{
COLLATOR_METHOD_INIT_VARS
@@ -34,7 +41,7 @@ PHP_FUNCTION( collator_get_error_code )
/* Fetch the object (without resetting its last error code). */
co = Z_INTL_COLLATOR_P(object);
if( co == NULL )
if( co == nullptr )
RETURN_FALSE;
/* Return collator's last error code. */
@@ -43,9 +50,9 @@ PHP_FUNCTION( collator_get_error_code )
/* }}} */
/* {{{ Get text description for collator's last error code. */
PHP_FUNCTION( collator_get_error_message )
U_CFUNC PHP_FUNCTION( collator_get_error_message )
{
zend_string* message = NULL;
zend_string* message = nullptr;
COLLATOR_METHOD_INIT_VARS
@@ -58,7 +65,7 @@ PHP_FUNCTION( collator_get_error_message )
/* Fetch the object (without resetting its last error code). */
co = Z_INTL_COLLATOR_P( object );
if( co == NULL )
if( co == nullptr )
RETURN_FALSE;
/* Return last error message. */

View File

@@ -82,20 +82,20 @@ static double collator_u_strtod(const UChar *nptr, UChar **endptr) /* {{{ */
}
*bufpos = '\0';
value = zend_strtod(numbuf, NULL);
value = zend_strtod(numbuf, nullptr);
if (numbuf != buf) {
free_alloca(numbuf, use_heap);
}
if (endptr != NULL) {
if (endptr != nullptr) {
*endptr = (UChar *)u;
}
return value;
}
if (endptr != NULL) {
if (endptr != nullptr) {
*endptr = (UChar *)nptr;
}
@@ -118,10 +118,10 @@ static zend_long collator_u_strtol(const UChar *nptr, UChar **endptr, int base)
zend_ulong cutoff;
int neg = 0, any, cutlim;
if (s == NULL) {
if (s == nullptr) {
errno = ERANGE;
if (endptr != NULL) {
*endptr = NULL;
if (endptr != nullptr) {
*endptr = nullptr;
}
return 0;
}
@@ -194,7 +194,7 @@ static zend_long collator_u_strtol(const UChar *nptr, UChar **endptr, int base)
errno = ERANGE;
} else if (neg)
acc = -acc;
if (endptr != NULL)
if (endptr != nullptr)
*endptr = (UChar *)(any ? s - 1 : nptr);
return (acc);
}
@@ -235,12 +235,12 @@ uint8_t collator_is_numeric( UChar *str, int32_t length, zend_long *lval, double
return 0;
}
} else {
end_ptr_long = NULL;
end_ptr_long = nullptr;
}
local_dval = collator_u_strtod(str, &end_ptr_double);
if (local_dval == 0 && end_ptr_double == str) {
end_ptr_double = NULL;
end_ptr_double = nullptr;
} else {
end_ptr_double = collator_skip_ws(end_ptr_double);
if (end_ptr_double == str+length) { /* floating point string */

View File

@@ -17,17 +17,24 @@
#include <config.h>
#endif
#if __cplusplus >= 201703L
#include <string_view>
#include <unicode/unistr.h>
#endif
extern "C" {
#include "php_intl.h"
}
#include "collator_class.h"
#include "intl_convert.h"
#include <zend_API.h>
/* {{{ Gets the locale name of the collator. */
PHP_FUNCTION( collator_get_locale )
U_CFUNC PHP_FUNCTION( collator_get_locale )
{
zend_long type = 0;
char* locale_name = NULL;
char* locale_name = nullptr;
COLLATOR_METHOD_INIT_VARS
@@ -42,16 +49,16 @@ PHP_FUNCTION( collator_get_locale )
COLLATOR_METHOD_FETCH_OBJECT;
if (!co || !co->ucoll) {
intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) );
intl_error_set_code( nullptr, COLLATOR_ERROR_CODE( co ) );
intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ), "Object not initialized");
zend_throw_error(NULL, "Object not initialized");
zend_throw_error(nullptr, "Object not initialized");
RETURN_THROWS();
}
/* Get locale by specified type. */
locale_name = (char*) ucol_getLocaleByType(
co->ucoll, type, COLLATOR_ERROR_CODE_P( co ) );
co->ucoll, static_cast<ULocDataLocaleType>(type), COLLATOR_ERROR_CODE_P( co ) );
COLLATOR_CHECK_STATUS( co, "Error getting locale by type" );
/* Return it. */

View File

@@ -17,12 +17,19 @@
#include <config.h>
#endif
#if __cplusplus >= 201703L
#include <string_view>
#include <unicode/unistr.h>
#endif
extern "C" {
#include "php_intl.h"
#include "intl_convert.h"
}
#include "collator.h"
#include "collator_class.h"
#include "collator_sort.h"
#include "collator_convert.h"
#include "intl_convert.h"
/**
* Declare 'index' which will point to sort key in sort key
@@ -50,8 +57,8 @@ static int collator_regular_compare_function(zval *result, zval *op1, zval *op2)
zval str1, str2;
zval num1, num2;
zval norm1, norm2;
zval *num1_p = NULL, *num2_p = NULL;
zval *norm1_p = NULL, *norm2_p = NULL;
zval *num1_p = nullptr, *num2_p = nullptr;
zval *norm1_p = nullptr, *norm2_p = nullptr;
zval *str1_p, *str2_p;
ZVAL_NULL(&str1);
@@ -66,7 +73,7 @@ static int collator_regular_compare_function(zval *result, zval *op1, zval *op2)
str2_p == ( num2_p = collator_convert_string_to_number_if_possible( str2_p, &num2 ) ) ) )
{
/* Compare the strings using ICU. */
ZEND_ASSERT(INTL_G(current_collator) != NULL);
ZEND_ASSERT(INTL_G(current_collator) != nullptr);
ZVAL_LONG(result, ucol_strcoll(
INTL_G(current_collator),
INTL_ZSTR_VAL(Z_STR_P(str1_p)), INTL_ZSTR_LEN(Z_STR_P(str1_p)),
@@ -132,8 +139,8 @@ static int collator_regular_compare_function(zval *result, zval *op1, zval *op2)
static int collator_numeric_compare_function(zval *result, zval *op1, zval *op2)
{
zval num1, num2;
zval *num1_p = NULL;
zval *num2_p = NULL;
zval *num1_p = nullptr;
zval *num2_p = nullptr;
if( Z_TYPE_P(op1) == IS_STRING )
{
@@ -168,7 +175,7 @@ static int collator_icu_compare_function(zval *result, zval *op1, zval *op2)
zend_string *str2 = collator_zval_to_string(op2);
/* Compare the strings using ICU. */
ZEND_ASSERT(INTL_G(current_collator) != NULL);
ZEND_ASSERT(INTL_G(current_collator) != nullptr);
ZVAL_LONG(result, ucol_strcoll(
INTL_G(current_collator),
INTL_ZSTR_VAL(str1), INTL_ZSTR_LEN(str1),
@@ -253,8 +260,8 @@ static collator_compare_func_t collator_get_compare_function( const zend_long so
static void collator_sort_internal( int renumber, INTERNAL_FUNCTION_PARAMETERS )
{
UCollator* saved_collator;
zval* array = NULL;
HashTable* hash = NULL;
zval* array = nullptr;
HashTable* hash = nullptr;
zend_long sort_flags = COLLATOR_SORT_REGULAR;
COLLATOR_METHOD_INIT_VARS
@@ -302,7 +309,7 @@ static void collator_sort_internal( int renumber, INTERNAL_FUNCTION_PARAMETERS )
/* }}} */
/* {{{ Sort array using specified collator. */
PHP_FUNCTION( collator_sort )
U_CFUNC PHP_FUNCTION( collator_sort )
{
collator_sort_internal( true, INTERNAL_FUNCTION_PARAM_PASSTHRU );
}
@@ -320,28 +327,28 @@ static void collator_sortkey_swap(collator_sort_key_index_t *p, collator_sort_ke
/* {{{ Equivalent to standard PHP sort using Collator.
* Uses ICU ucol_getSortKey for performance.
*/
PHP_FUNCTION( collator_sort_with_sort_keys )
U_CFUNC PHP_FUNCTION( collator_sort_with_sort_keys )
{
zval* array = NULL;
zval* array = nullptr;
zval garbage;
HashTable* hash = NULL;
zval* hashData = NULL; /* currently processed item of input hash */
HashTable* hash = nullptr;
zval* hashData = nullptr; /* currently processed item of input hash */
char* sortKeyBuf = NULL; /* buffer to store sort keys */
char* sortKeyBuf = nullptr; /* buffer to store sort keys */
uint32_t sortKeyBufSize = DEF_SORT_KEYS_BUF_SIZE; /* buffer size */
ptrdiff_t sortKeyBufOffset = 0; /* pos in buffer to store sort key */
uint32_t sortKeyLen = 0; /* the length of currently processing key */
uint32_t bufLeft = 0;
uint32_t bufIncrement = 0;
collator_sort_key_index_t* sortKeyIndxBuf = NULL; /* buffer to store 'indexes' which will be passed to 'qsort' */
collator_sort_key_index_t* sortKeyIndxBuf = nullptr; /* buffer to store 'indexes' which will be passed to 'qsort' */
uint32_t sortKeyIndxBufSize = DEF_SORT_KEYS_INDX_BUF_SIZE;
uint32_t sortKeyIndxSize = sizeof( collator_sort_key_index_t );
uint32_t sortKeyCount = 0;
uint32_t j = 0;
UChar* utf16_buf = NULL; /* tmp buffer to hold current processing string in utf-16 */
UChar* utf16_buf = nullptr; /* tmp buffer to hold current processing string in utf-16 */
int utf16_buf_size = DEF_UTF16_BUF_SIZE; /* the length of utf16_buf */
int utf16_len = 0; /* length of converted string */
@@ -358,7 +365,7 @@ PHP_FUNCTION( collator_sort_with_sort_keys )
COLLATOR_METHOD_FETCH_OBJECT;
if (!co || !co->ucoll) {
intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) );
intl_error_set_code( nullptr, COLLATOR_ERROR_CODE( co ) );
intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ), "Object not initialized");
zend_throw_error(NULL, "Object not initialized");
@@ -374,8 +381,8 @@ PHP_FUNCTION( collator_sort_with_sort_keys )
RETURN_TRUE;
/* Create bufers */
sortKeyBuf = ecalloc( sortKeyBufSize, sizeof( char ) );
sortKeyIndxBuf = ecalloc( sortKeyIndxBufSize, sizeof( uint8_t ) );
sortKeyBuf = reinterpret_cast<char *>(ecalloc( sortKeyBufSize, sizeof( char ) ));
sortKeyIndxBuf = reinterpret_cast<collator_sort_key_index_t *>(ecalloc( sortKeyIndxBufSize, sizeof( uint8_t ) ));
utf16_buf = eumalloc( utf16_buf_size );
/* Iterate through input hash and create a sort key for each value. */
@@ -391,7 +398,7 @@ PHP_FUNCTION( collator_sort_with_sort_keys )
if( U_FAILURE( COLLATOR_ERROR_CODE( co ) ) )
{
intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) );
intl_error_set_code( nullptr, COLLATOR_ERROR_CODE( co ) );
intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ), "Sort with sort keys failed");
if( utf16_buf )
@@ -430,7 +437,7 @@ PHP_FUNCTION( collator_sort_with_sort_keys )
sortKeyBufSize += bufIncrement;
bufLeft += bufIncrement;
sortKeyBuf = erealloc( sortKeyBuf, sortKeyBufSize );
sortKeyBuf = reinterpret_cast<char *>(erealloc( sortKeyBuf, sortKeyBufSize ));
sortKeyLen = ucol_getSortKey( co->ucoll, utf16_buf, utf16_len, (uint8_t*)sortKeyBuf + sortKeyBufOffset, bufLeft );
}
@@ -442,7 +449,7 @@ PHP_FUNCTION( collator_sort_with_sort_keys )
sortKeyIndxBufSize += bufIncrement;
sortKeyIndxBuf = erealloc( sortKeyIndxBuf, sortKeyIndxBufSize );
sortKeyIndxBuf = reinterpret_cast<collator_sort_key_index_t *>(erealloc( sortKeyIndxBuf, sortKeyIndxBufSize ));
}
sortKeyIndxBuf[sortKeyCount].key = (char*)sortKeyBufOffset; /* remember just offset, cause address */
@@ -485,18 +492,18 @@ PHP_FUNCTION( collator_sort_with_sort_keys )
/* }}} */
/* {{{ Sort array using specified collator, maintaining index association. */
PHP_FUNCTION( collator_asort )
U_CFUNC PHP_FUNCTION( collator_asort )
{
collator_sort_internal( false, INTERNAL_FUNCTION_PARAM_PASSTHRU );
}
/* }}} */
/* {{{ Get a sort key for a string from a Collator. */
PHP_FUNCTION( collator_get_sort_key )
U_CFUNC PHP_FUNCTION( collator_get_sort_key )
{
char* str = NULL;
char* str = nullptr;
size_t str_len = 0;
UChar* ustr = NULL;
UChar* ustr = nullptr;
int32_t ustr_len = 0;
int key_len = 0;
zend_string* key_str;
@@ -514,7 +521,7 @@ PHP_FUNCTION( collator_get_sort_key )
COLLATOR_METHOD_FETCH_OBJECT;
if (!co || !co->ucoll) {
intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) );
intl_error_set_code( nullptr, COLLATOR_ERROR_CODE( co ) );
intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ), "Object not initialized");
zend_throw_error(NULL, "Object not initialized");
@@ -531,7 +538,7 @@ PHP_FUNCTION( collator_get_sort_key )
if( U_FAILURE( COLLATOR_ERROR_CODE( co ) ) )
{
/* Set global error code. */
intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) );
intl_error_set_code( nullptr, COLLATOR_ERROR_CODE( co ) );
/* Set error messages. */
intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ), "Error converting first argument to UTF-16");
@@ -541,7 +548,7 @@ PHP_FUNCTION( collator_get_sort_key )
/* ucol_getSortKey is exception in that the key length includes the
* NUL terminator*/
key_len = ucol_getSortKey(co->ucoll, ustr, ustr_len, NULL, 0);
key_len = ucol_getSortKey(co->ucoll, ustr, ustr_len, nullptr, 0);
if(!key_len) {
efree( ustr );
RETURN_FALSE;

View File

@@ -8,23 +8,11 @@ if test "$PHP_INTL" != "no"; then
PHP_SUBST([INTL_SHARED_LIBADD])
INTL_COMMON_FLAGS="$ICU_CFLAGS -Wno-write-strings -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1"
PHP_NEW_EXTENSION([intl], m4_normalize([
collator/collator_attr.c
collator/collator_class.c
collator/collator_compare.c
collator/collator_convert.c
collator/collator_create.c
collator/collator_error.c
collator/collator_is_numeric.c
collator/collator_locale.c
collator/collator_sort.c
common/common_error.c
dateformat/dateformat_class.c
formatter/formatter_class.c
grapheme/grapheme_string.c
grapheme/grapheme_util.c
intl_convert.c
intl_error.c
listformatter/listformatter_class.c
php_intl.c
resourcebundle/resourcebundle_class.c
resourcebundle/resourcebundle_iterator.c
@@ -32,14 +20,21 @@ if test "$PHP_INTL" != "no"; then
spoofchecker/spoofchecker_class.c
spoofchecker/spoofchecker_create.c
spoofchecker/spoofchecker_main.c
transliterator/transliterator_class.c
transliterator/transliterator_methods.c
]),
[$ext_shared],,
[$INTL_COMMON_FLAGS],
[cxx])
PHP_INTL_CXX_SOURCES="intl_convertcpp.cpp \
collator/collator_attr.cpp \
collator/collator_class.cpp \
collator/collator_compare.cpp \
collator/collator_convert.cpp \
collator/collator_create.cpp \
collator/collator_error.cpp \
collator/collator_is_numeric.cpp \
collator/collator_locale.cpp \
collator/collator_sort.cpp \
common/common_enum.cpp \
common/common_date.cpp \
converter/converter.cpp \
@@ -54,6 +49,8 @@ if test "$PHP_INTL" != "no"; then
dateformat/dateformat_parse.cpp \
dateformat/datepatterngenerator_class.cpp \
dateformat/datepatterngenerator_methods.cpp \
grapheme/grapheme_string.cpp \
grapheme/grapheme_util.cpp \
msgformat/msgformat_helpers.cpp \
rangeformatter/rangeformatter_class.cpp \
timezone/timezone_class.cpp \
@@ -80,6 +77,9 @@ if test "$PHP_INTL" != "no"; then
breakiterator/rulebasedbreakiterator_methods.cpp \
breakiterator/codepointiterator_internal.cpp \
breakiterator/codepointiterator_methods.cpp \
listformatter/listformatter_class.cpp \
transliterator/transliterator_class.cpp \
transliterator/transliterator_methods.cpp \
idn/idn.cpp \
locale/locale_class.cpp \
locale/locale_methods.cpp \

View File

@@ -13,15 +13,15 @@ if (PHP_INTL != "no") {
"/I \"" + configure_module_dirname + "\" /DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
ADD_EXTENSION_DEP('intl', 'date');
ADD_SOURCES(configure_module_dirname + "/collator", "\
collator_attr.c \
collator_class.c \
collator_compare.c \
collator_convert.c \
collator_create.c \
collator_error.c \
collator_is_numeric.c \
collator_locale.c \
collator_sort.c \
collator_attr.cpp \
collator_class.cpp \
collator_compare.cpp \
collator_convert.cpp \
collator_create.cpp \
collator_error.cpp \
collator_is_numeric.cpp \
collator_locale.cpp \
collator_sort.cpp \
", "intl");
ADD_SOURCES(configure_module_dirname + "/common", "\
common_error.c \
@@ -40,7 +40,7 @@ if (PHP_INTL != "no") {
formatter_parse.cpp \
", "intl");
ADD_SOURCES(configure_module_dirname + "/listformatter", "\
listformatter_class.c \
listformatter_class.cpp \
", "intl");
ADD_SOURCES(configure_module_dirname + "/locale", "\
locale.cpp \
@@ -57,7 +57,7 @@ if (PHP_INTL != "no") {
msgformat_parse.cpp \
", "intl");
ADD_SOURCES(configure_module_dirname + "/grapheme", "\
grapheme_string.c grapheme_util.c \
grapheme_string.cpp grapheme_util.cpp \
", "intl");
ADD_SOURCES(configure_module_dirname + "/normalizer", "\
normalizer_class.cpp \
@@ -101,8 +101,8 @@ if (PHP_INTL != "no") {
}
ADD_SOURCES(configure_module_dirname + "/transliterator", "\
transliterator_class.c \
transliterator_methods.c",
transliterator_class.cpp \
transliterator_methods.cpp",
"intl");
ADD_SOURCES(configure_module_dirname + "/timezone", "\

View File

@@ -18,7 +18,13 @@
#include <php.h>
#include <unicode/utypes.h>
#ifdef __cplusplus
extern "C" {
#endif
void grapheme_close_global_iterator( void );
#ifdef __cplusplus
}
#endif
#define GRAPHEME_EXTRACT_TYPE_COUNT 0
#define GRAPHEME_EXTRACT_TYPE_MAXBYTES 1

View File

@@ -17,9 +17,16 @@
#include <config.h>
#endif
#if __cplusplus >= 201703L
#include <string_view>
#include <unicode/unistr.h>
#endif
extern "C" {
#include <php.h>
#include "grapheme.h"
#include "grapheme_util.h"
}
#include <unicode/utypes.h>
#include <unicode/utf8.h>
@@ -30,11 +37,11 @@
/* }}} */
/* {{{ Get number of graphemes in a string */
PHP_FUNCTION(grapheme_strlen)
U_CFUNC PHP_FUNCTION(grapheme_strlen)
{
char* string;
size_t string_len;
UChar* ustring = NULL;
UChar* ustring = nullptr;
int ustring_len = 0;
zend_long ret_len;
UErrorCode status;
@@ -54,17 +61,17 @@ PHP_FUNCTION(grapheme_strlen)
if ( U_FAILURE( status ) ) {
/* Set global error code. */
intl_error_set_code( NULL, status );
intl_error_set_code( nullptr, status );
/* Set error messages. */
intl_error_set_custom_msg( NULL, "Error converting input string to UTF-16");
intl_error_set_custom_msg( nullptr, "Error converting input string to UTF-16");
if (ustring) {
efree( ustring );
}
RETURN_NULL();
}
ret_len = grapheme_split_string(ustring, ustring_len, NULL, 0 );
ret_len = grapheme_split_string(ustring, ustring_len, nullptr, 0 );
if (ustring) {
efree( ustring );
@@ -79,7 +86,7 @@ PHP_FUNCTION(grapheme_strlen)
/* }}} */
/* {{{ Find position of first occurrence of a string within another */
PHP_FUNCTION(grapheme_strpos)
U_CFUNC PHP_FUNCTION(grapheme_strpos)
{
char *haystack, *needle, *locale = "";
size_t haystack_len, needle_len, locale_len = 0;
@@ -122,7 +129,7 @@ PHP_FUNCTION(grapheme_strpos)
}
/* do utf16 part of the strpos */
ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, /* fIgnoreCase */ 0, /* last */ 0, locale);
ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, nullptr, /* fIgnoreCase */ 0, /* last */ 0, locale);
if ( ret_pos >= 0 ) {
RETURN_LONG(ret_pos);
@@ -133,7 +140,7 @@ PHP_FUNCTION(grapheme_strpos)
/* }}} */
/* {{{ Find position of first occurrence of a string within another, ignoring case differences */
PHP_FUNCTION(grapheme_stripos)
U_CFUNC PHP_FUNCTION(grapheme_stripos)
{
char *haystack, *needle, *locale = "";
size_t haystack_len, needle_len, locale_len = 0;
@@ -187,7 +194,7 @@ PHP_FUNCTION(grapheme_stripos)
}
/* do utf16 part of the strpos */
ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, /* fIgnoreCase */ 1, /*last */ 0, locale);
ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, nullptr, /* fIgnoreCase */ 1, /*last */ 0, locale);
if ( ret_pos >= 0 ) {
RETURN_LONG(ret_pos);
@@ -199,7 +206,7 @@ PHP_FUNCTION(grapheme_stripos)
/* }}} */
/* {{{ Find position of last occurrence of a string within another */
PHP_FUNCTION(grapheme_strrpos)
U_CFUNC PHP_FUNCTION(grapheme_strrpos)
{
char *haystack, *needle;
char *locale = "";
@@ -246,7 +253,7 @@ PHP_FUNCTION(grapheme_strrpos)
/* else we need to continue via utf16 */
}
ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, /* f_ignore_case */ 0, /* last */ 1, locale);
ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, nullptr, /* f_ignore_case */ 0, /* last */ 1, locale);
if ( ret_pos >= 0 ) {
RETURN_LONG(ret_pos);
@@ -259,7 +266,7 @@ PHP_FUNCTION(grapheme_strrpos)
/* }}} */
/* {{{ Find position of last occurrence of a string within another, ignoring case */
PHP_FUNCTION(grapheme_strripos)
U_CFUNC PHP_FUNCTION(grapheme_strripos)
{
char *haystack, *needle, *locale = "";
size_t haystack_len, needle_len, locale_len = 0;
@@ -314,7 +321,7 @@ PHP_FUNCTION(grapheme_strripos)
/* else we need to continue via utf16 */
}
ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, /* f_ignore_case */ 1, /*last */ 1, locale);
ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, nullptr, /* f_ignore_case */ 1, /*last */ 1, locale);
if ( ret_pos >= 0 ) {
RETURN_LONG(ret_pos);
@@ -327,7 +334,7 @@ PHP_FUNCTION(grapheme_strripos)
/* }}} */
/* {{{ Returns part of a string */
PHP_FUNCTION(grapheme_substr)
U_CFUNC PHP_FUNCTION(grapheme_substr)
{
char *str, *locale = "";
zend_string *u8_sub_str;
@@ -339,7 +346,7 @@ PHP_FUNCTION(grapheme_substr)
int iter_val;
UErrorCode status;
unsigned char u_break_iterator_buffer[U_BRK_SAFECLONE_BUFFERSIZE];
UBreakIterator* bi = NULL;
UBreakIterator* bi = nullptr;
int sub_str_start_pos, sub_str_end_pos;
int32_t (*iter_func)(UBreakIterator *);
bool no_length = true;
@@ -375,25 +382,25 @@ PHP_FUNCTION(grapheme_substr)
char *sub_str;
grapheme_substr_ascii(str, str_len, start, (int32_t)length, &sub_str, &asub_str_len);
if ( NULL == sub_str ) {
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "invalid parameters");
if ( nullptr == sub_str ) {
intl_error_set( nullptr, U_ILLEGAL_ARGUMENT_ERROR, "invalid parameters");
RETURN_FALSE;
}
RETURN_STRINGL(sub_str, asub_str_len);
}
ustr = NULL;
ustr = nullptr;
ustr_len = 0;
status = U_ZERO_ERROR;
intl_convert_utf8_to_utf16(&ustr, &ustr_len, str, str_len, &status);
if ( U_FAILURE( status ) ) {
/* Set global error code. */
intl_error_set_code( NULL, status );
intl_error_set_code( nullptr, status );
/* Set error messages. */
intl_error_set_custom_msg( NULL, "Error converting input string to UTF-16");
intl_error_set_custom_msg( nullptr, "Error converting input string to UTF-16");
if (ustr) {
efree( ustr );
}
@@ -458,10 +465,10 @@ PHP_FUNCTION(grapheme_substr)
if ( !u8_sub_str ) {
/* Set global error code. */
intl_error_set_code( NULL, status );
intl_error_set_code( nullptr, status );
/* Set error messages. */
intl_error_set_custom_msg( NULL, "Error converting output string to UTF-8");
intl_error_set_custom_msg( nullptr, "Error converting output string to UTF-8");
RETURN_FALSE;
}
@@ -527,10 +534,10 @@ PHP_FUNCTION(grapheme_substr)
if ( !u8_sub_str ) {
/* Set global error code. */
intl_error_set_code( NULL, status );
intl_error_set_code( nullptr, status );
/* Set error messages. */
intl_error_set_custom_msg( NULL, "Error converting output string to UTF-8");
intl_error_set_custom_msg( nullptr, "Error converting output string to UTF-8");
RETURN_FALSE;
}
@@ -602,14 +609,14 @@ static void strstr_common_handler(INTERNAL_FUNCTION_PARAMETERS, int f_ignore_cas
/* }}} */
/* {{{ Finds first occurrence of a string within another */
PHP_FUNCTION(grapheme_strstr)
U_CFUNC PHP_FUNCTION(grapheme_strstr)
{
strstr_common_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0 /* f_ignore_case */);
}
/* }}} */
/* {{{ Finds first occurrence of a string within another */
PHP_FUNCTION(grapheme_stristr)
U_CFUNC PHP_FUNCTION(grapheme_stristr)
{
strstr_common_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1 /* f_ignore_case */);
}
@@ -712,7 +719,7 @@ static const grapheme_extract_iter grapheme_extract_iters[] = {
/* }}} */
/* {{{ Function to extract a sequence of default grapheme clusters */
PHP_FUNCTION(grapheme_extract)
U_CFUNC PHP_FUNCTION(grapheme_extract)
{
char *str, *pstr;
UText ut = UTEXT_INITIALIZER;
@@ -723,9 +730,9 @@ PHP_FUNCTION(grapheme_extract)
zend_long extract_type = GRAPHEME_EXTRACT_TYPE_COUNT;
UErrorCode status;
unsigned char u_break_iterator_buffer[U_BRK_SAFECLONE_BUFFERSIZE];
UBreakIterator* bi = NULL;
UBreakIterator* bi = nullptr;
int ret_pos;
zval *next = NULL; /* return offset of next part of the string */
zval *next = nullptr; /* return offset of next part of the string */
ZEND_PARSE_PARAMETERS_START(2, 5)
Z_PARAM_STRING(str, str_len)
@@ -740,7 +747,7 @@ PHP_FUNCTION(grapheme_extract)
lstart += str_len;
}
if ( NULL != next ) {
if ( nullptr != next ) {
ZEND_ASSERT(Z_ISREF_P(next));
ZEND_TRY_ASSIGN_REF_LONG(next, lstart);
if (UNEXPECTED(EG(exception))) {
@@ -754,7 +761,7 @@ PHP_FUNCTION(grapheme_extract)
}
if ( lstart > INT32_MAX || lstart < 0 || (size_t)lstart >= str_len ) {
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "start not contained in string");
intl_error_set( nullptr, U_ILLEGAL_ARGUMENT_ERROR, "start not contained in string");
RETURN_FALSE;
}
@@ -785,7 +792,7 @@ PHP_FUNCTION(grapheme_extract)
pstr++;
start++;
if ( pstr >= str_end ) {
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
intl_error_set( nullptr, U_ILLEGAL_ARGUMENT_ERROR,
"grapheme_extract: invalid input string");
RETURN_FALSE;
@@ -801,7 +808,7 @@ PHP_FUNCTION(grapheme_extract)
if ( -1 != grapheme_ascii_check((unsigned char *)pstr, MIN(size + 1, str_len)) ) {
size_t nsize = MIN(size, str_len);
if ( NULL != next ) {
if ( nullptr != next ) {
ZEND_TRY_ASSIGN_REF_LONG(next, start + nsize);
}
RETURN_STRINGL(pstr, nsize);
@@ -812,15 +819,15 @@ PHP_FUNCTION(grapheme_extract)
if ( U_FAILURE( status ) ) {
/* Set global error code. */
intl_error_set_code( NULL, status );
intl_error_set_code( nullptr, status );
/* Set error messages. */
intl_error_set_custom_msg( NULL, "Error opening UTF-8 text");
intl_error_set_custom_msg( nullptr, "Error opening UTF-8 text");
RETURN_FALSE;
}
bi = NULL;
bi = nullptr;
status = U_ZERO_ERROR;
bi = grapheme_get_break_iterator(u_break_iterator_buffer, &status );
@@ -835,14 +842,14 @@ PHP_FUNCTION(grapheme_extract)
utext_close(&ut);
ubrk_close(bi);
if ( NULL != next ) {
if ( nullptr != next ) {
ZEND_TRY_ASSIGN_REF_LONG(next, start + ret_pos);
}
RETURN_STRINGL(((char *)pstr), ret_pos);
}
PHP_FUNCTION(grapheme_str_split)
U_CFUNC PHP_FUNCTION(grapheme_str_split)
{
char *pstr, *end;
zend_string *str;
@@ -852,7 +859,7 @@ PHP_FUNCTION(grapheme_str_split)
UErrorCode ustatus = U_ZERO_ERROR;
int32_t pos, current, i, end_len = 0;
UBreakIterator* bi;
UText *ut = NULL;
UText *ut = nullptr;
ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_STR(str)
@@ -874,15 +881,15 @@ PHP_FUNCTION(grapheme_str_split)
if ( U_FAILURE( ustatus ) ) {
/* Set global error code. */
intl_error_set_code( NULL, ustatus );
intl_error_set_code( nullptr, ustatus );
/* Set error messages. */
intl_error_set_custom_msg( NULL, "Error opening UTF-8 text");
intl_error_set_custom_msg( nullptr, "Error opening UTF-8 text");
RETURN_FALSE;
}
bi = NULL;
bi = nullptr;
ustatus = U_ZERO_ERROR;
bi = grapheme_get_break_iterator((void*)u_break_iterator_buffer, &ustatus );
@@ -920,7 +927,7 @@ PHP_FUNCTION(grapheme_str_split)
ubrk_close(bi);
}
PHP_FUNCTION(grapheme_levenshtein)
U_CFUNC PHP_FUNCTION(grapheme_levenshtein)
{
zend_string *string1, *string2;
zend_long cost_ins = 1;
@@ -959,11 +966,17 @@ PHP_FUNCTION(grapheme_levenshtein)
size_t i2;
char *pstr1, *pstr2;
UChar *ustring1 = NULL;
UChar *ustring2 = NULL;
UChar *ustring1 = nullptr;
UChar *ustring2 = nullptr;
int32_t ustring1_len = 0;
int32_t ustring2_len = 0;
int32_t current1 = 0;
int32_t current2 = 0;
int32_t pos1 = 0;
int32_t pos2 = 0;
UCollator *collator = nullptr;
UErrorCode ustatus = U_ZERO_ERROR;
@@ -1002,8 +1015,8 @@ PHP_FUNCTION(grapheme_levenshtein)
UBreakIterator *bi1, *bi2;
int32_t strlen_1, strlen_2;
strlen_1 = grapheme_split_string(ustring1, ustring1_len, NULL, 0);
strlen_2 = grapheme_split_string(ustring2, ustring2_len, NULL, 0);
strlen_1 = grapheme_split_string(ustring1, ustring1_len, nullptr, 0);
strlen_2 = grapheme_split_string(ustring2, ustring2_len, nullptr, 0);
if (UNEXPECTED(strlen_1 < 0 || strlen_2 < 0)) {
RETVAL_FALSE;
goto out_ustring2;
@@ -1053,7 +1066,7 @@ PHP_FUNCTION(grapheme_levenshtein)
RETVAL_FALSE;
goto out_bi2;
}
UCollator *collator = ucol_open(locale, &ustatus);
collator = ucol_open(locale, &ustatus);
if (U_FAILURE(ustatus)) {
intl_error_set_code(NULL, ustatus);
@@ -1063,18 +1076,13 @@ PHP_FUNCTION(grapheme_levenshtein)
}
zend_long *p1, *p2, *tmp;
p1 = safe_emalloc((size_t) strlen_2 + 1, sizeof(zend_long), 0);
p2 = safe_emalloc((size_t) strlen_2 + 1, sizeof(zend_long), 0);
p1 = reinterpret_cast<zend_long *>(safe_emalloc((size_t) strlen_2 + 1, sizeof(zend_long), 0));
p2 = reinterpret_cast<zend_long *>(safe_emalloc((size_t) strlen_2 + 1, sizeof(zend_long), 0));
for (i2 = 0; i2 <= strlen_2; i2++) {
p1[i2] = i2 * cost_ins;
}
int32_t current1 = 0;
int32_t current2 = 0;
int32_t pos1 = 0;
int32_t pos2 = 0;
while (true) {
current1 = ubrk_current(bi1);
pos1 = ubrk_next(bi1);

View File

@@ -17,10 +17,17 @@
#include <config.h>
#endif
#if __cplusplus >= 201703L
#include <string_view>
#include <unicode/unistr.h>
#endif
extern "C" {
#include <php.h>
#include "grapheme.h"
#include "grapheme_util.h"
#include "intl_common.h"
}
#include <unicode/utypes.h>
#include <unicode/ucol.h>
@@ -33,7 +40,7 @@ ZEND_EXTERN_MODULE_GLOBALS( intl )
/* }}} */
/* {{{ grapheme_close_global_iterator - clean up */
void
U_CFUNC void
grapheme_close_global_iterator( void )
{
UBreakIterator *global_break_iterator = INTL_G( grapheme_iterator );
@@ -45,7 +52,7 @@ grapheme_close_global_iterator( void )
/* }}} */
/* {{{ grapheme_substr_ascii f='from' - starting point, l='length' */
void grapheme_substr_ascii(char *str, size_t str_len, int32_t f, int32_t l, char **sub_str, int32_t *sub_str_len)
U_CFUNC void grapheme_substr_ascii(char *str, size_t str_len, int32_t f, int32_t l, char **sub_str, int32_t *sub_str_len)
{
int32_t str_len2 = (int32_t)str_len; /* in order to avoid signed/unsigned problems */
*sub_str = NULL;
@@ -94,7 +101,7 @@ void grapheme_substr_ascii(char *str, size_t str_len, int32_t f, int32_t l, char
/* {{{ grapheme_strpos_utf16 - strrpos using utf16*/
int32_t grapheme_strpos_utf16(char *haystack, size_t haystack_len, char *needle, size_t needle_len, int32_t offset, int32_t *puchar_pos, int f_ignore_case, int last, const char* locale)
U_CFUNC int32_t grapheme_strpos_utf16(char *haystack, size_t haystack_len, char *needle, size_t needle_len, int32_t offset, int32_t *puchar_pos, int f_ignore_case, int last, const char* locale)
{
UChar *uhaystack = NULL, *uneedle = NULL;
int32_t uhaystack_len = 0, uneedle_len = 0, char_pos, ret_pos, offset_pos = 0;
@@ -212,7 +219,7 @@ finish:
/* }}} */
/* {{{ grapheme_ascii_check: ASCII check */
zend_long grapheme_ascii_check(const unsigned char *day, size_t len)
U_CFUNC zend_long grapheme_ascii_check(const unsigned char *day, size_t len)
{
int ret_len = len;
while ( len-- ) {
@@ -226,7 +233,7 @@ zend_long grapheme_ascii_check(const unsigned char *day, size_t len)
/* }}} */
/* {{{ grapheme_split_string: find and optionally return grapheme boundaries */
int32_t grapheme_split_string(const UChar *text, int32_t text_length, int boundary_array[], int boundary_array_len )
U_CFUNC int32_t grapheme_split_string(const UChar *text, int32_t text_length, int boundary_array[], int boundary_array_len )
{
unsigned char u_break_iterator_buffer[U_BRK_SAFECLONE_BUFFERSIZE];
UErrorCode status = U_ZERO_ERROR;
@@ -264,7 +271,7 @@ int32_t grapheme_split_string(const UChar *text, int32_t text_length, int bounda
/* }}} */
/* {{{ grapheme_count_graphemes */
int32_t grapheme_count_graphemes(UBreakIterator *bi, UChar *string, int32_t string_len)
U_CFUNC int32_t grapheme_count_graphemes(UBreakIterator *bi, UChar *string, int32_t string_len)
{
int ret_len = 0;
int pos = 0;
@@ -288,7 +295,7 @@ int32_t grapheme_count_graphemes(UBreakIterator *bi, UChar *string, int32_t stri
/* {{{ grapheme_get_haystack_offset - bump the haystack pointer based on the grapheme count offset */
int32_t grapheme_get_haystack_offset(UBreakIterator* bi, int32_t offset)
U_CFUNC int32_t grapheme_get_haystack_offset(UBreakIterator* bi, int32_t offset)
{
int32_t pos;
int32_t (*iter_op)(UBreakIterator* bi);
@@ -328,7 +335,7 @@ int32_t grapheme_get_haystack_offset(UBreakIterator* bi, int32_t offset)
/* }}} */
/* {{{ grapheme_strrpos_ascii: borrowed from the php ext/standard/string.c */
zend_long grapheme_strrpos_ascii(char *haystack, size_t haystack_len, char *needle, size_t needle_len, int32_t offset)
U_CFUNC zend_long grapheme_strrpos_ascii(char *haystack, size_t haystack_len, char *needle, size_t needle_len, int32_t offset)
{
char *p, *e;
@@ -368,7 +375,7 @@ zend_long grapheme_strrpos_ascii(char *haystack, size_t haystack_len, char *need
/* }}} */
/* {{{ grapheme_get_break_iterator: get a clone of the global character break iterator */
UBreakIterator* grapheme_get_break_iterator(void *stack_buffer, UErrorCode *status )
U_CFUNC UBreakIterator* grapheme_get_break_iterator(void *stack_buffer, UErrorCode *status )
{
UBreakIterator *global_break_iterator = INTL_G( grapheme_iterator );

View File

@@ -15,6 +15,9 @@
#ifndef GRAPHEME_GRAPHEME_UTIL_H
#define GRAPHEME_GRAPHEME_UTIL_H
#ifdef __cplusplus
extern "C" {
#endif
#include "php_intl.h"
#include "intl_convert.h"
@@ -35,6 +38,9 @@ int32_t grapheme_count_graphemes(UBreakIterator *bi, UChar *string, int32_t stri
int32_t grapheme_get_haystack_offset(UBreakIterator* bi, int32_t offset);
UBreakIterator* grapheme_get_break_iterator(void *stack_buffer, UErrorCode *status );
#ifdef __cplusplus
}
#endif
/* OUTSIDE_STRING: check if (possibly negative) long offset is outside the string with int32_t length */
#define OUTSIDE_STRING(offset, max_len) ( offset <= INT32_MIN || offset > INT32_MAX || (offset < 0 ? -offset > (zend_long) max_len : offset > (zend_long) max_len) )

View File

@@ -12,12 +12,14 @@
+----------------------------------------------------------------------+
*/
extern "C" {
#include "php.h"
#include "php_intl.h"
#include "intl_convert.h"
}
#include <unicode/ulistformatter.h>
#include "listformatter_class.h"
#include "listformatter_arginfo.h"
#include "intl_convert.h"
static zend_object_handlers listformatter_handlers;
@@ -28,7 +30,7 @@ static void listformatter_free_obj(zend_object *object)
if( obj->lf_data.ulistfmt )
ulistfmt_close( obj->lf_data.ulistfmt );
obj->lf_data.ulistfmt = NULL;
obj->lf_data.ulistfmt = nullptr;
intl_error_reset( &obj->lf_data.error );
zend_object_std_dtor(&obj->zo);
@@ -37,9 +39,9 @@ static void listformatter_free_obj(zend_object *object)
static zend_object *listformatter_create_object(zend_class_entry *class_type)
{
ListFormatter_object *obj;
obj = zend_object_alloc(sizeof(ListFormatter_object), class_type);
obj = reinterpret_cast<ListFormatter_object *>(zend_object_alloc(sizeof(ListFormatter_object), class_type));
obj->lf_data.ulistfmt = NULL;
obj->lf_data.ulistfmt = nullptr;
intl_error_reset( &obj->lf_data.error );
zend_object_std_init(&obj->zo, class_type);
@@ -93,7 +95,7 @@ PHP_METHOD(IntlListFormatter, __construct)
RETURN_THROWS();
}
LISTFORMATTER_OBJECT(obj) = ulistfmt_openForType(locale, type, width, &status);
LISTFORMATTER_OBJECT(obj) = ulistfmt_openForType(locale, static_cast<UListFormatterType>(type), static_cast<UListFormatterWidth>(width), &status);
#else
if (type != INTL_LISTFORMATTER_FALLBACK_TYPE_AND) {
zend_argument_value_error(2, "contains an unsupported type. ICU 66 and below only support IntlListFormatter::TYPE_AND");
@@ -109,7 +111,7 @@ PHP_METHOD(IntlListFormatter, __construct)
#endif
if (U_FAILURE(status)) {
intl_error_set(NULL, status, "Constructor failed");
intl_error_set(nullptr, status, "Constructor failed");
zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
RETURN_THROWS();
}
@@ -140,7 +142,7 @@ PHP_METHOD(IntlListFormatter, format)
str_val = zval_get_tmp_string(val, &tmp_str);
// Convert PHP string to UTF-16
UChar *ustr = NULL;
UChar *ustr = nullptr;
int32_t ustr_len = 0;
UErrorCode status = U_ZERO_ERROR;
@@ -154,7 +156,7 @@ PHP_METHOD(IntlListFormatter, format)
}
efree(items);
efree(itemLengths);
intl_error_set(NULL, status, "Failed to convert string to UTF-16");
intl_error_set(nullptr, status, "Failed to convert string to UTF-16");
RETURN_FALSE;
}
@@ -165,12 +167,13 @@ PHP_METHOD(IntlListFormatter, format)
UErrorCode status = U_ZERO_ERROR;
int32_t resultLength;
UChar *result = NULL;
UChar *result = nullptr;
zend_string *ret = nullptr;
resultLength = ulistfmt_format(LISTFORMATTER_OBJECT(obj), items, itemLengths, count, NULL, 0, &status);
resultLength = ulistfmt_format(LISTFORMATTER_OBJECT(obj), items, itemLengths, count, nullptr, 0, &status);
if (U_FAILURE(status) && status != U_BUFFER_OVERFLOW_ERROR) {
intl_error_set(NULL, status, "Failed to format list");
intl_error_set(nullptr, status, "Failed to format list");
RETVAL_FALSE;
goto cleanup;
}
@@ -184,17 +187,17 @@ PHP_METHOD(IntlListFormatter, format)
if (result) {
efree(result);
}
intl_error_set(NULL, status, "Failed to format list");
intl_error_set(nullptr, status, "Failed to format list");
RETVAL_FALSE;
goto cleanup;
}
// Convert result back to UTF-8
zend_string *ret = intl_convert_utf16_to_utf8(result, resultLength, &status);
ret = intl_convert_utf16_to_utf8(result, resultLength, &status);
efree(result);
if (!ret) {
intl_error_set(NULL, status, "Failed to convert result to UTF-8");
intl_error_set(nullptr, status, "Failed to convert result to UTF-8");
RETVAL_FALSE;
} else {
RETVAL_NEW_STR(ret);
@@ -237,5 +240,5 @@ void listformatter_register_class(void)
memcpy(&listformatter_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
listformatter_handlers.offset = XtOffsetOf(ListFormatter_object, zo);
listformatter_handlers.free_obj = listformatter_free_obj;
listformatter_handlers.clone_obj = NULL;
listformatter_handlers.clone_obj = nullptr;
}

View File

@@ -46,8 +46,14 @@ static inline ListFormatter_object *php_intl_listformatter_fetch_object(zend_obj
#define LISTFORMATTER_OBJECT(lfo) (lfo)->lf_data.ulistfmt
#ifdef __cplusplus
extern "C" {
#endif
void listformatter_register_class( void );
extern zend_class_entry *ListFormatter_ce_ptr;
#ifdef __cplusplus
}
#endif
#define INTL_LISTFORMATTER_FALLBACK_TYPE_AND 0
#define INTL_LISTFORMATTER_FALLBACK_WIDTH_WIDE 0

View File

@@ -13,22 +13,24 @@
*/
#include "transliterator_class.h"
extern "C" {
#include "php_intl.h"
#include "transliterator_arginfo.h"
#include "intl_error.h"
#include "intl_convert.h"
#include "intl_data.h"
#include "transliterator_arginfo.h"
}
#include <unicode/utrans.h>
zend_class_entry *Transliterator_ce_ptr = NULL;
zend_class_entry *Transliterator_ce_ptr = nullptr;
zend_object_handlers Transliterator_handlers;
/* {{{ int transliterator_object_construct( zval *object, UTransliterator *utrans, UErrorCode *status )
* Initialize internals of Transliterator_object.
*/
int transliterator_object_construct( zval *object,
U_CFUNC int transliterator_object_construct( zval *object,
UTransliterator *utrans,
UErrorCode *status )
{
@@ -40,7 +42,7 @@ int transliterator_object_construct( zval *object,
TRANSLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK;
assert( to->utrans == NULL );
assert( to->utrans == nullptr );
/* this assignment must happen before any return with failure because the
* caller relies on it always being made (so it can just destroy the object
* to close the transliterator) */
@@ -88,7 +90,7 @@ static void transliterator_object_destroy( Transliterator_object* to )
if( to->utrans )
{
utrans_close( to->utrans );
to->utrans = NULL;
to->utrans = nullptr;
}
intl_error_reset( TRANSLITERATOR_ERROR_P( to ) );
@@ -111,7 +113,7 @@ static zend_object *Transliterator_object_create( zend_class_entry *ce )
{
Transliterator_object* intern;
intern = zend_object_alloc(sizeof(Transliterator_object), ce);
intern = reinterpret_cast<Transliterator_object *>(zend_object_alloc(sizeof(Transliterator_object), ce));
zend_object_std_init( &intern->zo, ce );
object_properties_init( &intern->zo, ce );
@@ -133,22 +135,22 @@ static zend_object *Transliterator_clone_obj( zend_object *object )
Transliterator_object *to_new = php_intl_transliterator_fetch_object(ret_val);
zend_objects_clone_members( &to_new->zo, &to_orig->zo );
if (to_orig->utrans != NULL) {
/* guaranteed to return NULL if it fails */
if (to_orig->utrans != nullptr) {
/* guaranteed to return nullptr if it fails */
UErrorCode error = U_ZERO_ERROR;
UTransliterator *utrans = utrans_clone( to_orig->utrans, &error);
if (U_FAILURE(error)) {
if (utrans != NULL) {
if (utrans != nullptr) {
transliterator_object_destroy(to_new);
}
zend_throw_error(NULL, "Failed to clone Transliterator");
zend_throw_error(nullptr, "Failed to clone Transliterator");
} else {
to_new->utrans = utrans;
}
} else {
/* We shouldn't have unconstructed objects in the first place */
zend_throw_error(NULL, "Cannot clone uninitialized Transliterator");
zend_throw_error(nullptr, "Cannot clone uninitialized Transliterator");
}
return ret_val;
@@ -158,7 +160,7 @@ static zend_object *Transliterator_clone_obj( zend_object *object )
/* {{{ transliterator_register_Transliterator_class
* Initialize 'Transliterator' class
*/
void transliterator_register_Transliterator_class( void )
U_CFUNC void transliterator_register_Transliterator_class( void )
{
/* Create and register 'Transliterator' class. */
Transliterator_ce_ptr = register_class_Transliterator();

View File

@@ -17,8 +17,14 @@
#include <php.h>
#ifdef __cplusplus
extern "C" {
#endif
#include "intl_common.h"
#include "intl_error.h"
#ifdef __cplusplus
}
#endif
#include <unicode/utrans.h>
@@ -56,6 +62,9 @@ static inline Transliterator_object *php_intl_transliterator_fetch_object(zend_o
RETURN_THROWS(); \
}
#ifdef __cplusplus
extern "C" {
#endif
int transliterator_object_construct( zval *object,
UTransliterator *utrans,
UErrorCode *status );
@@ -64,5 +73,8 @@ void transliterator_register_Transliterator_class( void );
extern zend_class_entry *Transliterator_ce_ptr;
extern zend_object_handlers Transliterator_handlers;
#ifdef __cplusplus
}
#endif
#endif /* #ifndef TRANSLITERATOR_CLASS_H */

View File

@@ -16,23 +16,30 @@
#include <config.h>
#endif
#if __cplusplus >= 201703L
#include <string_view>
#include <unicode/unistr.h>
#endif
extern "C" {
#include "php_intl.h"
#include "transliterator.h"
#include "transliterator_class.h"
#include "intl_data.h"
#include "intl_convert.h"
}
#include "transliterator.h"
#include "transliterator_class.h"
#include <zend_exceptions.h>
static int create_transliterator( char *str_id, size_t str_id_len, zend_long direction, zval *object )
{
Transliterator_object *to;
UChar *ustr_id = NULL;
UChar *ustr_id = nullptr;
int32_t ustr_id_len = 0;
UTransliterator *utrans;
UParseError parse_error;
intl_error_reset( NULL );
intl_error_reset( nullptr );
if( ( direction != TRANSLITERATOR_FORWARD ) && (direction != TRANSLITERATOR_REVERSE ) )
{
@@ -47,31 +54,31 @@ static int create_transliterator( char *str_id, size_t str_id_len, zend_long dir
intl_convert_utf8_to_utf16( &ustr_id, &ustr_id_len, str_id, str_id_len, TRANSLITERATOR_ERROR_CODE_P( to ) );
if( U_FAILURE( TRANSLITERATOR_ERROR_CODE( to ) ) )
{
intl_error_set_code( NULL, TRANSLITERATOR_ERROR_CODE( to ) );
intl_error_set_custom_msg( NULL, "String conversion of id to UTF-16 failed");
intl_error_set_code( nullptr, TRANSLITERATOR_ERROR_CODE( to ) );
intl_error_set_custom_msg( nullptr, "String conversion of id to UTF-16 failed");
zval_ptr_dtor( object );
return FAILURE;
}
/* Open ICU Transliterator. */
utrans = utrans_openU( ustr_id, ustr_id_len, (UTransDirection ) direction,
NULL, -1, &parse_error, TRANSLITERATOR_ERROR_CODE_P( to ) );
nullptr, -1, &parse_error, TRANSLITERATOR_ERROR_CODE_P( to ) );
if (ustr_id) {
efree( ustr_id );
}
if( U_FAILURE( TRANSLITERATOR_ERROR_CODE( to ) ) )
{
char *buf = NULL;
intl_error_set_code( NULL, TRANSLITERATOR_ERROR_CODE( to ) );
char *buf = nullptr;
intl_error_set_code( nullptr, TRANSLITERATOR_ERROR_CODE( to ) );
spprintf( &buf, 0, "unable to open ICU transliterator"
" with id \"%s\"", str_id );
if( buf == NULL ) {
intl_error_set_custom_msg(NULL, "unable to open ICU transliterator");
if( buf == nullptr ) {
intl_error_set_custom_msg(nullptr, "unable to open ICU transliterator");
}
else
{
intl_error_set_custom_msg(NULL, buf);
intl_error_set_custom_msg(nullptr, buf);
efree( buf );
}
zval_ptr_dtor( object );
@@ -82,8 +89,8 @@ static int create_transliterator( char *str_id, size_t str_id_len, zend_long dir
/* no need to close the transliterator manually on construction error */
if( U_FAILURE( TRANSLITERATOR_ERROR_CODE( to ) ) )
{
intl_error_set_code( NULL, TRANSLITERATOR_ERROR_CODE( to ) );
intl_error_set_custom_msg(NULL, "internal constructor call failed");
intl_error_set_code( nullptr, TRANSLITERATOR_ERROR_CODE( to ) );
intl_error_set_custom_msg(nullptr, "internal constructor call failed");
zval_ptr_dtor( object );
return FAILURE;
}
@@ -92,7 +99,7 @@ static int create_transliterator( char *str_id, size_t str_id_len, zend_long dir
}
/* {{{ Opens a transliterator by id. */
PHP_FUNCTION( transliterator_create )
U_CFUNC PHP_FUNCTION( transliterator_create )
{
char *str_id;
size_t str_id_len;
@@ -119,11 +126,11 @@ PHP_FUNCTION( transliterator_create )
/* }}} */
/* {{{ Opens a transliterator by id. */
PHP_FUNCTION( transliterator_create_from_rules )
U_CFUNC PHP_FUNCTION( transliterator_create_from_rules )
{
char *str_rules;
size_t str_rules_len;
UChar *ustr_rules = NULL;
UChar *ustr_rules = nullptr;
int32_t ustr_rules_len = 0;
zend_long direction = TRANSLITERATOR_FORWARD;
UParseError parse_error;
@@ -161,16 +168,16 @@ PHP_FUNCTION( transliterator_create_from_rules )
efree( ustr_rules );
}
intl_error_set_code( NULL, INTL_DATA_ERROR_CODE( to ) );
intl_error_set_code( nullptr, INTL_DATA_ERROR_CODE( to ) );
if( U_FAILURE( INTL_DATA_ERROR_CODE( to ) ) )
{
char *msg = NULL;
char *msg = nullptr;
smart_str parse_error_str;
parse_error_str = intl_parse_error_to_string( &parse_error );
spprintf( &msg, 0, "unable to "
"create ICU transliterator from rules (%s)", parse_error_str.s? ZSTR_VAL(parse_error_str.s) : "" );
smart_str_free( &parse_error_str );
if( msg != NULL )
if( msg != nullptr )
{
intl_errors_set_custom_msg( INTL_DATA_ERROR_P( to ), msg);
efree( msg );
@@ -185,7 +192,7 @@ PHP_FUNCTION( transliterator_create_from_rules )
/* }}} */
/* {{{ Opens the inverse transliterator transliterator. */
PHP_FUNCTION( transliterator_create_inverse )
U_CFUNC PHP_FUNCTION( transliterator_create_inverse )
{
Transliterator_object *to_orig;
UTransliterator *utrans;
@@ -214,14 +221,14 @@ PHP_FUNCTION( transliterator_create_inverse )
/* }}} */
/* {{{ Return an array with the registered transliterator IDs. */
PHP_FUNCTION( transliterator_list_ids )
U_CFUNC PHP_FUNCTION( transliterator_list_ids )
{
UEnumeration *en;
const UChar *elem;
int32_t elem_len;
UErrorCode status = U_ZERO_ERROR;
intl_error_reset( NULL );
intl_error_reset( nullptr );
ZEND_PARSE_PARAMETERS_NONE();
@@ -245,23 +252,23 @@ PHP_FUNCTION( transliterator_list_ids )
}
uenum_close( en );
intl_error_set_code( NULL, status );
intl_error_set_code( nullptr, status );
if( U_FAILURE( status ) )
{
zend_array_destroy( Z_ARR_P(return_value) );
RETVAL_FALSE;
intl_error_set_custom_msg( NULL,
intl_error_set_custom_msg( nullptr,
"Failed to build array of registered transliterators");
}
}
/* }}} */
/* {{{ Transliterate a string. */
PHP_FUNCTION( transliterator_transliterate )
U_CFUNC PHP_FUNCTION( transliterator_transliterate )
{
char *str;
UChar *ustr = NULL,
*uresult = NULL;
UChar *ustr = nullptr,
*uresult = nullptr;
size_t str_len;
int32_t ustr_len = 0,
capacity,
@@ -276,7 +283,7 @@ PHP_FUNCTION( transliterator_transliterate )
ZVAL_UNDEF(&tmp_object);
if (object == NULL) {
if (object == nullptr) {
/* in non-OOP version, accept both a transliterator and a string */
zend_string *arg1_str;
zend_object *arg1_obj;
@@ -296,8 +303,8 @@ PHP_FUNCTION( transliterator_transliterate )
if( res == FAILURE )
{
if (!EG(exception)) {
zend_string *message = intl_error_get_message( NULL );
php_error_docref(NULL, E_WARNING, "Could not create transliterator with ID \"%s\" (%s)", ZSTR_VAL(arg1_str), ZSTR_VAL(message) );
zend_string *message = intl_error_get_message( nullptr );
php_error_docref(nullptr, E_WARNING, "Could not create transliterator with ID \"%s\" (%s)", ZSTR_VAL(arg1_str), ZSTR_VAL(message) );
zend_string_free( message );
}
ZVAL_UNDEF(&tmp_object);
@@ -343,7 +350,7 @@ PHP_FUNCTION( transliterator_transliterate )
"Neither \"start\" nor the \"end\" "
"arguments can exceed the number of UTF-16 code units "
"(in this case, %d)", (int) ustr_len );
if(msg != NULL )
if(msg != nullptr )
{
intl_errors_set(TRANSLITERATOR_ERROR_P(to), U_ILLEGAL_ARGUMENT_ERROR, msg);
efree( msg );
@@ -351,7 +358,7 @@ PHP_FUNCTION( transliterator_transliterate )
goto cleanup;
}
uresult = safe_emalloc( ustr_len, sizeof( UChar ), 1 * sizeof( UChar ) );
uresult = reinterpret_cast<UChar *>(safe_emalloc( ustr_len, sizeof( UChar ), 1 * sizeof( UChar ) ));
capacity = ustr_len + 1;
while( 1 )
@@ -366,21 +373,21 @@ PHP_FUNCTION( transliterator_transliterate )
{
efree( uresult );
uresult = safe_emalloc( uresult_len, sizeof( UChar ), 1 * sizeof( UChar ) );
uresult = reinterpret_cast<UChar *>(safe_emalloc( uresult_len, sizeof( UChar ), 1 * sizeof( UChar ) ));
capacity = uresult_len + 1;
intl_error_reset( TRANSLITERATOR_ERROR_P( to ) );
}
else if(TRANSLITERATOR_ERROR_CODE( to ) == U_STRING_NOT_TERMINATED_WARNING )
{
uresult = safe_erealloc( uresult, uresult_len, sizeof( UChar ), 1 * sizeof( UChar ) );
uresult = reinterpret_cast<UChar *>(safe_erealloc( uresult, uresult_len, sizeof( UChar ), 1 * sizeof( UChar ) ));
intl_error_reset( TRANSLITERATOR_ERROR_P( to ) );
break;
}
else if( U_FAILURE( TRANSLITERATOR_ERROR_CODE( to ) ) )
{
intl_error_set_code( NULL, TRANSLITERATOR_ERROR_CODE( to ) );
intl_error_set_code( nullptr, TRANSLITERATOR_ERROR_CODE( to ) );
intl_errors_set_custom_msg( TRANSLITERATOR_ERROR_P( to ), "transliteration failed");
goto cleanup;
}
@@ -412,16 +419,16 @@ cleanup_object:
}
/* }}} */
PHP_METHOD( Transliterator, __construct )
U_CFUNC PHP_METHOD( Transliterator, __construct )
{
/* this constructor shouldn't be called as it's private */
zend_throw_exception( NULL,
zend_throw_exception( nullptr,
"An object of this type cannot be created with the new operator.",
0 );
}
/* {{{ Get the last error code for this transliterator. */
PHP_FUNCTION( transliterator_get_error_code )
U_CFUNC PHP_FUNCTION( transliterator_get_error_code )
{
TRANSLITERATOR_METHOD_INIT_VARS
@@ -440,9 +447,9 @@ PHP_FUNCTION( transliterator_get_error_code )
/* {{{ Get the last error message for this transliterator. */
PHP_FUNCTION( transliterator_get_error_message )
U_CFUNC PHP_FUNCTION( transliterator_get_error_message )
{
zend_string* message = NULL;
zend_string* message = nullptr;
TRANSLITERATOR_METHOD_INIT_VARS
if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O",