Browse Source

MFH:

- Added arginfo
- Fixed WS
- Changed C++ comments to C comments
PECL
Felipe Pena 18 years ago
parent
commit
eb1837d9de
  1. 8
      ext/intl/collator/collator.c
  2. 22
      ext/intl/collator/collator_attr.c
  3. 24
      ext/intl/collator/collator_class.c
  4. 18
      ext/intl/collator/collator_compare.c
  5. 71
      ext/intl/collator/collator_convert.c
  6. 4
      ext/intl/collator/collator_create.c
  7. 12
      ext/intl/collator/collator_error.c
  8. 8
      ext/intl/collator/collator_locale.c
  9. 99
      ext/intl/collator/collator_sort.c
  10. 22
      ext/intl/common/common_error.c
  11. 24
      ext/intl/dateformat/dateformat.c
  12. 173
      ext/intl/dateformat/dateformat_attr.c
  13. 102
      ext/intl/dateformat/dateformat_class.c
  14. 39
      ext/intl/dateformat/dateformat_format.c
  15. 98
      ext/intl/dateformat/dateformat_parse.c
  16. 12
      ext/intl/formatter/formatter.c
  17. 52
      ext/intl/formatter/formatter_attr.c
  18. 120
      ext/intl/formatter/formatter_class.c
  19. 21
      ext/intl/formatter/formatter_format.c
  20. 14
      ext/intl/formatter/formatter_main.c
  21. 14
      ext/intl/formatter/formatter_parse.c
  22. 2
      ext/intl/grapheme/grapheme_string.c
  23. 35
      ext/intl/intl_convert.c
  24. 8
      ext/intl/intl_error.c
  25. 14
      ext/intl/msgformat/msgformat.c
  26. 14
      ext/intl/msgformat/msgformat_attr.c
  27. 73
      ext/intl/msgformat/msgformat_class.c
  28. 12
      ext/intl/msgformat/msgformat_format.c
  29. 10
      ext/intl/msgformat/msgformat_parse.c
  30. 2
      ext/intl/normalizer/normalizer.c
  31. 10
      ext/intl/normalizer/normalizer_class.c
  32. 56
      ext/intl/normalizer/normalizer_normalize.c
  33. 417
      ext/intl/php_intl.c

8
ext/intl/collator/collator.c

@ -42,7 +42,7 @@ void collator_register_constants( INIT_FUNC_ARGS )
#define COLLATOR_EXPOSE_CLASS_CONST(x) zend_declare_class_constant_long( Collator_ce_ptr, ZEND_STRS( #x ) - 1, UCOL_##x TSRMLS_CC );
#define COLLATOR_EXPOSE_CUSTOM_CLASS_CONST(name, value) zend_declare_class_constant_long( Collator_ce_ptr, ZEND_STRS( name ) - 1, value TSRMLS_CC );
// UColAttributeValue constants
/* UColAttributeValue constants */
COLLATOR_EXPOSE_CUSTOM_CLASS_CONST( "DEFAULT_VALUE", UCOL_DEFAULT );
COLLATOR_EXPOSE_CLASS_CONST( PRIMARY );
@ -61,7 +61,7 @@ void collator_register_constants( INIT_FUNC_ARGS )
COLLATOR_EXPOSE_CLASS_CONST( LOWER_FIRST );
COLLATOR_EXPOSE_CLASS_CONST( UPPER_FIRST );
// UColAttribute constants
/* UColAttribute constants */
COLLATOR_EXPOSE_CLASS_CONST( FRENCH_COLLATION );
COLLATOR_EXPOSE_CLASS_CONST( ALTERNATE_HANDLING );
COLLATOR_EXPOSE_CLASS_CONST( CASE_FIRST );
@ -71,11 +71,11 @@ void collator_register_constants( INIT_FUNC_ARGS )
COLLATOR_EXPOSE_CLASS_CONST( HIRAGANA_QUATERNARY_MODE );
COLLATOR_EXPOSE_CLASS_CONST( NUMERIC_COLLATION );
// ULocDataLocaleType constants
/* ULocDataLocaleType constants */
COLLATOR_EXPOSE_CONST( ULOC_ACTUAL_LOCALE );
COLLATOR_EXPOSE_CONST( ULOC_VALID_LOCALE );
// sort flags
/* sort flags */
COLLATOR_EXPOSE_CUSTOM_CLASS_CONST( "SORT_REGULAR", COLLATOR_SORT_REGULAR );
COLLATOR_EXPOSE_CUSTOM_CLASS_CONST( "SORT_STRING", COLLATOR_SORT_STRING );
COLLATOR_EXPOSE_CUSTOM_CLASS_CONST( "SORT_NUMERIC", COLLATOR_SORT_NUMERIC );

22
ext/intl/collator/collator_attr.c

@ -37,7 +37,7 @@ PHP_FUNCTION( collator_get_attribute )
COLLATOR_METHOD_INIT_VARS
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol",
&object, Collator_ce_ptr, &attribute ) == FAILURE )
{
@ -47,7 +47,7 @@ PHP_FUNCTION( collator_get_attribute )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
COLLATOR_METHOD_FETCH_OBJECT;
value = ucol_getAttribute( co->ucoll, attribute, COLLATOR_ERROR_CODE_P( co ) );
@ -68,7 +68,7 @@ PHP_FUNCTION( collator_set_attribute )
COLLATOR_METHOD_INIT_VARS
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oll",
&object, Collator_ce_ptr, &attribute, &value ) == FAILURE)
{
@ -78,10 +78,10 @@ PHP_FUNCTION( collator_set_attribute )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
COLLATOR_METHOD_FETCH_OBJECT;
// Set new value for the given attribute.
/* Set new value for the given attribute. */
ucol_setAttribute( co->ucoll, attribute, value, COLLATOR_ERROR_CODE_P( co ) );
COLLATOR_CHECK_STATUS( co, "Error setting attribute value" );
@ -98,7 +98,7 @@ PHP_FUNCTION( collator_get_strength )
{
COLLATOR_METHOD_INIT_VARS
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
&object, Collator_ce_ptr ) == FAILURE )
{
@ -108,10 +108,10 @@ PHP_FUNCTION( collator_get_strength )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
COLLATOR_METHOD_FETCH_OBJECT;
// Get current strength and return it.
/* Get current strength and return it. */
RETURN_LONG( ucol_getStrength( co->ucoll ) );
}
/* }}} */
@ -127,7 +127,7 @@ PHP_FUNCTION( collator_set_strength )
COLLATOR_METHOD_INIT_VARS
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol",
&object, Collator_ce_ptr, &strength ) == FAILURE )
{
@ -137,10 +137,10 @@ PHP_FUNCTION( collator_set_strength )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
COLLATOR_METHOD_FETCH_OBJECT;
// Set given strength.
/* Set given strength. */
ucol_setStrength( co->ucoll, strength );
RETURN_TRUE;

24
ext/intl/collator/collator_class.c

@ -30,9 +30,9 @@
zend_class_entry *Collator_ce_ptr = NULL;
/////////////////////////////////////////////////////////////////////////////
// Auxiliary functions needed by objects of 'Collator' class
/////////////////////////////////////////////////////////////////////////////
/*
* Auxiliary functions needed by objects of 'Collator' class
*/
/* {{{ Collator_objects_dtor */
static void Collator_objects_dtor(
@ -79,15 +79,15 @@ zend_object_value Collator_object_create(
}
/* }}} */
/////////////////////////////////////////////////////////////////////////////
// 'Collator' class registration structures & functions
/////////////////////////////////////////////////////////////////////////////
/*
* 'Collator' class registration structures & functions
*/
/* {{{ Collator methods arguments info */
// NOTE: modifying 'collator_XX_args' do not forget to
// modify approptiate 'collator_XX_args' for
// the procedural API.
/* NOTE: modifying 'collator_XX_args' do not forget to
modify approptiate 'collator_XX_args' for
the procedural API.
*/
static
ZEND_BEGIN_ARG_INFO_EX( collator_0_args, 0, 0, 0 )
ZEND_END_ARG_INFO()
@ -140,12 +140,12 @@ void collator_register_Collator_class( TSRMLS_D )
{
zend_class_entry ce;
// Create and register 'Collator' class.
/* Create and register 'Collator' class. */
INIT_CLASS_ENTRY( ce, "Collator", Collator_class_functions );
ce.create_object = Collator_object_create;
Collator_ce_ptr = zend_register_internal_class( &ce TSRMLS_CC );
// Declare 'Collator' class properties.
/* Declare 'Collator' class properties. */
if( !Collator_ce_ptr )
{
zend_error( E_ERROR,

18
ext/intl/collator/collator_compare.c

@ -45,7 +45,7 @@ PHP_FUNCTION( collator_compare )
COLLATOR_METHOD_INIT_VARS
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oss",
&object, Collator_ce_ptr, &str1, &str1_len, &str2, &str2_len ) == FAILURE )
{
@ -55,7 +55,7 @@ PHP_FUNCTION( collator_compare )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
COLLATOR_METHOD_FETCH_OBJECT;
@ -63,15 +63,15 @@ PHP_FUNCTION( collator_compare )
* Compare given strings (converting them to UTF-16 first).
*/
// First convert the strings to UTF-16.
/* First convert the strings to UTF-16. */
intl_convert_utf8_to_utf16(
&ustr1, &ustr1_len, str1, str1_len, COLLATOR_ERROR_CODE_P( co ) );
if( U_FAILURE( COLLATOR_ERROR_CODE( co ) ) )
{
// Set global error code.
/* Set global error code. */
intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) TSRMLS_CC );
// Set error messages.
/* Set error messages. */
intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ),
"Error converting first argument to UTF-16", 0 TSRMLS_CC );
efree( ustr1 );
@ -82,10 +82,10 @@ PHP_FUNCTION( collator_compare )
&ustr2, &ustr2_len, str2, str2_len, COLLATOR_ERROR_CODE_P( co ) );
if( U_FAILURE( COLLATOR_ERROR_CODE( co ) ) )
{
// Set global error code.
/* Set global error code. */
intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) TSRMLS_CC );
// Set error messages.
/* Set error messages. */
intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ),
"Error converting second argument to UTF-16", 0 TSRMLS_CC );
efree( ustr1 );
@ -93,7 +93,7 @@ PHP_FUNCTION( collator_compare )
RETURN_FALSE;
}
// Then compare them.
/* Then compare them. */
result = ucol_strcoll(
co->ucoll,
ustr1, ustr1_len,
@ -104,7 +104,7 @@ PHP_FUNCTION( collator_compare )
if( ustr2 )
efree( ustr2 );
// Return result of the comparison.
/* Return result of the comparison. */
RETURN_LONG( result );
}
/* }}} */

71
ext/intl/collator/collator_convert.c

@ -51,22 +51,22 @@ static void collator_convert_hash_item_from_utf8_to_utf16(
zval** hashData = NULL;
zval* znew_val = NULL;
// Get current hash item.
/* Get current hash item. */
zend_hash_get_current_data( hash, (void**) &hashData );
// Process string values only.
/* Process string values only. */
if( Z_TYPE_P( *hashData ) != IS_STRING )
return;
old_val = Z_STRVAL_P( *hashData );
old_val_len = Z_STRLEN_P( *hashData );
// Convert it from UTF-8 to UTF-16LE and save the result to new_val[_len].
/* Convert it from UTF-8 to UTF-16LE and save the result to new_val[_len]. */
intl_convert_utf8_to_utf16( &new_val, &new_val_len, old_val, old_val_len, status );
if( U_FAILURE( *status ) )
return;
// Update current hash item with the converted value.
/* Update current hash item with the converted value. */
MAKE_STD_ZVAL( znew_val );
ZVAL_STRINGL( znew_val, (char*)new_val, UBYTES(new_val_len), FALSE );
@ -75,7 +75,7 @@ static void collator_convert_hash_item_from_utf8_to_utf16(
zend_hash_update( hash, hashKey, strlen( hashKey ) + 1,
(void*) &znew_val, sizeof(zval*), NULL );
}
else // hashKeyType == HASH_KEY_IS_LONG
else /* hashKeyType == HASH_KEY_IS_LONG */
{
zend_hash_index_update( hash, hashIndex,
(void*) &znew_val, sizeof(zval*), NULL );
@ -95,23 +95,23 @@ static void collator_convert_hash_item_from_utf16_to_utf8(
zval** hashData = NULL;
zval* znew_val = NULL;
// Get current hash item.
/* Get current hash item. */
zend_hash_get_current_data( hash, (void**) &hashData );
// Process string values only.
/* Process string values only. */
if( Z_TYPE_P( *hashData ) != IS_STRING )
return;
old_val = Z_STRVAL_P( *hashData );
old_val_len = Z_STRLEN_P( *hashData );
// Convert it from UTF-16LE to UTF-8 and save the result to new_val[_len].
/* Convert it from UTF-16LE to UTF-8 and save the result to new_val[_len]. */
intl_convert_utf16_to_utf8( &new_val, &new_val_len,
(UChar*)old_val, UCHARS(old_val_len), status );
if( U_FAILURE( *status ) )
return;
// Update current hash item with the converted value.
/* Update current hash item with the converted value. */
MAKE_STD_ZVAL( znew_val );
ZVAL_STRINGL( znew_val, (char*)new_val, new_val_len, FALSE );
@ -120,7 +120,7 @@ static void collator_convert_hash_item_from_utf16_to_utf8(
zend_hash_update( hash, hashKey, strlen( hashKey ) + 1,
(void*) &znew_val, sizeof(zval*), NULL );
}
else // hashKeyType == HASH_KEY_IS_LONG
else /* hashKeyType == HASH_KEY_IS_LONG */
{
zend_hash_index_update( hash, hashIndex,
(void*) &znew_val, sizeof(zval*), NULL );
@ -141,13 +141,13 @@ void collator_convert_hash_from_utf8_to_utf16( HashTable* hash, UErrorCode* stat
while( ( hashKeyType = zend_hash_get_current_key( hash, &hashKey, &hashIndex, 0 ) )
!= HASH_KEY_NON_EXISTANT )
{
// Convert current hash item from UTF-8 to UTF-16LE.
/* Convert current hash item from UTF-8 to UTF-16LE. */
collator_convert_hash_item_from_utf8_to_utf16(
hash, hashKeyType, hashKey, hashIndex, status );
if( U_FAILURE( *status ) )
return;
// Proceed to the next item.
/* Proceed to the next item. */
zend_hash_move_forward( hash );
}
}
@ -166,13 +166,14 @@ void collator_convert_hash_from_utf16_to_utf8( HashTable* hash, UErrorCode* stat
while( ( hashKeyType = zend_hash_get_current_key( hash, &hashKey, &hashIndex, 0 ) )
!= HASH_KEY_NON_EXISTANT )
{
// Convert current hash item from UTF-16LE to UTF-8.
/* Convert current hash item from UTF-16LE to UTF-8. */
collator_convert_hash_item_from_utf16_to_utf8(
hash, hashKeyType, hashKey, hashIndex, status );
if( U_FAILURE( *status ) )
if( U_FAILURE( *status ) ) {
return;
}
// Proceed to the next item.
/* Proceed to the next item. */
zend_hash_move_forward( hash );
}
}
@ -193,7 +194,7 @@ zval* collator_convert_zstr_utf16_to_utf8( zval* utf16_zval )
int str_len = 0;
UErrorCode status = U_ZERO_ERROR;
// Convert to utf8 then.
/* Convert to utf8 then. */
intl_convert_utf16_to_utf8( &str, &str_len,
(UChar*) Z_STRVAL_P(utf16_zval), UCHARS( Z_STRLEN_P(utf16_zval) ), &status );
if( U_FAILURE( status ) )
@ -221,7 +222,7 @@ zval* collator_convert_zstr_utf8_to_utf16( zval* utf8_zval )
int ustr_len = 0;
UErrorCode status = U_ZERO_ERROR;
// Convert the string to UTF-16.
/* Convert the string to UTF-16. */
intl_convert_utf8_to_utf16(
&ustr, &ustr_len,
Z_STRVAL_P( utf8_zval ), Z_STRLEN_P( utf8_zval ),
@ -229,7 +230,7 @@ zval* collator_convert_zstr_utf8_to_utf16( zval* utf8_zval )
if( U_FAILURE( status ) )
php_error( E_WARNING, "Error casting object to string in collator_convert_zstr_utf8_to_utf16()" );
// Set string.
/* Set string. */
ALLOC_INIT_ZVAL( zstr );
ZVAL_STRINGL( zstr, (char*)ustr, UBYTES(ustr_len), FALSE );
@ -247,13 +248,13 @@ zval* collator_convert_object_to_string( zval* obj TSRMLS_DC )
UChar* ustr = NULL;
int ustr_len = 0;
// Bail out if it's not an object.
/* Bail out if it's not an object. */
if( Z_TYPE_P( obj ) != IS_OBJECT )
{
COLLATOR_CONVERT_RETURN_FAILED( obj );
}
// Try object's handlers.
/* Try object's handlers. */
if( Z_OBJ_HT_P(obj)->get )
{
zstr = Z_OBJ_HT_P(obj)->get( obj TSRMLS_CC );
@ -262,7 +263,7 @@ zval* collator_convert_object_to_string( zval* obj TSRMLS_DC )
{
case IS_OBJECT:
{
// Bail out.
/* Bail out. */
zval_ptr_dtor( &zstr );
COLLATOR_CONVERT_RETURN_FAILED( obj );
} break;
@ -282,19 +283,19 @@ zval* collator_convert_object_to_string( zval* obj TSRMLS_DC )
if( Z_OBJ_HT_P(obj)->cast_object( obj, zstr, IS_STRING CAST_OBJECT_SHOULD_FREE TSRMLS_CC ) == FAILURE )
{
// cast_object failed => bail out.
/* cast_object failed => bail out. */
zval_ptr_dtor( &zstr );
COLLATOR_CONVERT_RETURN_FAILED( obj );
}
}
// Object wasn't successfuly converted => bail out.
/* Object wasn't successfuly converted => bail out. */
if( zstr == NULL )
{
COLLATOR_CONVERT_RETURN_FAILED( obj );
}
// Convert the string to UTF-16.
/* Convert the string to UTF-16. */
intl_convert_utf8_to_utf16(
&ustr, &ustr_len,
Z_STRVAL_P( zstr ), Z_STRLEN_P( zstr ),
@ -302,14 +303,15 @@ zval* collator_convert_object_to_string( zval* obj TSRMLS_DC )
if( U_FAILURE( status ) )
php_error( E_WARNING, "Error casting object to string in collator_convert_object_to_string()" );
// Cleanup zstr to hold utf16 string.
/* Cleanup zstr to hold utf16 string. */
zval_dtor( zstr );
// Set string.
/* Set string. */
ZVAL_STRINGL( zstr, (char*)ustr, UBYTES(ustr_len), FALSE );
// Don't free ustr cause it's set in zstr without copy.
// efree( ustr );
/* Don't free ustr cause it's set in zstr without copy.
* efree( ustr );
*/
return zstr;
}
@ -328,7 +330,7 @@ zval* collator_convert_string_to_number( zval* str )
zval* num = collator_convert_string_to_number_if_possible( str );
if( num == str )
{
// String wasn't converted => return zero.
/* String wasn't converted => return zero. */
zval_ptr_dtor( &num );
ALLOC_INIT_ZVAL( num );
@ -452,20 +454,21 @@ zval* collator_normalize_sort_argument( zval* arg )
if( Z_TYPE_P( arg ) != IS_STRING )
{
// If its not a string then nothing to do.
// Return original arg.
/* If its not a string then nothing to do.
* Return original arg.
*/
COLLATOR_CONVERT_RETURN_FAILED( arg );
}
// Try convert to number.
/* Try convert to number. */
n_arg = collator_convert_string_to_number_if_possible( arg );
if( n_arg == arg )
{
// Conversion to number failed.
/* Conversion to number failed. */
zval_ptr_dtor( &n_arg );
// Convert string to utf8.
/* Convert string to utf8. */
n_arg = collator_convert_zstr_utf16_to_utf8( arg );
}

4
ext/intl/collator/collator_create.c

@ -34,7 +34,7 @@ static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS)
intl_error_reset( NULL TSRMLS_CC );
object = return_value;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "s",
&locale, &locale_len ) == FAILURE )
{
@ -51,7 +51,7 @@ static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS)
locale = INTL_G(default_locale);
}
// Open ICU collator.
/* Open ICU collator. */
co->ucoll = ucol_open( locale, COLLATOR_ERROR_CODE_P( co ) );
INTL_CTOR_CHECK_STATUS(co, "collator_create: unable to open ICU collator");
}

12
ext/intl/collator/collator_error.c

@ -32,7 +32,7 @@ PHP_FUNCTION( collator_get_error_code )
{
COLLATOR_METHOD_INIT_VARS
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
&object, Collator_ce_ptr ) == FAILURE )
{
@ -42,12 +42,12 @@ PHP_FUNCTION( collator_get_error_code )
RETURN_FALSE;
}
// Fetch the object (without resetting its last error code).
/* Fetch the object (without resetting its last error code). */
co = (Collator_object *) zend_object_store_get_object(object TSRMLS_CC);
if( co == NULL )
RETURN_FALSE;
// Return collator's last error code.
/* Return collator's last error code. */
RETURN_LONG( COLLATOR_ERROR_CODE( co ) );
}
/* }}} */
@ -63,7 +63,7 @@ PHP_FUNCTION( collator_get_error_message )
COLLATOR_METHOD_INIT_VARS
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
&object, Collator_ce_ptr ) == FAILURE )
{
@ -73,12 +73,12 @@ PHP_FUNCTION( collator_get_error_message )
RETURN_FALSE;
}
// Fetch the object (without resetting its last error code).
/* Fetch the object (without resetting its last error code). */
co = (Collator_object *) zend_object_store_get_object( object TSRMLS_CC );
if( co == NULL )
RETURN_FALSE;
// Return last error message.
/* Return last error message. */
message = intl_error_get_message( COLLATOR_ERROR_P( co ) TSRMLS_CC );
RETURN_STRING( (char*)message, FALSE );
}

