Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -40,15 +47,15 @@ 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 );
}
/* }}} */

/* {{{ Set collation attribute. */
PHP_FUNCTION( collator_set_attribute )
U_CFUNC PHP_FUNCTION( collator_set_attribute )
{
zend_long attribute, value;
COLLATOR_METHOD_INIT_VARS
Expand All @@ -65,15 +72,15 @@ 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;
}
/* }}} */

/* {{{ Returns the current collation strength. */
PHP_FUNCTION( collator_get_strength )
U_CFUNC PHP_FUNCTION( collator_get_strength )
{
COLLATOR_METHOD_INIT_VARS

Expand All @@ -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;

Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/*
Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -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;
}
/* }}} */
Expand All @@ -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;
Expand All @@ -96,15 +98,15 @@ 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;

if( co->ucoll )
{
ucol_close( co->ucoll );
co->ucoll = NULL;
co->ucoll = nullptr;
}

intl_error_reset( COLLATOR_ERROR_P( co ) );
Expand Down
12 changes: 12 additions & 0 deletions ext/intl/collator/collator_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;

Expand All @@ -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. */
Expand All @@ -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 );
}
Expand Down Expand Up @@ -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 )
Expand All @@ -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 )
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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 )
{
Expand Down
6 changes: 6 additions & 0 deletions ext/intl/collator/collator_convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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)
Expand All @@ -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) {
Expand All @@ -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);
Expand Down
Loading