27#if !defined(HAVE_PTRDIFF_T) && !defined(_PTRDIFF_T_DEFINED)
42static const size_t DEF_SORT_KEYS_BUF_SIZE = 1048576;
43static const size_t DEF_SORT_KEYS_BUF_INCREMENT = 1048576;
45static const size_t DEF_SORT_KEYS_INDX_BUF_SIZE = 1048576;
46static const size_t DEF_SORT_KEYS_INDX_BUF_INCREMENT = 1048576;
48static const size_t DEF_UTF16_BUF_SIZE = 1024;
59 zval *str1_p, *str2_p;
84 if( num1_p == str1_p )
181 zend_string_release(str1);
182 zend_string_release(str2);
195 zval *second = &
s->val;
222static int collator_cmp_sort_keys(
const void *p1,
const void *p2 )
227 return strcmp( key1, key2 );
239 func = collator_numeric_compare_function;
243 func = collator_icu_compare_function;
248 func = collator_regular_compare_function;
259 UCollator* saved_collator;
295 zend_hash_sort(
hash, collator_compare_func, renumber);
334 char* sortKeyBuf =
NULL;
335 uint32_t sortKeyBufSize = DEF_SORT_KEYS_BUF_SIZE;
337 uint32_t sortKeyLen = 0;
338 uint32_t bufLeft = 0;
339 uint32_t bufIncrement = 0;
342 uint32_t sortKeyIndxBufSize = DEF_SORT_KEYS_INDX_BUF_SIZE;
345 uint32_t sortKeyCount = 0;
348 UChar* utf16_buf =
NULL;
349 int utf16_buf_size = DEF_UTF16_BUF_SIZE;
364 if (!co || !co->ucoll) {
367 "Object not initialized", 0 );
378 if( !
hash || zend_hash_num_elements(
hash ) == 0 )
382 sortKeyBuf =
ecalloc( sortKeyBufSize,
sizeof(
char ) );
383 sortKeyIndxBuf =
ecalloc( sortKeyIndxBufSize,
sizeof( uint8_t ) );
384 utf16_buf =
eumalloc( utf16_buf_size );
390 utf16_len = utf16_buf_size;
405 efree( sortKeyIndxBuf );
415 utf16_buf[utf16_len] = 0;
418 if( (utf16_len + 1) > utf16_buf_size )
419 utf16_buf_size = utf16_len + 1;
422 bufLeft = sortKeyBufSize - sortKeyBufOffset;
424 sortKeyLen = ucol_getSortKey( co->ucoll,
427 (uint8_t*)sortKeyBuf + sortKeyBufOffset,
431 if( sortKeyLen > bufLeft )
433 bufIncrement = ( sortKeyLen > DEF_SORT_KEYS_BUF_INCREMENT ) ? sortKeyLen : DEF_SORT_KEYS_BUF_INCREMENT;
435 sortKeyBufSize += bufIncrement;
436 bufLeft += bufIncrement;
438 sortKeyBuf =
erealloc( sortKeyBuf, sortKeyBufSize );
440 sortKeyLen = ucol_getSortKey( co->ucoll, utf16_buf, utf16_len, (uint8_t*)sortKeyBuf + sortKeyBufOffset, bufLeft );
444 if( ( sortKeyCount + 1 ) * sortKeyIndxSize > sortKeyIndxBufSize )
446 bufIncrement = ( sortKeyIndxSize > DEF_SORT_KEYS_INDX_BUF_INCREMENT ) ? sortKeyIndxSize : DEF_SORT_KEYS_INDX_BUF_INCREMENT;
448 sortKeyIndxBufSize += bufIncrement;
450 sortKeyIndxBuf =
erealloc( sortKeyIndxBuf, sortKeyIndxBufSize );
453 sortKeyIndxBuf[sortKeyCount].
key = (
char*)sortKeyBufOffset;
455 sortKeyIndxBuf[sortKeyCount].
zstr = hashData;
457 sortKeyBufOffset += sortKeyLen;
463 for(
j = 0;
j < sortKeyCount;
j++ )
468 sortKeyIndxSize, collator_cmp_sort_keys, (
swap_func_t)collator_sortkey_swap);
474 for(
j = 0;
j < sortKeyCount;
j++ )
484 efree( sortKeyIndxBuf );
504 int32_t ustr_len = 0;
520 if (!co || !co->ucoll) {
523 "Object not initialized", 0 );
543 "Error converting first argument to UTF-16", 0 );
550 key_len = ucol_getSortKey(co->ucoll, ustr, ustr_len,
NULL, 0);
555 key_str = zend_string_alloc(key_len, 0);
556 key_len = ucol_getSortKey(co->ucoll, ustr, ustr_len, (uint8_t*)
ZSTR_VAL(key_str), key_len);
#define COLLATOR_SORT_NUMERIC
#define COLLATOR_SORT_REGULAR
#define COLLATOR_SORT_STRING
zend_class_entry * Collator_ce_ptr
#define COLLATOR_ERROR_CODE_P(co)
#define COLLATOR_CHECK_STATUS(co, msg)
#define COLLATOR_ERROR_P(co)
#define COLLATOR_METHOD_FETCH_OBJECT
#define COLLATOR_ERROR_CODE(co)
#define COLLATOR_METHOD_INIT_VARS
zval * collator_normalize_sort_argument(zval *arg, zval *rv)
zend_string * collator_zval_to_string(zval *arg)
void collator_convert_hash_from_utf16_to_utf8(HashTable *hash, UErrorCode *status)
zval * collator_convert_string_to_number_if_possible(zval *str, zval *rv)
zval * collator_convert_string_to_double(zval *str, zval *rv)
void collator_convert_hash_from_utf8_to_utf16(HashTable *hash, UErrorCode *status)
zval * collator_convert_zstr_utf16_to_utf8(zval *utf16_zval, zval *rv)
zval * collator_convert_object_to_string(zval *obj, zval *rv)
struct _collator_sort_key_index collator_sort_key_index_t
int(* collator_compare_func_t)(zval *result, zval *op1, zval *op2)
hash(string $algo, string $data, bool $binary=false, array $options=[])
#define INTL_ZSTR_LEN(str)
#define INTL_ZSTR_VAL(str)
void intl_convert_utf8_to_utf16(UChar **target, int32_t *target_len, const char *src, size_t src_len, UErrorCode *status)
void intl_errors_set_custom_msg(intl_error *err, const char *msg, int copyMsg)
void intl_error_set_code(intl_error *err, UErrorCode err_code)
collator_compare_func_t compare_func
struct UCollator * current_collator
collator_sort_with_sort_keys(Collator $object, array &$array)
collator_asort(Collator $object, array &$array, int $flags=Collator::SORT_REGULAR)
collator_get_sort_key(Collator $object, string $string)
collator_sort(Collator $object, array &$array, int $flags=Collator::SORT_REGULAR)
unsigned char key[REFLECTION_KEY_LEN]
ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format,...)
#define INTERNAL_FUNCTION_PARAMETERS
#define INTERNAL_FUNCTION_PARAM_PASSTHRU
ZEND_API zend_result zend_parse_method_parameters(uint32_t num_args, zval *this_ptr, const char *type_spec,...)
#define RETVAL_NEW_STR(s)
#define ZEND_EXTERN_MODULE_GLOBALS(module_name)
#define ecalloc(nmemb, size)
#define erealloc(ptr, size)
strcmp(string $string1, string $string2)
ZEND_API zval *ZEND_FASTCALL zend_hash_next_index_insert(HashTable *ht, zval *pData)
#define ZEND_HASH_FOREACH_END()
#define ZEND_HASH_FOREACH_VAL(ht, _val)
struct _zend_string zend_string
ZEND_API int ZEND_FASTCALL numeric_compare_function(zval *op1, zval *op2)
ZEND_API zend_result ZEND_FASTCALL compare_function(zval *result, zval *op1, zval *op2)
ZEND_API void ZEND_FASTCALL convert_to_long(zval *op)
ZEND_API void zend_sort(void *base, size_t nmemb, size_t siz, compare_func_t cmp, swap_func_t swp)
#define Z_TRY_ADDREF_P(pz)
#define Z_STRVAL_P(zval_p)
#define Z_ARRVAL_P(zval_p)
struct _zend_array HashTable
#define Z_STRLEN_P(zval_p)
void(* swap_func_t)(void *, void *)
#define ZVAL_COPY_VALUE(z, v)
ZEND_API void zval_ptr_dtor(zval *zval_ptr)
zend_refcounted * garbage