8
ext/intl/collator/collator_locale.c

@ -38,7 +38,7 @@ PHP_FUNCTION( collator_get_locale )
COLLATOR_METHOD_INIT_VARS
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol",
&object, Collator_ce_ptr, &type ) == FAILURE )
{
@ -48,15 +48,15 @@ PHP_FUNCTION( collator_get_locale )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
COLLATOR_METHOD_FETCH_OBJECT;
// Get locale by specified type.
/* Get locale by specified type. */
locale_name = (char*) ucol_getLocaleByType(
co->ucoll, type, COLLATOR_ERROR_CODE_P( co ) );
COLLATOR_CHECK_STATUS( co, "Error getting locale by type" );
// Return it.
/* Return it. */
RETVAL_STRINGL( locale_name, strlen(locale_name), TRUE );
}
/* }}} */

99
ext/intl/collator/collator_sort.c

@ -35,8 +35,8 @@ typedef long ptrdiff_t;
* buffer.
*/
typedef struct _collator_sort_key_index {
char* key; // pointer to sort key
zval** zstr; // pointer to original string(hash-item)
char* key; /* pointer to sort key */
zval** zstr; /* pointer to original string(hash-item) */
} collator_sort_key_index_t;
ZEND_EXTERN_MODULE_GLOBALS( intl )
@ -64,16 +64,16 @@ static int collator_regular_compare_function(zval *result, zval *op1, zval *op2
zval* norm1 = NULL;
zval* norm2 = NULL;
// If both args are strings AND either of args is not numeric string
// then use ICU-compare. Otherwise PHP-compare.
/* If both args are strings AND either of args is not numeric string
* then use ICU-compare. Otherwise PHP-compare. */
if( Z_TYPE_P(str1) == IS_STRING && Z_TYPE_P(str2) == IS_STRING &&
( str1 == ( num1 = collator_convert_string_to_number_if_possible( str1 ) ) ||
str2 == ( num2 = collator_convert_string_to_number_if_possible( str2 ) ) ) )
{
// Fetch collator object.
/* Fetch collator object. */
co = (Collator_object *) zend_object_store_get_object( INTL_G(current_collator) TSRMLS_CC );
// Compare the strings using ICU.
/* Compare the strings using ICU. */
result->value.lval = ucol_strcoll(
co->ucoll,
INTL_Z_STRVAL_P(str1), INTL_Z_STRLEN_P(str1),
@ -82,35 +82,36 @@ static int collator_regular_compare_function(zval *result, zval *op1, zval *op2
}
else
{
// num1 is set if str1 and str2 are strings.
/* num1 is set if str1 and str2 are strings. */
if( num1 )
{
if( num1 == str1 )
{
// str1 is string but not numeric string
// just convert it to utf8.
/* str1 is string but not numeric string
* just convert it to utf8.
*/
norm1 = collator_convert_zstr_utf16_to_utf8( str1 );
// num2 is not set but str2 is string => do normalization.
/* num2 is not set but str2 is string => do normalization. */
norm2 = collator_normalize_sort_argument( str2 );
}
else
{
// str1 is numeric strings => passthru to PHP-compare.
/* str1 is numeric strings => passthru to PHP-compare. */
zval_add_ref( &num1 );
norm1 = num1;
// str2 is numeric strings => passthru to PHP-compare.
/* str2 is numeric strings => passthru to PHP-compare. */
zval_add_ref( &num2 );
norm2 = num2;
}
}
else
{
// num1 is not set if str1 or str2 is not a string => do normalization.
/* num1 is not set if str1 or str2 is not a string => do normalization. */
norm1 = collator_normalize_sort_argument( str1 );
// if num1 is not set then num2 is not set as well => do normalization.
/* if num1 is not set then num2 is not set as well => do normalization. */
norm2 = collator_normalize_sort_argument( str2 );
}
@ -178,10 +179,10 @@ static int collator_icu_compare_function(zval *result, zval *op1, zval *op2 TSRM
str1 = collator_make_printable_zval( op1 );
str2 = collator_make_printable_zval( op2 );
// Fetch collator object.
/* Fetch collator object. */
co = (Collator_object *) zend_object_store_get_object( INTL_G(current_collator) TSRMLS_CC );
// Compare the strings using ICU.
/* Compare the strings using ICU. */
result->value.lval = ucol_strcoll(
co->ucoll,
INTL_Z_STRVAL_P(str1), INTL_Z_STRLEN_P(str1),
@ -287,7 +288,7 @@ static void collator_sort_internal( int renumber, INTERNAL_FUNCTION_PARAMETERS )
COLLATOR_METHOD_INIT_VARS
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oa|l",
&object, Collator_ce_ptr, &array, &sort_flags ) == FAILURE )
{
@ -297,29 +298,29 @@ static void collator_sort_internal( int renumber, INTERNAL_FUNCTION_PARAMETERS )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
COLLATOR_METHOD_FETCH_OBJECT;
// Set 'compare function' according to sort flags.
/* Set 'compare function' according to sort flags. */
INTL_G(compare_func) = collator_get_compare_function( sort_flags );
hash = HASH_OF( array );
// Convert strings in the specified array from UTF-8 to UTF-16.
/* Convert strings in the specified array from UTF-8 to UTF-16. */
collator_convert_hash_from_utf8_to_utf16( hash, COLLATOR_ERROR_CODE_P( co ) );
COLLATOR_CHECK_STATUS( co, "Error converting hash from UTF-8 to UTF-16" );
// Save specified collator in the request-global (?) variable.
/* Save specified collator in the request-global (?) variable. */
saved_collator = INTL_G( current_collator );
INTL_G( current_collator ) = object;
// Sort specified array.
/* Sort specified array. */
zend_hash_sort( hash, zend_qsort, collator_compare_func, renumber TSRMLS_CC );
// Restore saved collator.
/* Restore saved collator. */
INTL_G( current_collator ) = saved_collator;
// Convert strings in the specified array back to UTF-8.
/* Convert strings in the specified array back to UTF-8. */
collator_convert_hash_from_utf16_to_utf8( hash, COLLATOR_ERROR_CODE_P( co ) );
COLLATOR_CHECK_STATUS( co, "Error converting hash from UTF-16 to UTF-8" );
@ -349,31 +350,31 @@ PHP_FUNCTION( collator_sort_with_sort_keys )
{
zval* array = NULL;
HashTable* hash = NULL;
zval** hashData = NULL; // currently processed item of input hash
zval** hashData = NULL; /* currently processed item of input hash */
char* sortKeyBuf = NULL; // 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
int32_t sortKeyLen = 0; // the length of currently processing key
char* sortKeyBuf = NULL; /* 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 */
int32_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 = NULL; /* 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
int utf16_buf_size = DEF_UTF16_BUF_SIZE; // the length of utf16_buf
int utf16_len = 0; // length of converted string
UChar* utf16_buf = NULL; /* 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 */
HashTable* sortedHash = NULL;
COLLATOR_METHOD_INIT_VARS
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oa",
&object, Collator_ce_ptr, &array ) == FAILURE )
{
@ -383,7 +384,7 @@ PHP_FUNCTION( collator_sort_with_sort_keys )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
COLLATOR_METHOD_FETCH_OBJECT;
@ -395,20 +396,20 @@ PHP_FUNCTION( collator_sort_with_sort_keys )
if( !hash || zend_hash_num_elements( hash ) == 0 )
RETURN_TRUE;
// Create bufers
/* Create bufers */
sortKeyBuf = ecalloc( sortKeyBufSize, sizeof( char ) );
sortKeyIndxBuf = ecalloc( sortKeyIndxBufSize, sizeof( uint8_t ) );
utf16_buf = eumalloc( utf16_buf_size );
// Iterate through input hash and create a sort key for each value.
/* Iterate through input hash and create a sort key for each value. */
zend_hash_internal_pointer_reset( hash );
while( zend_hash_get_current_data( hash, (void**) &hashData ) == SUCCESS )
{
// Convert current hash item from UTF-8 to UTF-16LE and save the result to utf16_buf.
/* Convert current hash item from UTF-8 to UTF-16LE and save the result to utf16_buf. */
utf16_len = utf16_buf_size;
// Process string values only.
/* Process string values only. */
if( Z_TYPE_PP( hashData ) == IS_STRING )
{
intl_convert_utf8_to_utf16( &utf16_buf, &utf16_len, Z_STRVAL_PP( hashData ), Z_STRLEN_PP( hashData ), COLLATOR_ERROR_CODE_P( co ) );
@ -429,7 +430,7 @@ PHP_FUNCTION( collator_sort_with_sort_keys )
}
else
{
// Set empty string
/* Set empty string */
utf16_len = 0;
utf16_buf[utf16_len] = 0;
}
@ -437,7 +438,7 @@ PHP_FUNCTION( collator_sort_with_sort_keys )
if( (utf16_len + 1) > utf16_buf_size )
utf16_buf_size = utf16_len + 1;
// Get sort key, reallocating the buffer if needed.
/* Get sort key, reallocating the buffer if needed. */
bufLeft = sortKeyBufSize - sortKeyBufOffset;
sortKeyLen = ucol_getSortKey( co->ucoll,
@ -446,7 +447,7 @@ PHP_FUNCTION( collator_sort_with_sort_keys )
(uint8_t*)sortKeyBuf + sortKeyBufOffset,
bufLeft );
// check for sortKeyBuf overflow, increasing its size of the buffer if needed
/* check for sortKeyBuf overflow, increasing its size of the buffer if needed */
if( sortKeyLen > bufLeft )
{
bufIncrement = ( sortKeyLen > DEF_SORT_KEYS_BUF_INCREMENT ) ? sortKeyLen : DEF_SORT_KEYS_BUF_INCREMENT;
@ -459,7 +460,7 @@ PHP_FUNCTION( collator_sort_with_sort_keys )
sortKeyLen = ucol_getSortKey( co->ucoll, utf16_buf, utf16_len, (uint8_t*)sortKeyBuf + sortKeyBufOffset, bufLeft );
}
// check sortKeyIndxBuf overflow, increasing its size of the buffer if needed
/* check sortKeyIndxBuf overflow, increasing its size of the buffer if needed */
if( ( sortKeyCount + 1 ) * sortKeyIndxSize > sortKeyIndxBufSize )
{
bufIncrement = ( sortKeyIndxSize > DEF_SORT_KEYS_INDX_BUF_INCREMENT ) ? sortKeyIndxSize : DEF_SORT_KEYS_INDX_BUF_INCREMENT;
@ -469,8 +470,8 @@ PHP_FUNCTION( collator_sort_with_sort_keys )
sortKeyIndxBuf = erealloc( sortKeyIndxBuf, sortKeyIndxBufSize );
}
sortKeyIndxBuf[sortKeyCount].key = (char*)sortKeyBufOffset; // remeber just offset, cause address
// of 'sortKeyBuf' may be changed due to realloc.
sortKeyIndxBuf[sortKeyCount].key = (char*)sortKeyBufOffset; /* remeber just offset, cause address */
/* of 'sortKeyBuf' may be changed due to realloc. */
sortKeyIndxBuf[sortKeyCount].zstr = hashData;
sortKeyBufOffset += sortKeyLen;
@ -479,14 +480,14 @@ PHP_FUNCTION( collator_sort_with_sort_keys )
zend_hash_move_forward( hash );
}
// update ptrs to point to valid keys.
/* update ptrs to point to valid keys. */
for( j = 0; j < sortKeyCount; j++ )
sortKeyIndxBuf[j].key = sortKeyBuf + (ptrdiff_t)sortKeyIndxBuf[j].key;
// sort it
/* sort it */
zend_qsort( sortKeyIndxBuf, sortKeyCount, sortKeyIndxSize, collator_cmp_sort_keys TSRMLS_CC );
// for resulting hash we'll assign new hash keys rather then reordering
/* for resulting hash we'll assign new hash keys rather then reordering */
ALLOC_HASHTABLE( sortedHash );
zend_hash_init( sortedHash, 0, NULL, ZVAL_PTR_DTOR, 0 );
@ -496,7 +497,7 @@ PHP_FUNCTION( collator_sort_with_sort_keys )
zend_hash_next_index_insert( sortedHash, sortKeyIndxBuf[j].zstr, sizeof(zval **), NULL );
}
// Save sorted hash into return variable.
/* Save sorted hash into return variable. */
zval_dtor( array );
(array)->value.ht = sortedHash;
(array)->type = IS_ARRAY;

22
ext/intl/common/common_error.c

@ -51,7 +51,7 @@ PHP_FUNCTION( intl_is_failure )
{
long err_code;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "l",
&err_code ) == FAILURE )
{
@ -72,7 +72,7 @@ PHP_FUNCTION( intl_error_name )
{
long err_code;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "l",
&err_code ) == FAILURE )
{
@ -93,7 +93,7 @@ void intl_expose_icu_error_codes( INIT_FUNC_ARGS )
{
#define INTL_EXPOSE_CONST(x) REGISTER_LONG_CONSTANT(#x, x, CONST_CS)
// Warnings
/* Warnings */
INTL_EXPOSE_CONST( U_USING_FALLBACK_WARNING );
INTL_EXPOSE_CONST( U_ERROR_WARNING_START );
INTL_EXPOSE_CONST( U_USING_DEFAULT_WARNING );
@ -105,7 +105,7 @@ void intl_expose_icu_error_codes( INIT_FUNC_ARGS )
INTL_EXPOSE_CONST( U_DIFFERENT_UCA_VERSION );
INTL_EXPOSE_CONST( U_ERROR_WARNING_LIMIT );
// Standard errors
/* Standard errors */
INTL_EXPOSE_CONST( U_ZERO_ERROR );
INTL_EXPOSE_CONST( U_ILLEGAL_ARGUMENT_ERROR );
INTL_EXPOSE_CONST( U_MISSING_RESOURCE_ERROR );
@ -139,7 +139,7 @@ void intl_expose_icu_error_codes( INIT_FUNC_ARGS )
INTL_EXPOSE_CONST( U_NO_WRITE_PERMISSION );
INTL_EXPOSE_CONST( U_STANDARD_ERROR_LIMIT );
// The error code range 0x10000 0x10100 are reserved for Transliterator
/* The error code range 0x10000 0x10100 are reserved for Transliterator */
INTL_EXPOSE_CONST( U_BAD_VARIABLE_DEFINITION );
INTL_EXPOSE_CONST( U_PARSE_ERROR_START );
INTL_EXPOSE_CONST( U_MALFORMED_RULE );
@ -178,11 +178,11 @@ void intl_expose_icu_error_codes( INIT_FUNC_ARGS )
INTL_EXPOSE_CONST( U_INVALID_FUNCTION );
INTL_EXPOSE_CONST( U_PARSE_ERROR_LIMIT );
// The error code range 0x10100 0x10200 are reserved for formatting API parsing error
/* The error code range 0x10100 0x10200 are reserved for formatting API parsing error */
INTL_EXPOSE_CONST( U_UNEXPECTED_TOKEN );
INTL_EXPOSE_CONST( U_FMT_PARSE_ERROR_START );
INTL_EXPOSE_CONST( U_MULTIPLE_DECIMAL_SEPARATORS );
INTL_EXPOSE_CONST( U_MULTIPLE_DECIMAL_SEPERATORS ); // Typo: kept for backward compatibility. Use U_MULTIPLE_DECIMAL_SEPARATORS
INTL_EXPOSE_CONST( U_MULTIPLE_DECIMAL_SEPERATORS ); /* Typo: kept for backward compatibility. Use U_MULTIPLE_DECIMAL_SEPARATORS */
INTL_EXPOSE_CONST( U_MULTIPLE_EXPONENTIAL_SYMBOLS );
INTL_EXPOSE_CONST( U_MALFORMED_EXPONENTIAL_PATTERN );
INTL_EXPOSE_CONST( U_MULTIPLE_PERCENT_SYMBOLS );
@ -195,7 +195,7 @@ void intl_expose_icu_error_codes( INIT_FUNC_ARGS )
INTL_EXPOSE_CONST( U_UNSUPPORTED_ATTRIBUTE );
INTL_EXPOSE_CONST( U_FMT_PARSE_ERROR_LIMIT );
// The error code range 0x10200 0x102ff are reserved for Break Iterator related error
/* The error code range 0x10200 0x102ff are reserved for Break Iterator related error */
INTL_EXPOSE_CONST( U_BRK_INTERNAL_ERROR );
INTL_EXPOSE_CONST( U_BRK_ERROR_START );
INTL_EXPOSE_CONST( U_BRK_HEX_DIGITS_EXPECTED );
@ -213,7 +213,7 @@ void intl_expose_icu_error_codes( INIT_FUNC_ARGS )
INTL_EXPOSE_CONST( U_BRK_MALFORMED_RULE_TAG );
INTL_EXPOSE_CONST( U_BRK_ERROR_LIMIT );
// The error codes in the range 0x10300-0x103ff are reserved for regular expression related errrs
/* The error codes in the range 0x10300-0x103ff are reserved for regular expression related errrs */
INTL_EXPOSE_CONST( U_REGEX_INTERNAL_ERROR );
INTL_EXPOSE_CONST( U_REGEX_ERROR_START );
INTL_EXPOSE_CONST( U_REGEX_RULE_SYNTAX );
@ -231,7 +231,7 @@ void intl_expose_icu_error_codes( INIT_FUNC_ARGS )
INTL_EXPOSE_CONST( U_REGEX_SET_CONTAINS_STRING );
INTL_EXPOSE_CONST( U_REGEX_ERROR_LIMIT );
// The error code in the range 0x10400-0x104ff are reserved for IDNA related error codes
/* The error code in the range 0x10400-0x104ff are reserved for IDNA related error codes */
#if defined(U_IDNA_PROHIBITED_ERROR)
INTL_EXPOSE_CONST( U_IDNA_PROHIBITED_ERROR );
INTL_EXPOSE_CONST( U_IDNA_ERROR_START );
@ -245,7 +245,7 @@ void intl_expose_icu_error_codes( INIT_FUNC_ARGS )
INTL_EXPOSE_CONST( U_IDNA_ERROR_LIMIT );
#endif
// Aliases for StringPrep
/* Aliases for StringPrep */
INTL_EXPOSE_CONST( U_STRINGPREP_PROHIBITED_ERROR );
INTL_EXPOSE_CONST( U_STRINGPREP_UNASSIGNED_ERROR );
INTL_EXPOSE_CONST( U_STRINGPREP_CHECK_BIDI_ERROR );

24
ext/intl/dateformat/dateformat.c

@ -43,7 +43,7 @@ void dateformat_register_constants( INIT_FUNC_ARGS )
#define DATEFORMATTER_EXPOSE_UCAL_CLASS_CONST(x) zend_declare_class_constant_long( IntlDateFormatter_ce_ptr, ZEND_STRS( #x ) - 1, UCAL_##x TSRMLS_CC );
// UDateFormatStyle constants
/* UDateFormatStyle constants */
DATEFORMATTER_EXPOSE_CLASS_CONST( FULL );
DATEFORMATTER_EXPOSE_CLASS_CONST( LONG );
DATEFORMATTER_EXPOSE_CLASS_CONST( MEDIUM );
@ -80,16 +80,16 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
int timezone_str_len = 0;
char* pattern_str = NULL;
int pattern_str_len = 0;
UChar* svalue = NULL; //UTF-16 pattern_str
UChar* svalue = NULL; /* UTF-16 pattern_str */
int slength = 0;
UChar* timezone_utf16 = NULL; //UTF-16 timezone_str
UChar* timezone_utf16 = NULL; /* UTF-16 timezone_str */
int timezone_utf16_len = 0;
UCalendar ucal_obj = NULL;
IntlDateFormatter_object* dfo;
intl_error_reset( NULL TSRMLS_CC );
object = return_value;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "sll|sls",
&locale, &locale_len, &date_type, & time_type , &timezone_str, &timezone_str_len , &calendar ,&pattern_str , &pattern_str_len ) == FAILURE )
{
@ -100,13 +100,13 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
INTL_CHECK_LOCALE_LEN_OBJ(locale_len, return_value);
DATE_FORMAT_METHOD_FETCH_OBJECT;
// Convert pattern (if specified) to UTF-16.
/* Convert pattern (if specified) to UTF-16. */
if( pattern_str && pattern_str_len>0 ){
intl_convert_utf8_to_utf16(&svalue, &slength, pattern_str, pattern_str_len, &INTL_DATA_ERROR_CODE(dfo));
INTL_CTOR_CHECK_STATUS(dfo, "datefmt_create: error converting pattern to UTF-16");
}
// Convert pattern (if specified) to UTF-16.
/* Convert pattern (if specified) to UTF-16. */
if( timezone_str && timezone_str_len >0 ){
intl_convert_utf8_to_utf16(&timezone_utf16, &timezone_utf16_len, timezone_str, timezone_str_len, &INTL_DATA_ERROR_CODE(dfo));
INTL_CTOR_CHECK_STATUS(dfo, "datefmt_create: error converting timezone_str to UTF-16" );
@ -122,7 +122,7 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
DATE_FORMAT_OBJECT(dfo) = udat_open(time_type,date_type, locale, timezone_utf16, timezone_utf16_len ,svalue ,slength , &INTL_DATA_ERROR_CODE(dfo));
}
//Set the calendar if passed
/* Set the calendar if passed */
if(!U_FAILURE(INTL_DATA_ERROR_CODE(dfo)) && calendar) {
ucal_obj = ucal_open( timezone_utf16 , timezone_utf16_len , locale , calendar , &INTL_DATA_ERROR_CODE(dfo) );
if(!U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) {
@ -141,7 +141,7 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
INTL_CTOR_CHECK_STATUS(dfo, "datefmt_create: date formatter creation failed");
//Set the class variables
/* Set the class variables */
dfo->date_type = date_type;
dfo->time_type = time_type;
dfo->calendar = calendar;
@ -184,7 +184,7 @@ PHP_FUNCTION( datefmt_get_error_code )
zval* object = NULL;
IntlDateFormatter_object* dfo = NULL;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
&object, IntlDateFormatter_ce_ptr ) == FAILURE )
{
@ -195,7 +195,7 @@ PHP_FUNCTION( datefmt_get_error_code )
dfo = (IntlDateFormatter_object *) zend_object_store_get_object( object TSRMLS_CC );
// Return formatter's last error code.
/* Return formatter's last error code. */
RETURN_LONG( INTL_DATA_ERROR_CODE(dfo) );
}
/* }}} */
@ -211,7 +211,7 @@ PHP_FUNCTION( datefmt_get_error_message )
zval* object = NULL;
IntlDateFormatter_object* dfo = NULL;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
&object, IntlDateFormatter_ce_ptr ) == FAILURE )
{
@ -223,7 +223,7 @@ PHP_FUNCTION( datefmt_get_error_message )
dfo = (IntlDateFormatter_object *) zend_object_store_get_object( object TSRMLS_CC );
// Return last error message.
/* Return last error message. */
message = intl_error_get_message( &dfo->datef_data.error TSRMLS_CC );
RETURN_STRING( message, 0);
}

173
ext/intl/dateformat/dateformat_attr.c

@ -27,40 +27,36 @@
#include <unicode/ucal.h>
static void internal_set_calendar(IntlDateFormatter_object *dfo, char* timezone_id , int timezone_id_len , int calendar ,zval* return_value TSRMLS_DC){
int timezone_utf16_len = 0;
UChar* timezone_utf16 = NULL; /* timezone_id in UTF-16 */
char* locale = NULL;
int locale_type =ULOC_ACTUAL_LOCALE;
int timezone_utf16_len = 0;
UChar* timezone_utf16 = NULL; //timezone_id in UTF-16
char* locale = NULL;
int locale_type =ULOC_ACTUAL_LOCALE;
UCalendar* ucal_obj = NULL;
//check for the validity of value of calendar passed
intl_error_reset( NULL TSRMLS_CC );
if( calendar > 1){
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"datefmt_set_calendar: calendar value specified is out of valid range", 0 TSRMLS_CC);
RETURN_FALSE;
}
// Convert timezone to UTF-16.
intl_convert_utf8_to_utf16(&timezone_utf16, &timezone_utf16_len, timezone_id, timezone_id_len , &INTL_DATA_ERROR_CODE(dfo));
INTL_METHOD_CHECK_STATUS(dfo, "Error converting timezone to UTF-16" );
UCalendar* ucal_obj = NULL;
/* check for the validity of value of calendar passed */
intl_error_reset( NULL TSRMLS_CC );
if( calendar > 1){
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"datefmt_set_calendar: calendar value specified is out of valid range", 0 TSRMLS_CC);
RETURN_FALSE;
}
//Get the lcoale for the dateformatter
locale = (char *)udat_getLocaleByType(DATE_FORMAT_OBJECT(dfo), locale_type ,&INTL_DATA_ERROR_CODE(dfo));
/* Convert timezone to UTF-16. */
intl_convert_utf8_to_utf16(&timezone_utf16, &timezone_utf16_len, timezone_id, timezone_id_len , &INTL_DATA_ERROR_CODE(dfo));
INTL_METHOD_CHECK_STATUS(dfo, "Error converting timezone to UTF-16" );
//Set the calendar if passed
ucal_obj = ucal_open( timezone_utf16 , timezone_utf16_len , locale , calendar , &INTL_DATA_ERROR_CODE(dfo) );
udat_setCalendar( DATE_FORMAT_OBJECT(dfo), ucal_obj );
INTL_METHOD_CHECK_STATUS(dfo, "Error setting the calendar.");
/* Get the lcoale for the dateformatter */
locale = (char *)udat_getLocaleByType(DATE_FORMAT_OBJECT(dfo), locale_type ,&INTL_DATA_ERROR_CODE(dfo));
if( timezone_utf16){
efree(timezone_utf16);
}
/* Set the calendar if passed */
ucal_obj = ucal_open( timezone_utf16 , timezone_utf16_len , locale , calendar , &INTL_DATA_ERROR_CODE(dfo) );
udat_setCalendar( DATE_FORMAT_OBJECT(dfo), ucal_obj );
INTL_METHOD_CHECK_STATUS(dfo, "Error setting the calendar.");
if( timezone_utf16){
efree(timezone_utf16);
}
}
/* {{{ proto unicode IntlDateFormatter::getDateType( )
@ -72,7 +68,7 @@ PHP_FUNCTION( datefmt_get_datetype )
{
DATE_FORMAT_METHOD_INIT_VARS;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &object, IntlDateFormatter_ce_ptr ) == FAILURE )
{
intl_error_set( NULL , U_ILLEGAL_ARGUMENT_ERROR,
@ -80,7 +76,7 @@ PHP_FUNCTION( datefmt_get_datetype )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
DATE_FORMAT_METHOD_FETCH_OBJECT;
INTL_METHOD_CHECK_STATUS(dfo, "Error getting formatter datetype." );
@ -98,7 +94,7 @@ PHP_FUNCTION( datefmt_get_timetype )
{
DATE_FORMAT_METHOD_INIT_VARS;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &object, IntlDateFormatter_ce_ptr ) == FAILURE )
{
intl_error_set( NULL , U_ILLEGAL_ARGUMENT_ERROR,
@ -106,7 +102,7 @@ PHP_FUNCTION( datefmt_get_timetype )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
DATE_FORMAT_METHOD_FETCH_OBJECT;
INTL_METHOD_CHECK_STATUS(dfo, "Error getting formatter timetype." );
@ -125,7 +121,7 @@ PHP_FUNCTION( datefmt_get_calendar )
{
DATE_FORMAT_METHOD_INIT_VARS;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &object, IntlDateFormatter_ce_ptr ) == FAILURE )
{
intl_error_set( NULL , U_ILLEGAL_ARGUMENT_ERROR,
@ -133,7 +129,7 @@ PHP_FUNCTION( datefmt_get_calendar )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
DATE_FORMAT_METHOD_FETCH_OBJECT;
INTL_METHOD_CHECK_STATUS(dfo, "Error getting formatter calendar." );
@ -151,7 +147,7 @@ PHP_FUNCTION( datefmt_get_timezone_id )
{
DATE_FORMAT_METHOD_INIT_VARS;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &object, IntlDateFormatter_ce_ptr ) == FAILURE )
{
intl_error_set( NULL , U_ILLEGAL_ARGUMENT_ERROR,
@ -159,7 +155,7 @@ PHP_FUNCTION( datefmt_get_timezone_id )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
DATE_FORMAT_METHOD_FETCH_OBJECT;
INTL_METHOD_CHECK_STATUS(dfo, "Error getting formatter timezone_id." );
@ -181,23 +177,23 @@ PHP_FUNCTION( datefmt_set_timezone_id )
char* timezone_id = NULL;
int timezone_id_len = 0;
DATE_FORMAT_METHOD_INIT_VARS;
DATE_FORMAT_METHOD_INIT_VARS;
// Parse parameters.
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &object, IntlDateFormatter_ce_ptr ,&timezone_id , &timezone_id_len) == FAILURE )
{
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
"datefmt_set_timezone_id: unable to parse input params", 0 TSRMLS_CC );
RETURN_FALSE;
}
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &object, IntlDateFormatter_ce_ptr ,&timezone_id , &timezone_id_len) == FAILURE )
{
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
"datefmt_set_timezone_id: unable to parse input params", 0 TSRMLS_CC );
RETURN_FALSE;
}
// Fetch the object.
DATE_FORMAT_METHOD_FETCH_OBJECT;
/* Fetch the object. */
DATE_FORMAT_METHOD_FETCH_OBJECT;
//set the timezone for the calendar
/* set the timezone for the calendar */
internal_set_calendar( dfo , timezone_id , timezone_id_len , dfo->calendar ,return_value TSRMLS_CC );
//Set the IntlDateFormatter variable
/* Set the IntlDateFormatter variable */
if( dfo->timezone_id ){
efree(dfo->timezone_id);
}
@ -220,7 +216,7 @@ PHP_FUNCTION( datefmt_get_pattern )
DATE_FORMAT_METHOD_INIT_VARS;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &object, IntlDateFormatter_ce_ptr ) == FAILURE )
{
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
@ -228,12 +224,12 @@ PHP_FUNCTION( datefmt_get_pattern )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
DATE_FORMAT_METHOD_FETCH_OBJECT;
length = udat_toPattern(DATE_FORMAT_OBJECT(dfo), is_pattern_localized, value, length, &INTL_DATA_ERROR_CODE(dfo));
if(INTL_DATA_ERROR_CODE(dfo) == U_BUFFER_OVERFLOW_ERROR && length >= USIZE( value_buf )) {
++length; // to avoid U_STRING_NOT_TERMINATED_WARNING
++length; /* to avoid U_STRING_NOT_TERMINATED_WARNING */
INTL_DATA_ERROR_CODE(dfo) = U_ZERO_ERROR;
value = eumalloc(length);
length = udat_toPattern(DATE_FORMAT_OBJECT(dfo), is_pattern_localized , value, length, &INTL_DATA_ERROR_CODE(dfo) );
@ -264,7 +260,7 @@ PHP_FUNCTION( datefmt_set_pattern )
DATE_FORMAT_METHOD_INIT_VARS;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
&object, IntlDateFormatter_ce_ptr, &value, &value_len ) == FAILURE )
{
@ -275,7 +271,7 @@ PHP_FUNCTION( datefmt_set_pattern )
DATE_FORMAT_METHOD_FETCH_OBJECT;
// Convert given pattern to UTF-16.
/* Convert given pattern to UTF-16. */
intl_convert_utf8_to_utf16(&svalue, &slength, value, value_len, &INTL_DATA_ERROR_CODE(dfo));
INTL_METHOD_CHECK_STATUS(dfo, "Error converting pattern to UTF-16" );
@ -300,7 +296,7 @@ PHP_FUNCTION( datefmt_get_locale )
DATE_FORMAT_METHOD_INIT_VARS;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|l",
&object, IntlDateFormatter_ce_ptr ,&loc_type) == FAILURE )
{
@ -310,7 +306,7 @@ PHP_FUNCTION( datefmt_get_locale )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
DATE_FORMAT_METHOD_FETCH_OBJECT;
loc = (char *)udat_getLocaleByType(DATE_FORMAT_OBJECT(dfo), loc_type ,&INTL_DATA_ERROR_CODE(dfo));
@ -328,7 +324,7 @@ PHP_FUNCTION( datefmt_is_lenient )
DATE_FORMAT_METHOD_INIT_VARS;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
&object, IntlDateFormatter_ce_ptr ) == FAILURE )
{
@ -338,7 +334,7 @@ PHP_FUNCTION( datefmt_is_lenient )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
DATE_FORMAT_METHOD_FETCH_OBJECT;
RETVAL_BOOL(udat_isLenient(DATE_FORMAT_OBJECT(dfo)));
@ -352,25 +348,23 @@ PHP_FUNCTION( datefmt_is_lenient )
*/
PHP_FUNCTION( datefmt_set_lenient )
{
zend_bool isLenient = FALSE;
zend_bool isLenient = FALSE;
DATE_FORMAT_METHOD_INIT_VARS;
// Parse parameters.
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ob",
&object, IntlDateFormatter_ce_ptr ,&isLenient ) == FAILURE )
{
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
"datefmt_set_lenient: unable to parse input params", 0 TSRMLS_CC );
DATE_FORMAT_METHOD_INIT_VARS;
RETURN_FALSE;
}
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ob",
&object, IntlDateFormatter_ce_ptr ,&isLenient ) == FAILURE )
{
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
"datefmt_set_lenient: unable to parse input params", 0 TSRMLS_CC );
RETURN_FALSE;
}
// Fetch the object.
DATE_FORMAT_METHOD_FETCH_OBJECT;
/* Fetch the object. */
DATE_FORMAT_METHOD_FETCH_OBJECT;
udat_setLenient(DATE_FORMAT_OBJECT(dfo) , (UBool)isLenient );
udat_setLenient(DATE_FORMAT_OBJECT(dfo) , (UBool)isLenient );
}
/* }}} */
@ -383,33 +377,32 @@ PHP_FUNCTION( datefmt_set_calendar )
{
long calendar = 0;
DATE_FORMAT_METHOD_INIT_VARS;
DATE_FORMAT_METHOD_INIT_VARS;
// Parse parameters.
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol",
&object, IntlDateFormatter_ce_ptr, &calendar ) == FAILURE )
{
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"datefmt_set_calendar: unable to parse input params", 0 TSRMLS_CC);
RETURN_FALSE;
}
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol",
&object, IntlDateFormatter_ce_ptr, &calendar ) == FAILURE ) {
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"datefmt_set_calendar: unable to parse input params", 0 TSRMLS_CC);
RETURN_FALSE;
}
//check for the validity of value of calendar passed
/* check for the validity of value of calendar passed */
intl_error_reset( NULL TSRMLS_CC );
if( calendar > 1){
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"datefmt_set_calendar: calendar value specified is out of valid range", 0 TSRMLS_CC);
RETURN_FALSE;
if (calendar > 1) {
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"datefmt_set_calendar: calendar value specified is out of valid range", 0 TSRMLS_CC);
RETURN_FALSE;
}
DATE_FORMAT_METHOD_FETCH_OBJECT;
DATE_FORMAT_METHOD_FETCH_OBJECT;
internal_set_calendar( dfo , dfo->timezone_id , strlen(dfo->timezone_id) , calendar ,return_value TSRMLS_CC );
//Set the calendar value in the IntlDateFormatter object
dfo->calendar = calendar ;
/* Set the calendar value in the IntlDateFormatter object */
dfo->calendar = calendar ;
RETURN_TRUE;
RETURN_TRUE;
}
/* }}} */

102
ext/intl/dateformat/dateformat_class.c

@ -25,9 +25,9 @@
zend_class_entry *IntlDateFormatter_ce_ptr = NULL;
/////////////////////////////////////////////////////////////////////////////
// Auxiliary functions needed by objects of 'IntlDateFormatter' class
/////////////////////////////////////////////////////////////////////////////
/*
* Auxiliary functions needed by objects of 'IntlDateFormatter' class
*/
/* {{{ IntlDateFormatter_objects_dtor */
static void IntlDateFormatter_object_dtor(void *object, zend_object_handle handle TSRMLS_DC )
@ -64,7 +64,7 @@ zend_object_value IntlDateFormatter_object_create(zend_class_entry *ce TSRMLS_DC
zend_object_std_init( &intern->zo, ce TSRMLS_CC );
intern->date_type = 0;
intern->time_type = 0;
intern->calendar = 1; //Gregorian calendar
intern->calendar = 1; /* Gregorian calendar */
intern->timezone_id = NULL;
retval.handle = zend_objects_store_put(
@ -79,37 +79,79 @@ zend_object_value IntlDateFormatter_object_create(zend_class_entry *ce TSRMLS_DC
}
/* }}} */
/////////////////////////////////////////////////////////////////////////////
// 'IntlDateFormatter' class registration structures & functions
/////////////////////////////////////////////////////////////////////////////
/*
* 'IntlDateFormatter' class registration structures & functions
*/
/* {{{ arginfo */
static ZEND_BEGIN_ARG_INFO_EX(datefmt_parse_args, 0, 0, 1)
ZEND_ARG_INFO(0, string)
ZEND_ARG_INFO(1, position)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_intldateformatter_format, 0, 0, 0)
ZEND_ARG_INFO(0, args)
ZEND_ARG_INFO(0, array)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO(arginfo_intldateformatter_getdatetype, 0)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_intldateformatter_settimezoneid, 0, 0, 1)
ZEND_ARG_INFO(0, zone)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_intldateformatter_setpattern, 0, 0, 1)
ZEND_ARG_INFO(0, pattern)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_intldateformatter_setlenient, 0, 0, 1)
ZEND_ARG_INFO(0, lenient)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_intldateformatter_setcalendar, 0, 0, 1)
ZEND_ARG_INFO(0, which)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_intldateformatter___construct, 0, 0, 3)
ZEND_ARG_INFO(0, locale)
ZEND_ARG_INFO(0, datetype)
ZEND_ARG_INFO(0, timetype)
ZEND_ARG_INFO(0, timezone)
ZEND_ARG_INFO(0, calendar)
ZEND_ARG_INFO(0, pattern)
ZEND_END_ARG_INFO()
/* }}} */
/* {{{ IntlDateFormatter_class_functions
* Every 'IntlDateFormatter' class method has an entry in this table
*/
static ZEND_BEGIN_ARG_INFO_EX( datefmt_parse_args, 0, 0, 1 )
ZEND_ARG_INFO( 0, string )
ZEND_ARG_INFO( 1, position )
ZEND_END_ARG_INFO()
static function_entry IntlDateFormatter_class_functions[] = {
PHP_ME( IntlDateFormatter, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR )
ZEND_FENTRY( create, ZEND_FN( datefmt_create ), NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
PHP_NAMED_FE( getDateType, ZEND_FN( datefmt_get_datetype ), NULL )
PHP_NAMED_FE( getTimeType, ZEND_FN( datefmt_get_timetype ), NULL )
PHP_NAMED_FE( getCalendar, ZEND_FN( datefmt_get_calendar ), NULL )
PHP_NAMED_FE( setCalendar, ZEND_FN( datefmt_set_calendar ), NULL )
PHP_NAMED_FE( getTimeZoneId, ZEND_FN( datefmt_get_timezone_id ), NULL )
PHP_NAMED_FE( setTimeZoneId, ZEND_FN( datefmt_set_timezone_id ), NULL )
PHP_NAMED_FE( setPattern, ZEND_FN( datefmt_set_pattern ), NULL )
PHP_NAMED_FE( getPattern, ZEND_FN( datefmt_get_pattern ), NULL )
PHP_NAMED_FE( getLocale, ZEND_FN( datefmt_get_locale ), NULL )
PHP_NAMED_FE( setLenient, ZEND_FN( datefmt_set_lenient ), NULL )
PHP_NAMED_FE( isLenient, ZEND_FN( datefmt_is_lenient ), NULL )
PHP_NAMED_FE( format, ZEND_FN( datefmt_format ), NULL )
PHP_ME( IntlDateFormatter, __construct, arginfo_intldateformatter___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR )
ZEND_FENTRY( create, ZEND_FN( datefmt_create ), arginfo_intldateformatter___construct, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
PHP_NAMED_FE( getDateType, ZEND_FN( datefmt_get_datetype ), arginfo_intldateformatter_getdatetype )
PHP_NAMED_FE( getTimeType, ZEND_FN( datefmt_get_timetype ), arginfo_intldateformatter_getdatetype )
PHP_NAMED_FE( getCalendar, ZEND_FN( datefmt_get_calendar ), arginfo_intldateformatter_getdatetype )
PHP_NAMED_FE( setCalendar, ZEND_FN( datefmt_set_calendar ), arginfo_intldateformatter_setcalendar )
PHP_NAMED_FE( getTimeZoneId, ZEND_FN( datefmt_get_timezone_id ), arginfo_intldateformatter_getdatetype )
PHP_NAMED_FE( setTimeZoneId, ZEND_FN( datefmt_set_timezone_id ), arginfo_intldateformatter_settimezoneid )
PHP_NAMED_FE( setPattern, ZEND_FN( datefmt_set_pattern ), arginfo_intldateformatter_setpattern )
PHP_NAMED_FE( getPattern, ZEND_FN( datefmt_get_pattern ), arginfo_intldateformatter_getdatetype )
PHP_NAMED_FE( getLocale, ZEND_FN( datefmt_get_locale ), arginfo_intldateformatter_getdatetype )
PHP_NAMED_FE( setLenient, ZEND_FN( datefmt_set_lenient ), arginfo_intldateformatter_setlenient )
PHP_NAMED_FE( isLenient, ZEND_FN( datefmt_is_lenient ), arginfo_intldateformatter_getdatetype )
PHP_NAMED_FE( format, ZEND_FN( datefmt_format ), arginfo_intldateformatter_format )
PHP_NAMED_FE( parse, ZEND_FN( datefmt_parse), datefmt_parse_args )
PHP_NAMED_FE( localtime, ZEND_FN( datefmt_localtime ), datefmt_parse_args )
PHP_NAMED_FE( getErrorCode, ZEND_FN( datefmt_get_error_code ), NULL )
PHP_NAMED_FE( getErrorMessage, ZEND_FN( datefmt_get_error_message ), NULL )
PHP_NAMED_FE( getErrorCode, ZEND_FN( datefmt_get_error_code ), arginfo_intldateformatter_getdatetype )
PHP_NAMED_FE( getErrorMessage, ZEND_FN( datefmt_get_error_message ), arginfo_intldateformatter_getdatetype )
{ NULL, NULL, NULL }
};
/* }}} */
@ -121,12 +163,12 @@ void dateformat_register_IntlDateFormatter_class( TSRMLS_D )
{
zend_class_entry ce;
// Create and register 'IntlDateFormatter' class.
/* Create and register 'IntlDateFormatter' class. */
INIT_CLASS_ENTRY( ce, "IntlDateFormatter", IntlDateFormatter_class_functions );
ce.create_object = IntlDateFormatter_object_create;
IntlDateFormatter_ce_ptr = zend_register_internal_class( &ce TSRMLS_CC );
// Declare 'IntlDateFormatter' class properties.
/* Declare 'IntlDateFormatter' class properties. */
if( !IntlDateFormatter_ce_ptr )
{
zend_error(E_ERROR, "Failed to register IntlDateFormatter class");

39
ext/intl/dateformat/dateformat_format.c

@ -69,7 +69,7 @@ static double internal_get_arr_ele(IntlDateFormatter_object *dfo , HashTable* h
result = Z_LVAL_PP(ele_value);
}
}
//printf("\n Inside internal_get_arr_ele key_name= %s , result = %g \n" , key_name, result);
/* printf("\n Inside internal_get_arr_ele key_name= %s , result = %g \n" , key_name, result); */
return result;
}
/* }}} */
@ -88,9 +88,9 @@ static void internal_create_ucal(IntlDateFormatter_object *dfo, HashTable* hash_
long mday =0;
UBool isInDST = FALSE;
//Fetch values from the incoming array
year = internal_get_arr_ele( dfo , hash_arr , CALENDAR_YEAR TSRMLS_CC) + 1900; //tm_year is years since 1900
//Month in ICU and PHP starts from January =0
/* Fetch values from the incoming array */
year = internal_get_arr_ele( dfo , hash_arr , CALENDAR_YEAR TSRMLS_CC) + 1900; /* tm_year is years since 1900 */
/* Month in ICU and PHP starts from January =0 */
month = internal_get_arr_ele( dfo , hash_arr , CALENDAR_MON TSRMLS_CC);
hour = internal_get_arr_ele( dfo , hash_arr , CALENDAR_HOUR TSRMLS_CC);
minute = internal_get_arr_ele( dfo , hash_arr , CALENDAR_MIN TSRMLS_CC);
@ -98,20 +98,20 @@ static void internal_create_ucal(IntlDateFormatter_object *dfo, HashTable* hash_
wday = internal_get_arr_ele( dfo , hash_arr , CALENDAR_WDAY TSRMLS_CC);
yday = internal_get_arr_ele( dfo , hash_arr , CALENDAR_YDAY TSRMLS_CC);
isInDST = internal_get_arr_ele( dfo , hash_arr , CALENDAR_ISDST TSRMLS_CC);
//For the ucal_setDateTime() function , this is the 'date' value
/* For the ucal_setDateTime() function , this is the 'date' value */
mday = internal_get_arr_ele( dfo , hash_arr , CALENDAR_MDAY TSRMLS_CC);
//set the incoming values for the calendar
/* set the incoming values for the calendar */
ucal_setDateTime( pcal, year, month , mday , hour , minute , second , &INTL_DATA_ERROR_CODE(dfo));
if( INTL_DATA_ERROR_CODE(dfo) != U_ZERO_ERROR){
return;
}
//ICU UCAL_DAY_OF_WEEK starts from SUNDAY=1 thru SATURDAY=7
//whereas PHP localtime has tm_wday SUNDAY=0 thru SATURDAY=6
/* ICU UCAL_DAY_OF_WEEK starts from SUNDAY=1 thru SATURDAY=7
* whereas PHP localtime has tm_wday SUNDAY=0 thru SATURDAY=6 */
ucal_set( pcal, UCAL_DAY_OF_WEEK , (wday+1));
ucal_set( pcal, UCAL_DAY_OF_YEAR , yday);
//TO DO :How to set the isInDST field?Is it required to set
/* TO DO: How to set the isInDST field?Is it required to set */
}
@ -129,26 +129,23 @@ PHP_FUNCTION(datefmt_format)
DATE_FORMAT_METHOD_INIT_VARS;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oz", &object, IntlDateFormatter_ce_ptr ,&zarg ) == FAILURE )
{
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
"datefmt_format: unable to parse input params", 0 TSRMLS_CC );
RETURN_FALSE;
}
{
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_format: unable to parse input params", 0 TSRMLS_CC );
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
DATE_FORMAT_METHOD_FETCH_OBJECT;
switch(Z_TYPE_P(zarg) ){
case IS_LONG:
p_timestamp = Z_LVAL_P(zarg) ;
timestamp = p_timestamp * 1000;
break;
case IS_DOUBLE:
//timestamp*1000 since ICU expects it in milliseconds
/* timestamp*1000 since ICU expects it in milliseconds */
p_timestamp = Z_DVAL_P(zarg) ;
timestamp = p_timestamp * 1000;
break;
@ -156,13 +153,13 @@ PHP_FUNCTION(datefmt_format)
hash_arr = Z_ARRVAL_P(zarg);
if( !hash_arr || zend_hash_num_elements( hash_arr ) == 0 )
RETURN_FALSE;
//Create a UCalendar object from the array and then format it
/* Create a UCalendar object from the array and then format it */
temp_cal = ucal_open(NULL, -1, NULL, UCAL_GREGORIAN, &INTL_DATA_ERROR_CODE(dfo));
ucal_clear(temp_cal);
INTL_METHOD_CHECK_STATUS( dfo, "datefmt_format: Date formatting failed while creating calendar from the array" )
internal_create_ucal( dfo , hash_arr , temp_cal TSRMLS_CC);
INTL_METHOD_CHECK_STATUS( dfo, "datefmt_format: Date formatting failed while creating calendar from the array" )
//Fetch the timestamp from the created UCalendar
/* Fetch the timestamp from the created UCalendar */
timestamp = ucal_getMillis(temp_cal , &INTL_DATA_ERROR_CODE(dfo) );
INTL_METHOD_CHECK_STATUS( dfo, "datefmt_format: Date formatting failed" )
break;

98
ext/intl/dateformat/dateformat_parse.c

@ -39,9 +39,9 @@ static void internal_parse_to_timestamp(IntlDateFormatter_object *dfo, char* tex
UChar* text_utf16 = NULL;
int32_t text_utf16_len = 0;
// Convert timezone to UTF-16.
intl_convert_utf8_to_utf16(&text_utf16 , &text_utf16_len , text_to_parse , text_len, &INTL_DATA_ERROR_CODE(dfo));
INTL_METHOD_CHECK_STATUS(dfo, "Error converting timezone to UTF-16" );
/* Convert timezone to UTF-16. */
intl_convert_utf8_to_utf16(&text_utf16 , &text_utf16_len , text_to_parse , text_len, &INTL_DATA_ERROR_CODE(dfo));
INTL_METHOD_CHECK_STATUS(dfo, "Error converting timezone to UTF-16" );
timestamp = udat_parse( DATE_FORMAT_OBJECT(dfo), text_utf16 , text_utf16_len , parse_pos , &INTL_DATA_ERROR_CODE(dfo));
if( text_utf16 ){
@ -50,7 +50,7 @@ static void internal_parse_to_timestamp(IntlDateFormatter_object *dfo, char* tex
INTL_METHOD_CHECK_STATUS( dfo, "Date parsing failed" );
//Since return is in sec.
/* Since return is in sec. */
result = (long )( timestamp / 1000 );
if( result != (timestamp/1000) ) {
intl_error_set( NULL, U_BUFFER_OVERFLOW_ERROR,
@ -65,10 +65,10 @@ static void add_to_localtime_arr( IntlDateFormatter_object *dfo, zval* return_va
INTL_METHOD_CHECK_STATUS( dfo, "Date parsing - localtime failed : could not get a field from calendar" );
if( strcmp(key_name , CALENDAR_YEAR )==0 ){
//since tm_year is years from 1900
/* since tm_year is years from 1900 */
add_assoc_long( return_value, key_name ,( calendar_field_val-1900) );
}else if( strcmp(key_name , CALENDAR_WDAY )==0 ){
//since tm_wday starts from 0 whereas ICU WDAY start from 1
/* since tm_wday starts from 0 whereas ICU WDAY start from 1 */
add_assoc_long( return_value, key_name ,( calendar_field_val-1) );
}else{
add_assoc_long( return_value, key_name , calendar_field_val );
@ -79,26 +79,27 @@ static void add_to_localtime_arr( IntlDateFormatter_object *dfo, zval* return_va
* Internal function which calls the udat_parseCalendar
*/
static void internal_parse_to_localtime(IntlDateFormatter_object *dfo, char* text_to_parse , int32_t text_len, int32_t *parse_pos , zval *return_value TSRMLS_DC){
UCalendar* parsed_calendar = NULL ;
UChar* text_utf16 = NULL;
int32_t text_utf16_len = 0;
UCalendar* parsed_calendar = NULL;
UChar* text_utf16 = NULL;
int32_t text_utf16_len = 0;
long isInDST = 0;
// Convert timezone to UTF-16.
intl_convert_utf8_to_utf16(&text_utf16 , &text_utf16_len , text_to_parse , text_len, &INTL_DATA_ERROR_CODE(dfo));
INTL_METHOD_CHECK_STATUS(dfo, "Error converting timezone to UTF-16" );
/* Convert timezone to UTF-16. */
intl_convert_utf8_to_utf16(&text_utf16 , &text_utf16_len , text_to_parse , text_len, &INTL_DATA_ERROR_CODE(dfo));
INTL_METHOD_CHECK_STATUS(dfo, "Error converting timezone to UTF-16" );
parsed_calendar = ucal_open(NULL, -1, NULL, UCAL_GREGORIAN, &INTL_DATA_ERROR_CODE(dfo));
udat_parseCalendar( DATE_FORMAT_OBJECT(dfo), parsed_calendar , text_utf16 , text_utf16_len , parse_pos , &INTL_DATA_ERROR_CODE(dfo));
if( text_utf16 ){
efree(text_utf16);
}
udat_parseCalendar( DATE_FORMAT_OBJECT(dfo), parsed_calendar , text_utf16 , text_utf16_len , parse_pos , &INTL_DATA_ERROR_CODE(dfo));
if (text_utf16) {
efree(text_utf16);
}
INTL_METHOD_CHECK_STATUS( dfo, "Date parsing failed" );
INTL_METHOD_CHECK_STATUS( dfo, "Date parsing failed" );
array_init( return_value );
//Add entries from various fields of the obtained parsed_calendar
/* Add entries from various fields of the obtained parsed_calendar */
add_to_localtime_arr( dfo , return_value , parsed_calendar , UCAL_SECOND , CALENDAR_SEC TSRMLS_CC);
add_to_localtime_arr( dfo , return_value , parsed_calendar , UCAL_MINUTE , CALENDAR_MIN TSRMLS_CC);
add_to_localtime_arr( dfo , return_value , parsed_calendar , UCAL_HOUR_OF_DAY , CALENDAR_HOUR TSRMLS_CC);
@ -108,9 +109,9 @@ static void internal_parse_to_localtime(IntlDateFormatter_object *dfo, char* tex
add_to_localtime_arr( dfo , return_value , parsed_calendar , UCAL_DAY_OF_YEAR , CALENDAR_YDAY TSRMLS_CC);
add_to_localtime_arr( dfo , return_value , parsed_calendar , UCAL_MONTH , CALENDAR_MON TSRMLS_CC);
//Is in DST?
/* Is in DST? */
isInDST = ucal_inDaylightTime(parsed_calendar , &INTL_DATA_ERROR_CODE(dfo));
INTL_METHOD_CHECK_STATUS( dfo, "Date parsing - localtime failed : while checking if currently in DST." );
INTL_METHOD_CHECK_STATUS( dfo, "Date parsing - localtime failed : while checking if currently in DST." );
add_assoc_long( return_value, CALENDAR_ISDST ,(isInDST==1?1:0));
}
/* }}} */
@ -122,26 +123,24 @@ 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)
{
char* text_to_parse = NULL;
int32_t text_len =0;
zval* z_parse_pos = NULL;
int32_t parse_pos = -1;
char* text_to_parse = NULL;
int32_t text_len =0;
zval* z_parse_pos = NULL;
int32_t parse_pos = -1;
DATE_FORMAT_METHOD_INIT_VARS;
DATE_FORMAT_METHOD_INIT_VARS;
// Parse parameters.
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|z!",
&object, IntlDateFormatter_ce_ptr, &text_to_parse , &text_len , &z_parse_pos ) == FAILURE ){
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
"datefmt_parse: unable to parse input params", 0 TSRMLS_CC );
RETURN_FALSE;
}
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|z!",
&object, IntlDateFormatter_ce_ptr, &text_to_parse , &text_len , &z_parse_pos ) == FAILURE ){
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_parse: unable to parse input params", 0 TSRMLS_CC );
RETURN_FALSE;
}
// Fetch the object.
DATE_FORMAT_METHOD_FETCH_OBJECT;
/* Fetch the object. */
DATE_FORMAT_METHOD_FETCH_OBJECT;
if(z_parse_pos) {
if (z_parse_pos) {
convert_to_long(z_parse_pos);
parse_pos = (int32_t)Z_LVAL_P(z_parse_pos);
if(parse_pos > text_len) {
@ -162,25 +161,22 @@ PHP_FUNCTION(datefmt_parse)
* Parse the string $value to a localtime array }}}*/
PHP_FUNCTION(datefmt_localtime)
{
char* text_to_parse = NULL;
int32_t text_len =0;
zval* z_parse_pos = NULL;
int32_t parse_pos = -1;
char* text_to_parse = NULL;
int32_t text_len =0;
zval* z_parse_pos = NULL;
int32_t parse_pos = -1;
DATE_FORMAT_METHOD_INIT_VARS;
DATE_FORMAT_METHOD_INIT_VARS;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|z!",
&object, IntlDateFormatter_ce_ptr, &text_to_parse , &text_len , &z_parse_pos ) == FAILURE ){
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
"datefmt_parse_to_localtime: unable to parse input params", 0 TSRMLS_CC );
RETURN_FALSE;
}
&object, IntlDateFormatter_ce_ptr, &text_to_parse , &text_len , &z_parse_pos ) == FAILURE ){
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_parse_to_localtime: unable to parse input params", 0 TSRMLS_CC );
RETURN_FALSE;
}
// Fetch the object.
DATE_FORMAT_METHOD_FETCH_OBJECT;
/* Fetch the object. */
DATE_FORMAT_METHOD_FETCH_OBJECT;
if(z_parse_pos) {
convert_to_long(z_parse_pos);

12
ext/intl/formatter/formatter.c

@ -44,7 +44,7 @@ void formatter_register_constants( INIT_FUNC_ARGS )
#define FORMATTER_EXPOSE_CLASS_CONST(x) zend_declare_class_constant_long( NumberFormatter_ce_ptr, ZEND_STRS( #x ) - 1, UNUM_##x TSRMLS_CC );
#define FORMATTER_EXPOSE_CUSTOM_CLASS_CONST(name, value) zend_declare_class_constant_long( NumberFormatter_ce_ptr, ZEND_STRS( name ) - 1, value TSRMLS_CC );
// UNumberFormatStyle constants
/* UNumberFormatStyle constants */
FORMATTER_EXPOSE_CLASS_CONST( PATTERN_DECIMAL );
FORMATTER_EXPOSE_CLASS_CONST( DECIMAL );
FORMATTER_EXPOSE_CLASS_CONST( CURRENCY );
@ -63,7 +63,7 @@ void formatter_register_constants( INIT_FUNC_ARGS )
#define UNUM_ROUND_HALFEVEN UNUM_FOUND_HALFEVEN
#endif
// UNumberFormatRoundingMode
/* UNumberFormatRoundingMode */
FORMATTER_EXPOSE_CLASS_CONST( ROUND_CEILING );
FORMATTER_EXPOSE_CLASS_CONST( ROUND_FLOOR );
FORMATTER_EXPOSE_CLASS_CONST( ROUND_DOWN );
@ -72,13 +72,13 @@ void formatter_register_constants( INIT_FUNC_ARGS )
FORMATTER_EXPOSE_CLASS_CONST( ROUND_HALFDOWN );
FORMATTER_EXPOSE_CLASS_CONST( ROUND_HALFUP );
// UNumberFormatPadPosition
/* UNumberFormatPadPosition */
FORMATTER_EXPOSE_CLASS_CONST( PAD_BEFORE_PREFIX );
FORMATTER_EXPOSE_CLASS_CONST( PAD_AFTER_PREFIX );
FORMATTER_EXPOSE_CLASS_CONST( PAD_BEFORE_SUFFIX );
FORMATTER_EXPOSE_CLASS_CONST( PAD_AFTER_SUFFIX );
// UNumberFormatAttribute
/* UNumberFormatAttribute */
FORMATTER_EXPOSE_CLASS_CONST( PARSE_INT_ONLY );
FORMATTER_EXPOSE_CLASS_CONST( GROUPING_USED );
FORMATTER_EXPOSE_CLASS_CONST( DECIMAL_ALWAYS_SHOWN );
@ -100,7 +100,7 @@ void formatter_register_constants( INIT_FUNC_ARGS )
FORMATTER_EXPOSE_CLASS_CONST( MAX_SIGNIFICANT_DIGITS );
FORMATTER_EXPOSE_CLASS_CONST( LENIENT_PARSE );
// UNumberFormatTextAttribute
/* UNumberFormatTextAttribute */
FORMATTER_EXPOSE_CLASS_CONST( POSITIVE_PREFIX );
FORMATTER_EXPOSE_CLASS_CONST( POSITIVE_SUFFIX );
FORMATTER_EXPOSE_CLASS_CONST( NEGATIVE_PREFIX );
@ -110,7 +110,7 @@ void formatter_register_constants( INIT_FUNC_ARGS )
FORMATTER_EXPOSE_CLASS_CONST( DEFAULT_RULESET );
FORMATTER_EXPOSE_CLASS_CONST( PUBLIC_RULESETS );
// UNumberFormatSymbol
/* UNumberFormatSymbol */
FORMATTER_EXPOSE_CLASS_CONST( DECIMAL_SEPARATOR_SYMBOL );
FORMATTER_EXPOSE_CLASS_CONST( GROUPING_SEPARATOR_SYMBOL );
FORMATTER_EXPOSE_CLASS_CONST( PATTERN_SEPARATOR_SYMBOL );

52
ext/intl/formatter/formatter_attr.c

@ -35,7 +35,7 @@ PHP_FUNCTION( numfmt_get_attribute )
long attribute, value;
FORMATTER_METHOD_INIT_VARS;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol",
&object, NumberFormatter_ce_ptr, &attribute ) == FAILURE )
{
@ -45,7 +45,7 @@ PHP_FUNCTION( numfmt_get_attribute )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
FORMATTER_METHOD_FETCH_OBJECT;
switch(attribute) {
@ -108,7 +108,7 @@ PHP_FUNCTION( numfmt_get_text_attribute )
int length = 0;
FORMATTER_METHOD_INIT_VARS;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol",
&object, NumberFormatter_ce_ptr, &attribute ) == FAILURE )
{
@ -118,12 +118,12 @@ PHP_FUNCTION( numfmt_get_text_attribute )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
FORMATTER_METHOD_FETCH_OBJECT;
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
++length; /* to avoid U_STRING_NOT_TERMINATED_WARNING */
INTL_DATA_ERROR_CODE(nfo) = U_ZERO_ERROR;
value = eumalloc(length);
length = unum_getTextAttribute( FORMATTER_OBJECT(nfo), attribute, value, length, &INTL_DATA_ERROR_CODE(nfo) );
@ -149,7 +149,7 @@ PHP_FUNCTION( numfmt_set_attribute )
zval **value;
FORMATTER_METHOD_INIT_VARS;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OlZ",
&object, NumberFormatter_ce_ptr, &attribute, &value ) == FAILURE)
{
@ -159,7 +159,7 @@ PHP_FUNCTION( numfmt_set_attribute )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
FORMATTER_METHOD_FETCH_OBJECT;
switch(attribute) {
@ -214,7 +214,7 @@ PHP_FUNCTION( numfmt_set_text_attribute )
int len;
FORMATTER_METHOD_INIT_VARS;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ols",
&object, NumberFormatter_ce_ptr, &attribute, &value, &len ) == FAILURE)
{
@ -224,14 +224,14 @@ PHP_FUNCTION( numfmt_set_text_attribute )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
FORMATTER_METHOD_FETCH_OBJECT;
// Convert given attribute value to UTF-16.
/* Convert given attribute value to UTF-16. */
intl_convert_utf8_to_utf16(&svalue, &slength, value, len, &INTL_DATA_ERROR_CODE(nfo));
INTL_METHOD_CHECK_STATUS( nfo, "Error converting attribute value to UTF-16" );
// Actually set new attribute value.
/* Actually set new attribute value. */
unum_setTextAttribute(FORMATTER_OBJECT(nfo), attribute, svalue, slength, &INTL_DATA_ERROR_CODE(nfo));
efree(svalue);
INTL_METHOD_CHECK_STATUS( nfo, "Error setting text attribute" );
@ -253,7 +253,7 @@ PHP_FUNCTION( numfmt_get_symbol )
int length = USIZE(value);
FORMATTER_METHOD_INIT_VARS;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol",
&object, NumberFormatter_ce_ptr, &symbol ) == FAILURE )
{
@ -263,12 +263,12 @@ PHP_FUNCTION( numfmt_get_symbol )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
FORMATTER_METHOD_FETCH_OBJECT;
length = unum_getSymbol(FORMATTER_OBJECT(nfo), symbol, value_buf, length, &INTL_DATA_ERROR_CODE(nfo));
if(INTL_DATA_ERROR_CODE(nfo) == U_BUFFER_OVERFLOW_ERROR && length >= USIZE( value )) {
++length; // to avoid U_STRING_NOT_TERMINATED_WARNING
++length; /* to avoid U_STRING_NOT_TERMINATED_WARNING */
INTL_DATA_ERROR_CODE(nfo) = U_ZERO_ERROR;
value = eumalloc(length);
length = unum_getSymbol(FORMATTER_OBJECT(nfo), symbol, value, length, &INTL_DATA_ERROR_CODE(nfo));
@ -297,7 +297,7 @@ PHP_FUNCTION( numfmt_set_symbol )
int slength = 0;
FORMATTER_METHOD_INIT_VARS;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ols",
&object, NumberFormatter_ce_ptr, &symbol, &value, &value_len ) == FAILURE )
{
@ -307,14 +307,14 @@ PHP_FUNCTION( numfmt_set_symbol )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
FORMATTER_METHOD_FETCH_OBJECT;
// Convert given symbol to UTF-16.
/* Convert given symbol to UTF-16. */
intl_convert_utf8_to_utf16(&svalue, &slength, value, value_len, &INTL_DATA_ERROR_CODE(nfo));
INTL_METHOD_CHECK_STATUS( nfo, "Error converting symbol value to UTF-16" );
// Actually set the symbol.
/* Actually set the symbol. */
unum_setSymbol(FORMATTER_OBJECT(nfo), symbol, svalue, slength, &INTL_DATA_ERROR_CODE(nfo));
efree(svalue);
INTL_METHOD_CHECK_STATUS( nfo, "Error setting symbol value" );
@ -335,7 +335,7 @@ PHP_FUNCTION( numfmt_get_pattern )
UChar* value = value_buf;
FORMATTER_METHOD_INIT_VARS;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
&object, NumberFormatter_ce_ptr ) == FAILURE )
{
@ -345,12 +345,12 @@ PHP_FUNCTION( numfmt_get_pattern )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
FORMATTER_METHOD_FETCH_OBJECT;
length = unum_toPattern(FORMATTER_OBJECT(nfo), 0, value, length, &INTL_DATA_ERROR_CODE(nfo));
if(INTL_DATA_ERROR_CODE(nfo) == U_BUFFER_OVERFLOW_ERROR && length >= USIZE( value_buf )) {
++length; // to avoid U_STRING_NOT_TERMINATED_WARNING
++length; /* to avoid U_STRING_NOT_TERMINATED_WARNING */
INTL_DATA_ERROR_CODE(nfo) = U_ZERO_ERROR;
value = eumalloc(length);
length = unum_toPattern( FORMATTER_OBJECT(nfo), 0, value, length, &INTL_DATA_ERROR_CODE(nfo) );
@ -378,7 +378,7 @@ PHP_FUNCTION( numfmt_set_pattern )
UChar* svalue = NULL;
FORMATTER_METHOD_INIT_VARS;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
&object, NumberFormatter_ce_ptr, &value, &value_len ) == FAILURE )
{
@ -390,11 +390,11 @@ PHP_FUNCTION( numfmt_set_pattern )
FORMATTER_METHOD_FETCH_OBJECT;
// Convert given pattern to UTF-16.
/* Convert given pattern to UTF-16. */
intl_convert_utf8_to_utf16(&svalue, &slength, value, value_len, &INTL_DATA_ERROR_CODE(nfo));
INTL_METHOD_CHECK_STATUS( nfo, "Error converting pattern to UTF-16" );
// TODO: add parse error information
/* TODO: add parse error information */
unum_applyPattern(FORMATTER_OBJECT(nfo), 0, svalue, slength, NULL, &INTL_DATA_ERROR_CODE(nfo));
efree(svalue);
INTL_METHOD_CHECK_STATUS( nfo, "Error setting pattern value" );
@ -414,7 +414,7 @@ PHP_FUNCTION( numfmt_get_locale )
char* loc;
FORMATTER_METHOD_INIT_VARS;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|l",
&object, NumberFormatter_ce_ptr, &type ) == FAILURE )
{
@ -424,7 +424,7 @@ PHP_FUNCTION( numfmt_get_locale )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
FORMATTER_METHOD_FETCH_OBJECT;
loc = (char *)unum_getLocaleByType(FORMATTER_OBJECT(nfo), type, &INTL_DATA_ERROR_CODE(nfo));

120
ext/intl/formatter/formatter_class.c

@ -26,9 +26,9 @@
zend_class_entry *NumberFormatter_ce_ptr = NULL;
/////////////////////////////////////////////////////////////////////////////
// Auxiliary functions needed by objects of 'NumberFormatter' class
/////////////////////////////////////////////////////////////////////////////
/*
* Auxiliary functions needed by objects of 'NumberFormatter' class
*/
/* {{{ NumberFormatter_objects_dtor */
static void NumberFormatter_object_dtor(
@ -75,43 +75,95 @@ zend_object_value NumberFormatter_object_create(
}
/* }}} */
/////////////////////////////////////////////////////////////////////////////
// 'NumberFormatter' class registration structures & functions
/////////////////////////////////////////////////////////////////////////////
/* {{{ NumberFormatter_class_functions
* Every 'NumberFormatter' class method has an entry in this table
/*
* 'NumberFormatter' class registration structures & functions
*/
static ZEND_BEGIN_ARG_INFO_EX( number_parse_arginfo, 0, 0, 1 )
ZEND_ARG_INFO( 0, string )
ZEND_ARG_INFO( 0, type )
ZEND_ARG_INFO( 1, position )
/* {{{ arginfo */
static ZEND_BEGIN_ARG_INFO_EX(number_parse_arginfo, 0, 0, 1)
ZEND_ARG_INFO(0, string)
ZEND_ARG_INFO(0, type)
ZEND_ARG_INFO(1, position)
ZEND_END_ARG_INFO()
static ZEND_BEGIN_ARG_INFO_EX(number_parse_currency_arginfo, 0, 0, 2)
ZEND_ARG_INFO(0, string)
ZEND_ARG_INFO(1, currency)
ZEND_ARG_INFO(1, position)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_numberformatter_getattribute, 0, 0, 1)
ZEND_ARG_INFO(0, attr)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_numberformatter_setattribute, 0, 0, 2)
ZEND_ARG_INFO(0, attr)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_numberformatter_setsymbol, 0, 0, 2)
ZEND_ARG_INFO(0, attr)
ZEND_ARG_INFO(0, symbol)
ZEND_END_ARG_INFO()
static ZEND_BEGIN_ARG_INFO_EX( number_parse_currency_arginfo, 0, 0, 2 )
ZEND_ARG_INFO( 0, string )
ZEND_ARG_INFO( 1, currency )
ZEND_ARG_INFO( 1, position )
static
ZEND_BEGIN_ARG_INFO(arginfo_numberformatter_getpattern, 0)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_numberformatter_setpattern, 0, 0, 1)
ZEND_ARG_INFO(0, pattern)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_numberformatter_getlocale, 0, 0, 0)
ZEND_ARG_INFO(0, type)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_numberformatter___construct, 0, 0, 2)
ZEND_ARG_INFO(0, locale)
ZEND_ARG_INFO(0, style)
ZEND_ARG_INFO(0, pattern)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_numberformatter_formatcurrency, 0, 0, 2)
ZEND_ARG_INFO(0, num)
ZEND_ARG_INFO(0, currency)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_numberformatter_format, 0, 0, 1)
ZEND_ARG_INFO(0, num)
ZEND_ARG_INFO(0, type)
ZEND_END_ARG_INFO()
/* }}} */
/* {{{ NumberFormatter_class_functions
* Every 'NumberFormatter' class method has an entry in this table
*/
static function_entry NumberFormatter_class_functions[] = {
PHP_ME( NumberFormatter, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR )
ZEND_FENTRY( create, ZEND_FN( numfmt_create ), NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
PHP_NAMED_FE( format, ZEND_FN( numfmt_format ), NULL )
PHP_ME( NumberFormatter, __construct, arginfo_numberformatter___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR )
ZEND_FENTRY( create, ZEND_FN( numfmt_create ), arginfo_numberformatter___construct, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
PHP_NAMED_FE( format, ZEND_FN( numfmt_format ), arginfo_numberformatter_format )
PHP_NAMED_FE( parse, ZEND_FN( numfmt_parse ), number_parse_arginfo )
PHP_NAMED_FE( formatCurrency, ZEND_FN( numfmt_format_currency ), NULL )
PHP_NAMED_FE( formatCurrency, ZEND_FN( numfmt_format_currency ), arginfo_numberformatter_formatcurrency )
PHP_NAMED_FE( parseCurrency, ZEND_FN( numfmt_parse_currency ), number_parse_currency_arginfo )
PHP_NAMED_FE( setAttribute, ZEND_FN( numfmt_set_attribute ), NULL )
PHP_NAMED_FE( getAttribute, ZEND_FN( numfmt_get_attribute ), NULL )
PHP_NAMED_FE( setTextAttribute, ZEND_FN( numfmt_set_text_attribute ), NULL )
PHP_NAMED_FE( getTextAttribute, ZEND_FN( numfmt_get_text_attribute ), NULL )
PHP_NAMED_FE( setSymbol, ZEND_FN( numfmt_set_symbol ), NULL )
PHP_NAMED_FE( getSymbol, ZEND_FN( numfmt_get_symbol ), NULL )
PHP_NAMED_FE( setPattern, ZEND_FN( numfmt_set_pattern ), NULL )
PHP_NAMED_FE( getPattern, ZEND_FN( numfmt_get_pattern ), NULL )
PHP_NAMED_FE( getLocale, ZEND_FN( numfmt_get_locale ), NULL )
PHP_NAMED_FE( getErrorCode, ZEND_FN( numfmt_get_error_code ), NULL )
PHP_NAMED_FE( getErrorMessage, ZEND_FN( numfmt_get_error_message ), NULL )
PHP_NAMED_FE( setAttribute, ZEND_FN( numfmt_set_attribute ), arginfo_numberformatter_setattribute )
PHP_NAMED_FE( getAttribute, ZEND_FN( numfmt_get_attribute ), arginfo_numberformatter_getattribute )
PHP_NAMED_FE( setTextAttribute, ZEND_FN( numfmt_set_text_attribute ), arginfo_numberformatter_setattribute )
PHP_NAMED_FE( getTextAttribute, ZEND_FN( numfmt_get_text_attribute ), arginfo_numberformatter_getattribute )
PHP_NAMED_FE( setSymbol, ZEND_FN( numfmt_set_symbol ), arginfo_numberformatter_setsymbol )
PHP_NAMED_FE( getSymbol, ZEND_FN( numfmt_get_symbol ), arginfo_numberformatter_getattribute )
PHP_NAMED_FE( setPattern, ZEND_FN( numfmt_set_pattern ), arginfo_numberformatter_setpattern )
PHP_NAMED_FE( getPattern, ZEND_FN( numfmt_get_pattern ), arginfo_numberformatter_getpattern )
PHP_NAMED_FE( getLocale, ZEND_FN( numfmt_get_locale ), arginfo_numberformatter_getlocale )
PHP_NAMED_FE( getErrorCode, ZEND_FN( numfmt_get_error_code ), arginfo_numberformatter_getpattern )
PHP_NAMED_FE( getErrorMessage, ZEND_FN( numfmt_get_error_message ), arginfo_numberformatter_getpattern )
{ NULL, NULL, NULL }
};
/* }}} */
@ -123,12 +175,12 @@ void formatter_register_class( TSRMLS_D )
{
zend_class_entry ce;
// Create and register 'NumberFormatter' class.
/* Create and register 'NumberFormatter' class. */
INIT_CLASS_ENTRY( ce, "NumberFormatter", NumberFormatter_class_functions );
ce.create_object = NumberFormatter_object_create;
NumberFormatter_ce_ptr = zend_register_internal_class( &ce TSRMLS_CC );
// Declare 'NumberFormatter' class properties.
/* Declare 'NumberFormatter' class properties. */
if( !NumberFormatter_ce_ptr )
{
zend_error(E_ERROR, "Failed to register NumberFormatter class");

21
ext/intl/formatter/formatter_format.c

@ -39,7 +39,7 @@ PHP_FUNCTION( numfmt_format )
int formatted_len = USIZE(format_buf);
FORMATTER_METHOD_INIT_VARS;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OZ|l",
&object, NumberFormatter_ce_ptr, &number, &type ) == FAILURE )
{
@ -49,7 +49,7 @@ PHP_FUNCTION( numfmt_format )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
FORMATTER_METHOD_FETCH_OBJECT;
if(type == FORMAT_TYPE_DEFAULT) {
@ -62,7 +62,7 @@ PHP_FUNCTION( numfmt_format )
}
if(Z_TYPE_PP(number) == IS_LONG) {
// take INT32 on 32-bit, int64 on 64-bit
/* take INT32 on 32-bit, int64 on 64-bit */
type = (sizeof(long) == 8)?FORMAT_TYPE_INT64:FORMAT_TYPE_INT32;
} else if(Z_TYPE_PP(number) == IS_DOUBLE) {
type = FORMAT_TYPE_DOUBLE;
@ -150,7 +150,7 @@ PHP_FUNCTION( numfmt_format_currency )
int scurrency_len = 0;
FORMATTER_METHOD_INIT_VARS;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ods",
&object, NumberFormatter_ce_ptr, &number, &currency, &currency_len ) == FAILURE )
{
@ -160,19 +160,20 @@ PHP_FUNCTION( numfmt_format_currency )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
FORMATTER_METHOD_FETCH_OBJECT;
// Convert currency to UTF-16.
/* Convert currency to UTF-16. */
intl_convert_utf8_to_utf16(&scurrency, &scurrency_len, currency, currency_len, &INTL_DATA_ERROR_CODE(nfo));
INTL_METHOD_CHECK_STATUS( nfo, "Currency conversion to UTF-16 failed" );
// Format the number using a fixed-length buffer.
/* Format the number using a fixed-length buffer. */
formatted_len = unum_formatDoubleCurrency(FORMATTER_OBJECT(nfo), number, scurrency, formatted, formatted_len, NULL, &INTL_DATA_ERROR_CODE(nfo));
// If the buffer turned out to be too small
// then allocate another buffer dynamically
// and use it to format the number.
/* If the buffer turned out to be too small
* then allocate another buffer dynamically
* and use it to format the number.
*/
if (INTL_DATA_ERROR_CODE(nfo) == U_BUFFER_OVERFLOW_ERROR) {
intl_error_reset(INTL_DATA_ERROR_P(nfo) TSRMLS_CC);
formatted = eumalloc(formatted_len);

14
ext/intl/formatter/formatter_main.c

@ -35,7 +35,7 @@ static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
int spattern_len = 0;
FORMATTER_METHOD_INIT_VARS;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "sl|s",
&locale, &locale_len, &style, &pattern, &pattern_len ) == FAILURE )
{
@ -49,7 +49,7 @@ static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
object = return_value;
FORMATTER_METHOD_FETCH_OBJECT;
// Convert pattern (if specified) to UTF-16.
/* Convert pattern (if specified) to UTF-16. */
if(pattern && pattern_len) {
intl_convert_utf8_to_utf16(&spattern, &spattern_len, pattern, pattern_len, &INTL_DATA_ERROR_CODE(nfo));
INTL_CTOR_CHECK_STATUS(nfo, "numfmt_create: error converting pattern to UTF-16");
@ -59,7 +59,7 @@ static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
locale = INTL_G(default_locale);
}
// Create an ICU number formatter.
/* Create an ICU number formatter. */
FORMATTER_OBJECT(nfo) = unum_open(style, spattern, spattern_len, locale, NULL, &INTL_DATA_ERROR_CODE(nfo));
if(spattern) {
@ -101,7 +101,7 @@ PHP_FUNCTION( numfmt_get_error_code )
{
FORMATTER_METHOD_INIT_VARS
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
&object, NumberFormatter_ce_ptr ) == FAILURE )
{
@ -113,7 +113,7 @@ PHP_FUNCTION( numfmt_get_error_code )
nfo = (NumberFormatter_object *) zend_object_store_get_object( object TSRMLS_CC );
// Return formatter's last error code.
/* Return formatter's last error code. */
RETURN_LONG( INTL_DATA_ERROR_CODE(nfo) );
}
/* }}} */
@ -128,7 +128,7 @@ PHP_FUNCTION( numfmt_get_error_message )
char* message = NULL;
FORMATTER_METHOD_INIT_VARS
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
&object, NumberFormatter_ce_ptr ) == FAILURE )
{
@ -140,7 +140,7 @@ PHP_FUNCTION( numfmt_get_error_message )
nfo = (NumberFormatter_object *) zend_object_store_get_object( object TSRMLS_CC );
// Return last error message.
/* Return last error message. */
message = intl_error_get_message( &INTL_DATA_ERROR(nfo) TSRMLS_CC );
RETURN_STRING( message, 0);
}

14
ext/intl/formatter/formatter_parse.c

@ -45,7 +45,7 @@ PHP_FUNCTION( numfmt_parse )
zval *zposition = NULL;
FORMATTER_METHOD_INIT_VARS;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|lz!",
&object, NumberFormatter_ce_ptr, &str, &str_len, &type, &zposition ) == FAILURE )
{
@ -55,10 +55,10 @@ PHP_FUNCTION( numfmt_parse )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
FORMATTER_METHOD_FETCH_OBJECT;
// Convert given string to UTF-16.
/* Convert given string to UTF-16. */
intl_convert_utf8_to_utf16(&sstr, &sstr_len, str, str_len, &INTL_DATA_ERROR_CODE(nfo));
INTL_METHOD_CHECK_STATUS( nfo, "String conversion to UTF-16 failed" );
@ -122,7 +122,7 @@ PHP_FUNCTION( numfmt_parse_currency )
zval *zcurrency, *zposition = NULL;
FORMATTER_METHOD_INIT_VARS;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osz|z!",
&object, NumberFormatter_ce_ptr, &str, &str_len, &zcurrency, &zposition ) == FAILURE )
{
@ -132,10 +132,10 @@ PHP_FUNCTION( numfmt_parse_currency )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
FORMATTER_METHOD_FETCH_OBJECT;
// Convert given string to UTF-16.
/* Convert given string to UTF-16. */
intl_convert_utf8_to_utf16(&sstr, &sstr_len, str, str_len, &INTL_DATA_ERROR_CODE(nfo));
INTL_METHOD_CHECK_STATUS( nfo, "String conversion to UTF-16 failed" );
@ -153,7 +153,7 @@ PHP_FUNCTION( numfmt_parse_currency )
efree(sstr);
INTL_METHOD_CHECK_STATUS( nfo, "Number parsing failed" );
// Convert parsed currency to UTF-8 and pass it back to caller.
/* Convert parsed currency to UTF-8 and pass it back to caller. */
intl_convert_utf16_to_utf8(&currency_str, &currency_len, currency, u_strlen(currency), &INTL_DATA_ERROR_CODE(nfo));
INTL_METHOD_CHECK_STATUS( nfo, "Currency conversion to UTF-8 failed" );
zval_dtor( zcurrency );

2
ext/intl/grapheme/grapheme_string.c

@ -787,7 +787,7 @@ PHP_FUNCTION(grapheme_extract)
unsigned char u_break_iterator_buffer[U_BRK_SAFECLONE_BUFFERSIZE];
UBreakIterator* bi = NULL;
int ret_pos;
zval *next = NULL; // return offset of next part of the string
zval *next = NULL; /* return offset of next part of the string */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|llz", (char **)&str, &str_len, &size, &extract_type, &lstart, &next) == FAILURE) {

35
ext/intl/intl_convert.c

@ -51,31 +51,33 @@ void intl_convert_utf8_to_utf16(
UChar* dst_buf = NULL;
int32_t dst_len = 0;
// If *target is NULL determine required destination buffer size (pre-flighting).
// Otherwise, attempt to convert source string; if *target buffer is not large enough
// it will be resized appropriately.
/* If *target is NULL determine required destination buffer size (pre-flighting).
* Otherwise, attempt to convert source string; if *target buffer is not large enough
* it will be resized appropriately.
*/
*status = U_ZERO_ERROR;
u_strFromUTF8( *target, *target_len, &dst_len, src, src_len, status );
if( *status == U_ZERO_ERROR )
{
// String is converted successfuly
/* String is converted successfuly */
(*target)[dst_len] = 0;
*target_len = dst_len;
return;
}
// Bail out if an unexpected error occured.
// (U_BUFFER_OVERFLOW_ERROR means that *target buffer is not large enough).
// (U_STRING_NOT_TERMINATED_WARNING usually means that the input string is empty).
/* Bail out if an unexpected error occured.
* (U_BUFFER_OVERFLOW_ERROR means that *target buffer is not large enough).
* (U_STRING_NOT_TERMINATED_WARNING usually means that the input string is empty).
*/
if( *status != U_BUFFER_OVERFLOW_ERROR && *status != U_STRING_NOT_TERMINATED_WARNING )
return;
// Allocate memory for the destination buffer (it will be zero-terminated).
/* Allocate memory for the destination buffer (it will be zero-terminated). */
dst_buf = eumalloc( dst_len + 1 );
// Convert source string from UTF-8 to UTF-16.
/* Convert source string from UTF-8 to UTF-16. */
*status = U_ZERO_ERROR;
u_strFromUTF8( dst_buf, dst_len+1, NULL, src, src_len, status );
if( U_FAILURE( *status ) )
@ -113,20 +115,21 @@ void intl_convert_utf16_to_utf8(
char* dst_buf = NULL;
int32_t dst_len;
// Determine required destination buffer size (pre-flighting).
/* Determine required destination buffer size (pre-flighting). */
*status = U_ZERO_ERROR;
u_strToUTF8( NULL, 0, &dst_len, src, src_len, status );
// Bail out if an unexpected error occured.
// (U_BUFFER_OVERFLOW_ERROR means that *target buffer is not large enough).
// (U_STRING_NOT_TERMINATED_WARNING usually means that the input string is empty).
/* Bail out if an unexpected error occured.
* (U_BUFFER_OVERFLOW_ERROR means that *target buffer is not large enough).
* (U_STRING_NOT_TERMINATED_WARNING usually means that the input string is empty).
*/
if( *status != U_BUFFER_OVERFLOW_ERROR && *status != U_STRING_NOT_TERMINATED_WARNING )
return;
// Allocate memory for the destination buffer (it will be zero-terminated).
/* Allocate memory for the destination buffer (it will be zero-terminated). */
dst_buf = emalloc( dst_len+1 );
// Convert source string from UTF-8 to UTF-16.
/* Convert source string from UTF-8 to UTF-16. */
*status = U_ZERO_ERROR;
u_strToUTF8( dst_buf, dst_len, NULL, src, src_len, status );
if( U_FAILURE( *status ) )
@ -135,7 +138,7 @@ void intl_convert_utf16_to_utf8(
return;
}
// U_STRING_NOT_TERMINATED_WARNING is OK for us => reset 'status'.
/* U_STRING_NOT_TERMINATED_WARNING is OK for us => reset 'status'. */
*status = U_ZERO_ERROR;
dst_buf[dst_len] = 0;

8
ext/intl/intl_error.c

@ -106,13 +106,13 @@ void intl_error_set_custom_msg( intl_error* err, char* msg, int copyMsg TSRMLS_D
if( !err && !( err = intl_g_error_get( TSRMLS_C ) ) )
return;
// Free previous message if any
/* Free previous message if any */
intl_free_custom_error_msg( err TSRMLS_CC );
// Mark message copied if any
/* Mark message copied if any */
err->free_custom_error_message = copyMsg;
// Set user's error text message
/* Set user's error text message */
err->custom_error_message = copyMsg ? estrdup( msg ) : msg;
}
/* }}} */
@ -130,7 +130,7 @@ char* intl_error_get_message( intl_error* err TSRMLS_DC )
uErrorName = u_errorName( err->code );
// Format output string
/* Format output string */
if( err->custom_error_message )
{
spprintf( &errMessage, 0, "%s: %s", err->custom_error_message, uErrorName );

14
ext/intl/msgformat/msgformat.c

@ -38,7 +38,7 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
intl_error_reset( NULL TSRMLS_CC );
object = return_value;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "ss",
&locale, &locale_len, &pattern, &pattern_len ) == FAILURE )
{
@ -51,7 +51,7 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
INTL_CHECK_LOCALE_LEN_OBJ(locale_len, return_value);
MSG_FORMAT_METHOD_FETCH_OBJECT;
// Convert pattern (if specified) to UTF-16.
/* Convert pattern (if specified) to UTF-16. */
if(pattern && pattern_len) {
intl_convert_utf8_to_utf16(&spattern, &spattern_len, pattern, pattern_len, &INTL_DATA_ERROR_CODE(mfo));
INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: error converting pattern to UTF-16");
@ -71,7 +71,7 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
(mfo)->mf_data.orig_format = estrndup(pattern, pattern_len);
(mfo)->mf_data.orig_format_len = pattern_len;
// Create an ICU message formatter.
/* Create an ICU message formatter. */
MSG_FORMAT_OBJECT(mfo) = umsg_open(spattern, spattern_len, locale, NULL, &INTL_DATA_ERROR_CODE(mfo));
if(spattern) {
@ -114,7 +114,7 @@ PHP_FUNCTION( msgfmt_get_error_code )
zval* object = NULL;
MessageFormatter_object* mfo = NULL;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
&object, MessageFormatter_ce_ptr ) == FAILURE )
{
@ -126,7 +126,7 @@ PHP_FUNCTION( msgfmt_get_error_code )
mfo = (MessageFormatter_object *) zend_object_store_get_object( object TSRMLS_CC );
// Return formatter's last error code.
/* Return formatter's last error code. */
RETURN_LONG( INTL_DATA_ERROR_CODE(mfo) );
}
/* }}} */
@ -142,7 +142,7 @@ PHP_FUNCTION( msgfmt_get_error_message )
zval* object = NULL;
MessageFormatter_object* mfo = NULL;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
&object, MessageFormatter_ce_ptr ) == FAILURE )
{
@ -154,7 +154,7 @@ PHP_FUNCTION( msgfmt_get_error_message )
mfo = (MessageFormatter_object *) zend_object_store_get_object( object TSRMLS_CC );
// Return last error message.
/* Return last error message. */
message = intl_error_get_message( &mfo->mf_data.error TSRMLS_CC );
RETURN_STRING( message, 0);
}

14
ext/intl/msgformat/msgformat_attr.c

@ -38,7 +38,7 @@ PHP_FUNCTION( msgfmt_get_pattern )
UChar* value = value_buf;
MSG_FORMAT_METHOD_INIT_VARS;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &object, MessageFormatter_ce_ptr ) == FAILURE )
{
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
@ -46,7 +46,7 @@ PHP_FUNCTION( msgfmt_get_pattern )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
MSG_FORMAT_METHOD_FETCH_OBJECT;
if(mfo->mf_data.orig_format) {
@ -70,7 +70,7 @@ PHP_FUNCTION( msgfmt_set_pattern )
UChar* spattern = NULL;
MSG_FORMAT_METHOD_INIT_VARS;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
&object, MessageFormatter_ce_ptr, &value, &value_len ) == FAILURE )
{
@ -81,7 +81,7 @@ PHP_FUNCTION( msgfmt_set_pattern )
MSG_FORMAT_METHOD_FETCH_OBJECT;
// Convert given pattern to UTF-16.
/* Convert given pattern to UTF-16. */
intl_convert_utf8_to_utf16(&spattern, &spattern_len, value, value_len, &INTL_DATA_ERROR_CODE(mfo));
INTL_METHOD_CHECK_STATUS(mfo, "Error converting pattern to UTF-16" );
@ -91,7 +91,7 @@ PHP_FUNCTION( msgfmt_set_pattern )
RETURN_FALSE;
}
// TODO: add parse error information
/* TODO: add parse error information */
umsg_applyPattern(MSG_FORMAT_OBJECT(mfo), spattern, spattern_len, NULL, &INTL_DATA_ERROR_CODE(mfo));
efree(spattern);
INTL_METHOD_CHECK_STATUS(mfo, "Error setting symbol value");
@ -116,7 +116,7 @@ PHP_FUNCTION( msgfmt_get_locale )
char *loc;
MSG_FORMAT_METHOD_INIT_VARS;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
&object, MessageFormatter_ce_ptr ) == FAILURE )
{
@ -126,7 +126,7 @@ PHP_FUNCTION( msgfmt_get_locale )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
MSG_FORMAT_METHOD_FETCH_OBJECT;
loc = (char *)umsg_getLocale(MSG_FORMAT_OBJECT(mfo));

73
ext/intl/msgformat/msgformat_class.c

@ -26,9 +26,9 @@
zend_class_entry *MessageFormatter_ce_ptr = NULL;
/////////////////////////////////////////////////////////////////////////////
// Auxiliary functions needed by objects of 'MessageFormatter' class
/////////////////////////////////////////////////////////////////////////////
/*
* Auxiliary functions needed by objects of 'MessageFormatter' class
*/
/* {{{ MessageFormatter_objects_dtor */
static void MessageFormatter_object_dtor(void *object, zend_object_handle handle TSRMLS_DC )
@ -72,26 +72,59 @@ zend_object_value MessageFormatter_object_create(zend_class_entry *ce TSRMLS_DC)
}
/* }}} */
/////////////////////////////////////////////////////////////////////////////
// 'MessageFormatter' class registration structures & functions
/////////////////////////////////////////////////////////////////////////////
/*
* 'MessageFormatter' class registration structures & functions
*/
/* {{{ arginfo */
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_messageformatter___construct, 0, 0, 2)
ZEND_ARG_INFO(0, locale)
ZEND_ARG_INFO(0, pattern)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO(arginfo_messageformatter_geterrormessage, 0)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_messageformatter_formatmessage, 0, 0, 3)
ZEND_ARG_INFO(0, locale)
ZEND_ARG_INFO(0, pattern)
ZEND_ARG_INFO(0, args)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_messageformatter_format, 0, 0, 1)
ZEND_ARG_INFO(0, args)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_messageformatter_setpattern, 0, 0, 1)
ZEND_ARG_INFO(0, pattern)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_messageformatter_parse, 0, 0, 1)
ZEND_ARG_INFO(0, source)
ZEND_END_ARG_INFO()
/* }}} */
/* {{{ MessageFormatter_class_functions
* Every 'MessageFormatter' class method has an entry in this table
*/
static function_entry MessageFormatter_class_functions[] = {
PHP_ME( MessageFormatter, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR )
ZEND_FENTRY( create, ZEND_FN( msgfmt_create ), NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
PHP_NAMED_FE( format, ZEND_FN( msgfmt_format ), NULL )
ZEND_FENTRY( formatMessage, ZEND_FN( msgfmt_format_message ), NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
PHP_NAMED_FE( parse, ZEND_FN( msgfmt_parse ), NULL )
ZEND_FENTRY( parseMessage, ZEND_FN( msgfmt_parse_message ), NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
PHP_NAMED_FE( setPattern, ZEND_FN( msgfmt_set_pattern ), NULL )
PHP_NAMED_FE( getPattern, ZEND_FN( msgfmt_get_pattern ), NULL )
PHP_NAMED_FE( getLocale, ZEND_FN( msgfmt_get_locale ), NULL )
PHP_NAMED_FE( getErrorCode, ZEND_FN( msgfmt_get_error_code ), NULL )
PHP_NAMED_FE( getErrorMessage, ZEND_FN( msgfmt_get_error_message ), NULL )
PHP_ME( MessageFormatter, __construct, arginfo_messageformatter___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR )
ZEND_FENTRY( create, ZEND_FN( msgfmt_create ), arginfo_messageformatter___construct, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
PHP_NAMED_FE( format, ZEND_FN( msgfmt_format ), arginfo_messageformatter_format )
ZEND_FENTRY( formatMessage, ZEND_FN( msgfmt_format_message ), arginfo_messageformatter_formatmessage, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
PHP_NAMED_FE( parse, ZEND_FN( msgfmt_parse ), arginfo_messageformatter_parse )
ZEND_FENTRY( parseMessage, ZEND_FN( msgfmt_parse_message ), arginfo_messageformatter_formatmessage, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
PHP_NAMED_FE( setPattern, ZEND_FN( msgfmt_set_pattern ), arginfo_messageformatter_setpattern )
PHP_NAMED_FE( getPattern, ZEND_FN( msgfmt_get_pattern ), arginfo_messageformatter_geterrormessage )
PHP_NAMED_FE( getLocale, ZEND_FN( msgfmt_get_locale ), arginfo_messageformatter_geterrormessage )
PHP_NAMED_FE( getErrorCode, ZEND_FN( msgfmt_get_error_code ), arginfo_messageformatter_geterrormessage )
PHP_NAMED_FE( getErrorMessage, ZEND_FN( msgfmt_get_error_message ), arginfo_messageformatter_geterrormessage )
{ NULL, NULL, NULL }
};
/* }}} */
@ -103,12 +136,12 @@ void msgformat_register_class( TSRMLS_D )
{
zend_class_entry ce;
// Create and register 'MessageFormatter' class.
/* Create and register 'MessageFormatter' class. */
INIT_CLASS_ENTRY( ce, "MessageFormatter", MessageFormatter_class_functions );
ce.create_object = MessageFormatter_object_create;
MessageFormatter_ce_ptr = zend_register_internal_class( &ce TSRMLS_CC );
// Declare 'MessageFormatter' class properties.
/* Declare 'MessageFormatter' class properties. */
if( !MessageFormatter_ce_ptr )
{
zend_error(E_ERROR, "Failed to register MessageFormatter class");

12
ext/intl/msgformat/msgformat_format.c

@ -44,7 +44,7 @@ static void msgfmt_do_format(MessageFormatter_object *mfo, zval *args, zval *ret
count = zend_hash_num_elements(Z_ARRVAL_P(args));
if(count < umsg_format_arg_count(MSG_FORMAT_OBJECT(mfo))) {
// Not enough aguments for format!
/* Not enough aguments for format! */
intl_error_set( INTL_DATA_ERROR_P(mfo), U_ILLEGAL_ARGUMENT_ERROR,
"msgfmt_format: not enough parameters", 0 TSRMLS_CC );
RETVAL_FALSE;
@ -91,7 +91,7 @@ PHP_FUNCTION( msgfmt_format )
MSG_FORMAT_METHOD_INIT_VARS;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oa",
&object, MessageFormatter_ce_ptr, &args ) == FAILURE )
{
@ -101,7 +101,7 @@ PHP_FUNCTION( msgfmt_format )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
MSG_FORMAT_METHOD_FETCH_OBJECT;
msgfmt_do_format(mfo, args, return_value TSRMLS_CC);
@ -125,7 +125,7 @@ PHP_FUNCTION( msgfmt_format_message )
MessageFormatter_object mf = {0};
MessageFormatter_object *mfo = &mf;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "ssa",
&slocale, &slocale_len, &pattern, &pattern_len, &args ) == FAILURE )
{
@ -160,7 +160,7 @@ PHP_FUNCTION( msgfmt_format_message )
RETURN_FALSE;
}
// Create an ICU message formatter.
/* Create an ICU message formatter. */
MSG_FORMAT_OBJECT(mfo) = umsg_open(spattern, spattern_len, slocale, NULL, &INTL_DATA_ERROR_CODE(mfo));
if(spattern && spattern_len) {
efree(spattern);
@ -169,7 +169,7 @@ PHP_FUNCTION( msgfmt_format_message )
msgfmt_do_format(mfo, args, return_value TSRMLS_CC);
// drop the temporary formatter
/* drop the temporary formatter */
msgformat_data_free(&mfo->mf_data TSRMLS_CC);
}
/* }}} */

10
ext/intl/msgformat/msgformat_parse.c

@ -63,7 +63,7 @@ PHP_FUNCTION( msgfmt_parse )
MSG_FORMAT_METHOD_INIT_VARS;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
&object, MessageFormatter_ce_ptr, &source, &source_len ) == FAILURE )
{
@ -73,7 +73,7 @@ PHP_FUNCTION( msgfmt_parse )
RETURN_FALSE;
}
// Fetch the object.
/* Fetch the object. */
MSG_FORMAT_METHOD_FETCH_OBJECT;
msgfmt_do_parse(mfo, source, source_len, return_value TSRMLS_CC);
@ -98,7 +98,7 @@ PHP_FUNCTION( msgfmt_parse_message )
MessageFormatter_object mf = {0};
MessageFormatter_object *mfo = &mf;
// Parse parameters.
/* Parse parameters. */
if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "sss",
&slocale, &slocale_len, &pattern, &pattern_len, &source, &src_len ) == FAILURE )
{
@ -133,7 +133,7 @@ PHP_FUNCTION( msgfmt_parse_message )
RETURN_FALSE;
}
// Create an ICU message formatter.
/* Create an ICU message formatter. */
MSG_FORMAT_OBJECT(mfo) = umsg_open(spattern, spattern_len, slocale, NULL, &INTL_DATA_ERROR_CODE(mfo));
if(spattern && spattern_len) {
efree(spattern);
@ -142,7 +142,7 @@ PHP_FUNCTION( msgfmt_parse_message )
msgfmt_do_parse(mfo, source, src_len, return_value TSRMLS_CC);
// drop the temporary formatter
/* drop the temporary formatter */
msgformat_data_free(&mfo->mf_data TSRMLS_CC);
}
/* }}} */

2
ext/intl/normalizer/normalizer.c

@ -41,7 +41,7 @@ void normalizer_register_constants( INIT_FUNC_ARGS )
#define NORMALIZER_EXPOSE_CLASS_CONST(x) zend_declare_class_constant_long( Normalizer_ce_ptr, ZEND_STRS( #x ) - 1, NORMALIZER_##x TSRMLS_CC );
#define NORMALIZER_EXPOSE_CUSTOM_CLASS_CONST(name, value) zend_declare_class_constant_long( Normalizer_ce_ptr, ZEND_STRS( name ) - 1, value TSRMLS_CC );
// Normalization form constants
/* Normalization form constants */
NORMALIZER_EXPOSE_CLASS_CONST( NONE );
NORMALIZER_EXPOSE_CLASS_CONST( FORM_D );
NORMALIZER_EXPOSE_CLASS_CONST( NFD );

10
ext/intl/normalizer/normalizer_class.c

@ -23,9 +23,9 @@
zend_class_entry *Normalizer_ce_ptr = NULL;
/////////////////////////////////////////////////////////////////////////////
// 'Normalizer' class registration structures & functions
/////////////////////////////////////////////////////////////////////////////
/*
* 'Normalizer' class registration structures & functions
*/
/* {{{ Normalizer methods arguments info */
@ -56,12 +56,12 @@ void normalizer_register_Normalizer_class( TSRMLS_D )
{
zend_class_entry ce;
// Create and register 'Normalizer' class.
/* Create and register 'Normalizer' class. */
INIT_CLASS_ENTRY( ce, "Normalizer", Normalizer_class_functions );
ce.create_object = NULL;
Normalizer_ce_ptr = zend_register_internal_class( &ce TSRMLS_CC );
// Declare 'Normalizer' class properties.
/* Declare 'Normalizer' class properties. */
if( !Normalizer_ce_ptr )
{
zend_error( E_ERROR,

56
ext/intl/normalizer/normalizer_normalize.c

@ -33,7 +33,7 @@
PHP_FUNCTION( normalizer_normalize )
{
char* input = NULL;
// form is optional, defaults to FORM_C
/* form is optional, defaults to FORM_C */
long form = NORMALIZER_DEFAULT;
int input_len = 0;
@ -54,7 +54,7 @@ PHP_FUNCTION( normalizer_normalize )
intl_error_reset( NULL TSRMLS_CC );
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "s|l",
&input, &input_len, &form ) == FAILURE )
{
@ -88,31 +88,32 @@ PHP_FUNCTION( normalizer_normalize )
* Normalize string (converting it to UTF-16 first).
*/
// First convert the string to UTF-16.
/* First convert the string to UTF-16. */
intl_convert_utf8_to_utf16(&uinput, &uinput_len, input, input_len, &status );
if( U_FAILURE( status ) )
{
// Set global error code.
/* Set global error code. */
intl_error_set_code( NULL, status TSRMLS_CC );
// Set error messages.
/* Set error messages. */
intl_error_set_custom_msg( NULL, "Error converting input string to UTF-16", 1 TSRMLS_CC );
efree( uinput );
RETURN_NULL();
}
// Allocate memory for the destination buffer for normalization
/* Allocate memory for the destination buffer for normalization */
uret_len = uinput_len * expansion_factor;
uret_buf = eumalloc( uret_len + 1 );
// normalize
/* normalize */
size_needed = unorm_normalize( uinput, uinput_len, form, (int32_t) 0 /* options */, uret_buf, uret_len, &status);
// Bail out if an unexpected error occured.
// (U_BUFFER_OVERFLOW_ERROR means that *target buffer is not large enough).
// (U_STRING_NOT_TERMINATED_WARNING usually means that the input string is empty).
/* Bail out if an unexpected error occured.
* (U_BUFFER_OVERFLOW_ERROR means that *target buffer is not large enough).
* (U_STRING_NOT_TERMINATED_WARNING usually means that the input string is empty).
*/
if( U_FAILURE(status) && status != U_BUFFER_OVERFLOW_ERROR && status != U_STRING_NOT_TERMINATED_WARNING ) {
efree( uret_buf );
efree( uinput );
@ -120,20 +121,21 @@ PHP_FUNCTION( normalizer_normalize )
}
if ( size_needed > uret_len ) {
// realloc does not seem to work properly - memory is corrupted
// uret_buf = eurealloc(uret_buf, size_needed + 1);
/* realloc does not seem to work properly - memory is corrupted
* uret_buf = eurealloc(uret_buf, size_needed + 1);
*/
efree( uret_buf );
uret_buf = eumalloc( size_needed + 1 );
uret_len = size_needed;
status = U_ZERO_ERROR;
// try normalize again
/* try normalize again */
size_needed = unorm_normalize( uinput, uinput_len, form, (int32_t) 0 /* options */, uret_buf, uret_len, &status);
// Bail out if an unexpected error occured.
/* Bail out if an unexpected error occured. */
if( U_FAILURE(status) ) {
// Set error messages.
/* Set error messages. */
intl_error_set_custom_msg( NULL,"Error normalizing string", 1 TSRMLS_CC );
efree( uret_buf );
efree( uinput );
@ -143,10 +145,10 @@ PHP_FUNCTION( normalizer_normalize )
efree( uinput );
// the buffer we actually used
/* the buffer we actually used */
uret_len = size_needed;
// Convert normalized string from UTF-16 to UTF-8.
/* Convert normalized string from UTF-16 to UTF-8. */
intl_convert_utf16_to_utf8( &ret_buf, &ret_len, uret_buf, uret_len, &status );
efree( uret_buf );
if( U_FAILURE( status ) )
@ -156,7 +158,7 @@ PHP_FUNCTION( normalizer_normalize )
RETURN_NULL();
}
// Return it.
/* Return it. */
RETVAL_STRINGL( ret_buf, ret_len, FALSE );
}
/* }}} */
@ -169,7 +171,7 @@ PHP_FUNCTION( normalizer_normalize )
PHP_FUNCTION( normalizer_is_normalized )
{
char* input = NULL;
// form is optional, defaults to FORM_C
/* form is optional, defaults to FORM_C */
long form = NORMALIZER_DEFAULT;
int input_len = 0;
@ -183,7 +185,7 @@ PHP_FUNCTION( normalizer_is_normalized )
intl_error_reset( NULL TSRMLS_CC );
// Parse parameters.
/* Parse parameters. */
if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "s|l",
&input, &input_len, &form) == FAILURE )
{
@ -194,7 +196,7 @@ PHP_FUNCTION( normalizer_is_normalized )
}
switch(form) {
// case NORMALIZER_NONE: not allowed - doesn't make sense
/* case NORMALIZER_NONE: not allowed - doesn't make sense */
case NORMALIZER_FORM_D:
case NORMALIZER_FORM_KD:
@ -212,29 +214,29 @@ PHP_FUNCTION( normalizer_is_normalized )
* Test normalization of string (converting it to UTF-16 first).
*/
// First convert the string to UTF-16.
/* First convert the string to UTF-16. */
intl_convert_utf8_to_utf16(&uinput, &uinput_len, input, input_len, &status );
if( U_FAILURE( status ) )
{
// Set global error code.
/* Set global error code. */
intl_error_set_code( NULL, status TSRMLS_CC );
// Set error messages.
/* Set error messages. */
intl_error_set_custom_msg( NULL, "Error converting string to UTF-16.", 1 TSRMLS_CC );
efree( uinput );
RETURN_FALSE;
}
// test string
/* test string */
uret = unorm_isNormalizedWithOptions( uinput, uinput_len, form, (int32_t) 0 /* options */, &status);
efree( uinput );
// Bail out if an unexpected error occured.
/* Bail out if an unexpected error occured. */
if( U_FAILURE(status) ) {
// Set error messages.
/* Set error messages. */
intl_error_set_custom_msg( NULL,"Error testing if string is the given normalization form.", 1 TSRMLS_CC );
RETURN_FALSE;
}

417
ext/intl/php_intl.c

@ -85,137 +85,280 @@ ZEND_DECLARE_MODULE_GLOBALS( intl )
/* {{{ Arguments info */
static
ZEND_BEGIN_ARG_INFO_EX( collator_static_0_args, 0, 0, 0 )
ZEND_BEGIN_ARG_INFO_EX(collator_static_0_args, 0, 0, 0)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX( collator_static_1_arg, 0, 0, 1 )
ZEND_ARG_INFO( 0, arg1 )
ZEND_BEGIN_ARG_INFO_EX(collator_static_1_arg, 0, 0, 1)
ZEND_ARG_INFO(0, arg1)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX( collator_static_2_args, 0, 0, 2 )
ZEND_ARG_INFO( 0, arg1 )
ZEND_ARG_INFO( 0, arg2 )
ZEND_BEGIN_ARG_INFO_EX(collator_static_2_args, 0, 0, 2)
ZEND_ARG_INFO(0, arg1)
ZEND_ARG_INFO(0, arg2)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX( collator_0_args, 0, 0, 1 )
ZEND_ARG_OBJ_INFO( 0, object, Collator, 0 )
ZEND_BEGIN_ARG_INFO_EX(collator_0_args, 0, 0, 1)
ZEND_ARG_OBJ_INFO(0, object, Collator, 0)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX( collator_1_arg, 0, 0, 2 )
ZEND_ARG_OBJ_INFO( 0, object, Collator, 0 )
ZEND_ARG_INFO( 0, arg1 )
ZEND_BEGIN_ARG_INFO_EX(collator_1_arg, 0, 0, 2)
ZEND_ARG_OBJ_INFO(0, object, Collator, 0)
ZEND_ARG_INFO(0, arg1)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX( collator_2_args, 0, 0, 3 )
ZEND_ARG_OBJ_INFO( 0, object, Collator, 0 )
ZEND_ARG_INFO( 0, arg1 )
ZEND_ARG_INFO( 0, arg2 )
ZEND_BEGIN_ARG_INFO_EX(collator_2_args, 0, 0, 3)
ZEND_ARG_OBJ_INFO(0, object, Collator, 0)
ZEND_ARG_INFO(0, arg1)
ZEND_ARG_INFO(0, arg2)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX( collator_sort_args, 0, 0, 2 )
ZEND_ARG_OBJ_INFO( 0, object, Collator, 0 )
ZEND_ARG_ARRAY_INFO( 1, arr, 0 )
ZEND_ARG_INFO( 0, sort_flags )
ZEND_BEGIN_ARG_INFO_EX(collator_sort_args, 0, 0, 2)
ZEND_ARG_OBJ_INFO(0, object, Collator, 0)
ZEND_ARG_ARRAY_INFO(1, arr, 0)
ZEND_ARG_INFO(0, sort_flags)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX( numfmt_parse_arginfo, 0, 0, 2 )
ZEND_ARG_INFO( 0, formatter )
ZEND_ARG_INFO( 0, string )
ZEND_ARG_INFO( 0, type )
ZEND_ARG_INFO( 1, position )
static
ZEND_BEGIN_ARG_INFO_EX(numfmt_parse_arginfo, 0, 0, 2)
ZEND_ARG_INFO(0, formatter)
ZEND_ARG_INFO(0, string)
ZEND_ARG_INFO(0, type)
ZEND_ARG_INFO(1, position)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX( numfmt_parse_currency_arginfo, 0, 0, 3 )
ZEND_ARG_INFO( 0, formatter )
ZEND_ARG_INFO( 0, string )
ZEND_ARG_INFO( 1, currency )
ZEND_ARG_INFO( 1, position )
static
ZEND_BEGIN_ARG_INFO_EX(numfmt_parse_currency_arginfo, 0, 0, 3)
ZEND_ARG_INFO(0, formatter)
ZEND_ARG_INFO(0, string)
ZEND_ARG_INFO(1, currency)
ZEND_ARG_INFO(1, position)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX( locale_0_args, 0, 0, 0 )
ZEND_BEGIN_ARG_INFO_EX(locale_0_args, 0, 0, 0)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX( locale_1_arg, 0, 0, 1 )
ZEND_ARG_INFO( 0, arg1 )
ZEND_BEGIN_ARG_INFO_EX(locale_1_arg, 0, 0, 1)
ZEND_ARG_INFO(0, arg1)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX( locale_2_args, 0, 0, 2 )
ZEND_ARG_INFO( 0, arg1 )
ZEND_ARG_INFO( 0, arg2 )
ZEND_BEGIN_ARG_INFO_EX(locale_2_args, 0, 0, 2)
ZEND_ARG_INFO(0, arg1)
ZEND_ARG_INFO(0, arg2)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX( locale_3_args, 0, 0, 3 )
ZEND_ARG_INFO( 0, arg1 )
ZEND_ARG_INFO( 0, arg2 )
ZEND_ARG_INFO( 0, arg3 )
ZEND_BEGIN_ARG_INFO_EX(locale_3_args, 0, 0, 3)
ZEND_ARG_INFO(0, arg1)
ZEND_ARG_INFO(0, arg2)
ZEND_ARG_INFO(0, arg3)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX( locale_4_args, 0, 0, 4 )
ZEND_ARG_INFO( 0, arg1 )
ZEND_ARG_INFO( 0, arg2 )
ZEND_ARG_INFO( 0, arg3 )
ZEND_ARG_INFO( 0, arg4 )
ZEND_BEGIN_ARG_INFO_EX(locale_4_args, 0, 0, 4)
ZEND_ARG_INFO(0, arg1)
ZEND_ARG_INFO(0, arg2)
ZEND_ARG_INFO(0, arg3)
ZEND_ARG_INFO(0, arg4)
ZEND_END_ARG_INFO()
#define intl_0_args collator_static_0_args
#define intl_1_arg collator_static_1_arg
static
ZEND_BEGIN_ARG_INFO_EX( normalizer_args, 0, 0, 1 )
ZEND_ARG_INFO( 0, input )
ZEND_ARG_INFO( 0, form )
ZEND_BEGIN_ARG_INFO_EX(normalizer_args, 0, 0, 1)
ZEND_ARG_INFO(0, input)
ZEND_ARG_INFO(0, form)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(grapheme_1_arg, 0, 0, 1)
ZEND_ARG_INFO(0, string)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(grapheme_search_args, 0, 0, 2)
ZEND_ARG_INFO(0, haystack)
ZEND_ARG_INFO(0, needle)
ZEND_ARG_INFO(0, offset)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(grapheme_substr_args, 0, 0, 2)
ZEND_ARG_INFO(0, string)
ZEND_ARG_INFO(0, start)
ZEND_ARG_INFO(0, length)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(grapheme_strstr_args, 0, 0, 2)
ZEND_ARG_INFO(0, haystack)
ZEND_ARG_INFO(0, needle)
ZEND_ARG_INFO(0, before_needle)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(grapheme_extract_args, 0, 0, 2)
ZEND_ARG_INFO(0, arg1)
ZEND_ARG_INFO(0, arg2)
ZEND_ARG_INFO(0, arg3)
ZEND_ARG_INFO(0, arg4)
ZEND_ARG_INFO(1, arg5) /* 1 = pass by reference */
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(datefmt_parse_args, 0, 0, 2)
ZEND_ARG_INFO(0, formatter)
ZEND_ARG_INFO(0, string)
ZEND_ARG_INFO(1, position)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_numfmt_create, 0, 0, 2)
ZEND_ARG_INFO(0, locale)
ZEND_ARG_INFO(0, style)
ZEND_ARG_INFO(0, pattern)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_numfmt_get_error_code, 0, 0, 1)
ZEND_ARG_INFO(0, nf)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_numfmt_format, 0, 0, 2)
ZEND_ARG_INFO(0, nf)
ZEND_ARG_INFO(0, num)
ZEND_ARG_INFO(0, type)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_numfmt_format_currency, 0, 0, 3)
ZEND_ARG_INFO(0, nf)
ZEND_ARG_INFO(0, num)
ZEND_ARG_INFO(0, currency)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_numfmt_get_attribute, 0, 0, 2)
ZEND_ARG_INFO(0, nf)
ZEND_ARG_INFO(0, attr)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_numfmt_set_attribute, 0, 0, 3)
ZEND_ARG_INFO(0, nf)
ZEND_ARG_INFO(0, attr)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_numfmt_set_symbol, 0, 0, 3)
ZEND_ARG_INFO(0, nf)
ZEND_ARG_INFO(0, attr)
ZEND_ARG_INFO(0, symbol)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_numfmt_set_pattern, 0, 0, 2)
ZEND_ARG_INFO(0, nf)
ZEND_ARG_INFO(0, pattern)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX( grapheme_1_arg, 0, 0, 1 )
ZEND_ARG_INFO( 0, string )
ZEND_BEGIN_ARG_INFO_EX(arginfo_numfmt_get_locale, 0, 0, 1)
ZEND_ARG_INFO(0, nf)
ZEND_ARG_INFO(0, type)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX( grapheme_search_args, 0, 0, 2 )
ZEND_ARG_INFO( 0, haystack )
ZEND_ARG_INFO( 0, needle )
ZEND_ARG_INFO( 0, offset )
ZEND_BEGIN_ARG_INFO_EX(arginfo_msgfmt_create, 0, 0, 2)
ZEND_ARG_INFO(0, locale)
ZEND_ARG_INFO(0, pattern)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX( grapheme_substr_args, 0, 0, 2 )
ZEND_ARG_INFO( 0, string )
ZEND_ARG_INFO( 0, start )
ZEND_ARG_INFO( 0, length )
ZEND_BEGIN_ARG_INFO_EX(arginfo_msgfmt_get_error_code, 0, 0, 1)
ZEND_ARG_INFO(0, nf)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX( grapheme_strstr_args, 0, 0, 2 )
ZEND_ARG_INFO( 0, haystack )
ZEND_ARG_INFO( 0, needle )
ZEND_ARG_INFO( 0, before_needle )
ZEND_BEGIN_ARG_INFO_EX(arginfo_msgfmt_get_error_message, 0, 0, 1)
ZEND_ARG_INFO(0, coll)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX( grapheme_extract_args, 0, 0, 2 )
ZEND_ARG_INFO( 0, arg1 )
ZEND_ARG_INFO( 0, arg2 )
ZEND_ARG_INFO( 0, arg3 )
ZEND_ARG_INFO( 0, arg4 )
ZEND_ARG_INFO( 1, arg5 ) /* 1 = pass by reference */
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_msgfmt_format, 0, 0, 2)
ZEND_ARG_INFO(0, nf)
ZEND_ARG_INFO(0, args)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_msgfmt_format_message, 0, 0, 3)
ZEND_ARG_INFO(0, locale)
ZEND_ARG_INFO(0, pattern)
ZEND_ARG_INFO(0, args)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX( datefmt_parse_args, 0, 0, 2 )
ZEND_ARG_INFO( 0, formatter )
ZEND_ARG_INFO( 0, string )
ZEND_ARG_INFO( 1, position )
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_msgfmt_parse, 0, 0, 2)
ZEND_ARG_INFO(0, nf)
ZEND_ARG_INFO(0, source)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_numfmt_parse_message, 0, 0, 3)
ZEND_ARG_INFO(0, locale)
ZEND_ARG_INFO(0, pattern)
ZEND_ARG_INFO(0, source)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_msgfmt_set_pattern, 0, 0, 2)
ZEND_ARG_INFO(0, mf)
ZEND_ARG_INFO(0, pattern)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_msgfmt_get_locale, 0, 0, 1)
ZEND_ARG_INFO(0, mf)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_datefmt_set_pattern, 0, 0, 2)
ZEND_ARG_INFO(0, mf)
ZEND_ARG_INFO(0, pattern)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_datefmt_set_calendar, 0, 0, 2)
ZEND_ARG_INFO(0, mf)
ZEND_ARG_INFO(0, calendar)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_datefmt_format, 0, 0, 0)
ZEND_ARG_INFO(0, args)
ZEND_ARG_INFO(0, array)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_datefmt_create, 0, 0, 3)
ZEND_ARG_INFO(0, locale)
ZEND_ARG_INFO(0, date_type)
ZEND_ARG_INFO(0, time_type)
ZEND_ARG_INFO(0, timezone_str)
ZEND_ARG_INFO(0, calendar)
ZEND_ARG_INFO(0, pattern)
ZEND_END_ARG_INFO()
/* }}} */
/* {{{ intl_functions
@ -224,7 +367,7 @@ ZEND_END_ARG_INFO()
*/
zend_function_entry intl_functions[] = {
// collator functions
/* collator functions */
PHP_FE( collator_create, collator_static_1_arg )
PHP_FE( collator_compare, collator_2_args )
PHP_FE( collator_get_attribute, collator_1_arg )
@ -238,29 +381,29 @@ zend_function_entry intl_functions[] = {
PHP_FE( collator_get_error_code, collator_0_args )
PHP_FE( collator_get_error_message, collator_0_args )
// formatter functions
PHP_FE( numfmt_create, NULL )
PHP_FE( numfmt_format, NULL )
/* formatter functions */
PHP_FE( numfmt_create, arginfo_numfmt_create )
PHP_FE( numfmt_format, arginfo_numfmt_format )
PHP_FE( numfmt_parse, numfmt_parse_arginfo )
PHP_FE( numfmt_format_currency, NULL )
PHP_FE( numfmt_format_currency, arginfo_numfmt_format_currency )
PHP_FE( numfmt_parse_currency, numfmt_parse_currency_arginfo )
PHP_FE( numfmt_set_attribute, NULL )
PHP_FE( numfmt_get_attribute, NULL )
PHP_FE( numfmt_set_text_attribute, NULL )
PHP_FE( numfmt_get_text_attribute, NULL )
PHP_FE( numfmt_set_symbol, NULL )
PHP_FE( numfmt_get_symbol, NULL )
PHP_FE( numfmt_set_pattern, NULL )
PHP_FE( numfmt_get_pattern, NULL )
PHP_FE( numfmt_get_locale, NULL )
PHP_FE( numfmt_get_error_code, NULL )
PHP_FE( numfmt_get_error_message, NULL )
// normalizer functions
PHP_FE( numfmt_set_attribute, arginfo_numfmt_set_attribute )
PHP_FE( numfmt_get_attribute, arginfo_numfmt_get_attribute )
PHP_FE( numfmt_set_text_attribute, arginfo_numfmt_set_attribute )
PHP_FE( numfmt_get_text_attribute, arginfo_numfmt_get_attribute )
PHP_FE( numfmt_set_symbol, arginfo_numfmt_set_symbol )
PHP_FE( numfmt_get_symbol, arginfo_numfmt_get_attribute )
PHP_FE( numfmt_set_pattern, arginfo_numfmt_set_pattern )
PHP_FE( numfmt_get_pattern, arginfo_numfmt_get_error_code )
PHP_FE( numfmt_get_locale, arginfo_numfmt_get_locale )
PHP_FE( numfmt_get_error_code, arginfo_numfmt_get_error_code )
PHP_FE( numfmt_get_error_message, arginfo_numfmt_get_error_code )
/* normalizer functions */
PHP_FE( normalizer_normalize, normalizer_args )
PHP_FE( normalizer_is_normalized, normalizer_args )
//Locale functions
/* Locale functions */
PHP_NAMED_FE( locale_get_default, zif_locale_get_default, locale_0_args )
PHP_NAMED_FE( locale_set_default, zif_locale_set_default, locale_1_arg )
PHP_FE( locale_get_primary_language, locale_1_arg )
@ -280,38 +423,38 @@ zend_function_entry intl_functions[] = {
PHP_FE( locale_lookup, locale_4_args )
PHP_FE( locale_accept_from_http, locale_1_arg )
// MessageFormatter functions
PHP_FE( msgfmt_create, NULL )
PHP_FE( msgfmt_format, NULL )
PHP_FE( msgfmt_format_message, NULL )
PHP_FE( msgfmt_parse, NULL )
PHP_FE( msgfmt_parse_message, NULL )
PHP_FE( msgfmt_set_pattern, NULL )
PHP_FE( msgfmt_get_pattern, NULL )
PHP_FE( msgfmt_get_locale, NULL )
PHP_FE( msgfmt_get_error_code, NULL )
PHP_FE( msgfmt_get_error_message, NULL )
// IntlDateFormatter functions
PHP_FE( datefmt_create, NULL )
PHP_FE( datefmt_get_datetype, NULL )
PHP_FE( datefmt_get_timetype, NULL )
PHP_FE( datefmt_get_calendar, NULL )
PHP_FE( datefmt_set_calendar, NULL )
PHP_FE( datefmt_get_locale, NULL )
PHP_FE( datefmt_get_timezone_id, NULL )
PHP_FE( datefmt_set_timezone_id, NULL )
PHP_FE( datefmt_get_pattern, NULL )
PHP_FE( datefmt_set_pattern, NULL )
PHP_FE( datefmt_is_lenient, NULL )
PHP_FE( datefmt_set_lenient, NULL )
PHP_FE( datefmt_format, NULL )
/* MessageFormatter functions */
PHP_FE( msgfmt_create, arginfo_msgfmt_create )
PHP_FE( msgfmt_format, arginfo_msgfmt_format )
PHP_FE( msgfmt_format_message, arginfo_msgfmt_format_message )
PHP_FE( msgfmt_parse, arginfo_msgfmt_parse )
PHP_FE( msgfmt_parse_message, arginfo_numfmt_parse_message )
PHP_FE( msgfmt_set_pattern, arginfo_msgfmt_set_pattern )
PHP_FE( msgfmt_get_pattern, arginfo_msgfmt_get_locale )
PHP_FE( msgfmt_get_locale, arginfo_msgfmt_get_locale )
PHP_FE( msgfmt_get_error_code, arginfo_msgfmt_get_error_code )
PHP_FE( msgfmt_get_error_message, arginfo_msgfmt_get_error_message )
/* IntlDateFormatter functions */
PHP_FE( datefmt_create, arginfo_datefmt_create )
PHP_FE( datefmt_get_datetype, arginfo_msgfmt_get_locale )
PHP_FE( datefmt_get_timetype, arginfo_msgfmt_get_locale )
PHP_FE( datefmt_get_calendar, arginfo_msgfmt_get_locale )
PHP_FE( datefmt_set_calendar, arginfo_datefmt_set_calendar )
PHP_FE( datefmt_get_locale, arginfo_msgfmt_get_locale )
PHP_FE( datefmt_get_timezone_id, arginfo_msgfmt_get_locale )
PHP_FE( datefmt_set_timezone_id, arginfo_msgfmt_get_locale )
PHP_FE( datefmt_get_pattern, arginfo_msgfmt_get_locale )
PHP_FE( datefmt_set_pattern, arginfo_datefmt_set_pattern )
PHP_FE( datefmt_is_lenient, arginfo_msgfmt_get_locale )
PHP_FE( datefmt_set_lenient, arginfo_msgfmt_get_locale )
PHP_FE( datefmt_format, arginfo_datefmt_format )
PHP_FE( datefmt_parse, datefmt_parse_args )
PHP_FE( datefmt_localtime , datefmt_parse_args )
PHP_FE( datefmt_get_error_code, NULL )
PHP_FE( datefmt_get_error_message, NULL )
PHP_FE( datefmt_get_error_code, arginfo_msgfmt_get_error_code )
PHP_FE( datefmt_get_error_message, arginfo_msgfmt_get_error_message )
// grapheme functions
/* grapheme functions */
PHP_FE( grapheme_strlen, grapheme_1_arg )
PHP_FE( grapheme_strpos, grapheme_search_args )
PHP_FE( grapheme_stripos, grapheme_search_args )
@ -322,7 +465,7 @@ zend_function_entry intl_functions[] = {
PHP_FE( grapheme_stristr, grapheme_strstr_args )
PHP_FE( grapheme_extract, grapheme_extract_args )
// common functions
/* common functions */
PHP_FE( intl_get_error_code, intl_0_args )
PHP_FE( intl_get_error_message, intl_0_args )
PHP_FE( intl_is_failure, intl_1_arg )
@ -379,52 +522,52 @@ static PHP_GINIT_FUNCTION(intl)
*/
PHP_MINIT_FUNCTION( intl )
{
//For the default locale php.ini setting
/* For the default locale php.ini setting */
REGISTER_INI_ENTRIES();
REGISTER_LONG_CONSTANT("INTL_MAX_LOCALE_LEN", INTL_MAX_LOCALE_LEN, CONST_CS);
// Register 'Collator' PHP class
/* Register 'Collator' PHP class */
collator_register_Collator_class( TSRMLS_C );
// Expose Collator constants to PHP scripts
/* Expose Collator constants to PHP scripts */
collator_register_constants( INIT_FUNC_ARGS_PASSTHRU );
// Register 'NumberFormatter' PHP class
/* Register 'NumberFormatter' PHP class */
formatter_register_class( TSRMLS_C );
// Expose NumberFormatter constants to PHP scripts
/* Expose NumberFormatter constants to PHP scripts */
formatter_register_constants( INIT_FUNC_ARGS_PASSTHRU );
// Register 'Normalizer' PHP class
/* Register 'Normalizer' PHP class */
normalizer_register_Normalizer_class( TSRMLS_C );
// Expose Normalizer constants to PHP scripts
/* Expose Normalizer constants to PHP scripts */
normalizer_register_constants( INIT_FUNC_ARGS_PASSTHRU );
// Register 'Locale' PHP class
/* Register 'Locale' PHP class */
locale_register_Locale_class( TSRMLS_C );
// Expose Locale constants to PHP scripts
/* Expose Locale constants to PHP scripts */
locale_register_constants( INIT_FUNC_ARGS_PASSTHRU );
msgformat_register_class(TSRMLS_C);
grapheme_register_constants( INIT_FUNC_ARGS_PASSTHRU );
// Register 'DateFormat' PHP class
/* Register 'DateFormat' PHP class */
dateformat_register_IntlDateFormatter_class( TSRMLS_C );
// Expose DateFormat constants to PHP scripts
/* Expose DateFormat constants to PHP scripts */
dateformat_register_constants( INIT_FUNC_ARGS_PASSTHRU );
// Expose ICU error codes to PHP scripts.
/* Expose ICU error codes to PHP scripts. */
intl_expose_icu_error_codes( INIT_FUNC_ARGS_PASSTHRU );
// Global error handling.
/* Global error handling. */
intl_error_init( NULL TSRMLS_CC );
//Set the default_locale value
/* Set the default_locale value */
if( INTL_G(default_locale) == NULL ) {
INTL_G(default_locale) = pestrdup(uloc_getDefault(), 1) ;
}
@ -437,7 +580,7 @@ PHP_MINIT_FUNCTION( intl )
*/
PHP_MSHUTDOWN_FUNCTION( intl )
{
//For the default locale php.ini setting
/* For the default locale php.ini setting */
UNREGISTER_INI_ENTRIES();
return SUCCESS;
@ -448,7 +591,7 @@ PHP_MSHUTDOWN_FUNCTION( intl )
*/
PHP_RINIT_FUNCTION( intl )
{
//Set the default_locale value
/* Set the default_locale value */
if( INTL_G(default_locale) == NULL ) {
INTL_G(default_locale) = pestrdup(uloc_getDefault(), 1) ;
}
@ -483,7 +626,7 @@ PHP_MINFO_FUNCTION( intl )
php_info_print_table_row( 2, "ICU version", U_ICU_VERSION );
php_info_print_table_end();
//For the default locale php.ini setting
/* For the default locale php.ini setting */
DISPLAY_INI_ENTRIES() ;
}
/* }}} */

Loading…
Cancel
Save