PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/intl/transliterator - transliterator_methods.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 188 214 87.9 %
Date: 2015-06-27 Functions: 8 9 88.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | This source file is subject to version 3.01 of the PHP license,      |
       6             :    | that is bundled with this package in the file LICENSE, and is        |
       7             :    | available through the world-wide-web at the following url:           |
       8             :    | http://www.php.net/license/3_01.txt                                  |
       9             :    | If you did not receive a copy of the PHP license and are unable to   |
      10             :    | obtain it through the world-wide-web, please send a note to          |
      11             :    | license@php.net so we can mail you a copy immediately.               |
      12             :    +----------------------------------------------------------------------+
      13             :    | Authors: Gustavo Lopes <cataphract@php.net>                          |
      14             :    +----------------------------------------------------------------------+
      15             :  */
      16             : 
      17             : #ifdef HAVE_CONFIG_H
      18             : #include "config.h"
      19             : #endif
      20             : 
      21             : #include "php_intl.h"
      22             : #include "transliterator.h"
      23             : #include "transliterator_class.h"
      24             : #include "transliterator_methods.h"
      25             : #include "intl_data.h"
      26             : #include "intl_convert.h"
      27             : 
      28             : #include <zend_exceptions.h>
      29             : 
      30          19 : static int create_transliterator( char *str_id, size_t str_id_len, zend_long direction, zval *object )
      31             : {
      32             :         Transliterator_object *to;
      33          19 :         UChar                 *ustr_id    = NULL;
      34          19 :         int32_t               ustr_id_len = 0;
      35             :         UTransliterator       *utrans;
      36          19 :         UParseError           parse_error   = {0, -1};
      37             : 
      38          19 :         intl_error_reset( NULL );
      39             : 
      40          19 :         if( ( direction != TRANSLITERATOR_FORWARD ) && (direction != TRANSLITERATOR_REVERSE ) )
      41             :         {
      42           0 :                 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
      43             :                         "transliterator_create: invalid direction", 0 );
      44           0 :                 return FAILURE;
      45             :         }
      46             : 
      47          19 :         object_init_ex( object, Transliterator_ce_ptr );
      48          19 :         TRANSLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; /* fetch zend object from zval "object" into "to" */
      49             : 
      50             :         /* Convert transliterator id to UTF-16 */
      51          19 :         intl_convert_utf8_to_utf16( &ustr_id, &ustr_id_len, str_id, str_id_len, TRANSLITERATOR_ERROR_CODE_P( to ) );
      52          19 :         if( U_FAILURE( TRANSLITERATOR_ERROR_CODE( to ) ) )
      53             :         {
      54           2 :                 intl_error_set_code( NULL, TRANSLITERATOR_ERROR_CODE( to ) );
      55           2 :                 intl_error_set_custom_msg( NULL, "String conversion of id to UTF-16 failed", 0 );
      56             :                 zval_dtor( object );
      57           2 :                 return FAILURE;
      58             :         }
      59             : 
      60             :         /* Open ICU Transliterator. */
      61          17 :         utrans = utrans_openU( ustr_id, ustr_id_len, (UTransDirection ) direction,
      62             :                 NULL, -1, &parse_error, TRANSLITERATOR_ERROR_CODE_P( to ) );
      63          17 :         if (ustr_id) {
      64          17 :                 efree( ustr_id );
      65             :         }
      66             : 
      67          17 :         if( U_FAILURE( TRANSLITERATOR_ERROR_CODE( to ) ) )
      68             :         {
      69           2 :                 char *buf = NULL;
      70           2 :                 intl_error_set_code( NULL, TRANSLITERATOR_ERROR_CODE( to ) );
      71           2 :                 spprintf( &buf, 0, "transliterator_create: unable to open ICU transliterator"
      72             :                         " with id \"%s\"", str_id );
      73           2 :                 if( buf == NULL ) {
      74           0 :                         intl_error_set_custom_msg( NULL,
      75             :                                 "transliterator_create: unable to open ICU transliterator", 0 );
      76             :                 }
      77             :                 else
      78             :                 {
      79           2 :                         intl_error_set_custom_msg( NULL, buf, /* copy message */ 1 );
      80           2 :                         efree( buf );
      81             :                 }
      82             :                 zval_dtor( object );
      83           2 :                 return FAILURE;
      84             :         }
      85             : 
      86          15 :         transliterator_object_construct( object, utrans, TRANSLITERATOR_ERROR_CODE_P( to ) );
      87             :         /* no need to close the transliterator manually on construction error */
      88          15 :         if( U_FAILURE( TRANSLITERATOR_ERROR_CODE( to ) ) )
      89             :         {
      90           0 :                 intl_error_set_code( NULL, TRANSLITERATOR_ERROR_CODE( to ) );
      91           0 :                 intl_error_set_custom_msg( NULL,
      92             :                         "transliterator_create: internal constructor call failed", 0 );
      93             :                 zval_dtor( object );
      94           0 :                 return FAILURE;
      95             :         }
      96             : 
      97          15 :         return SUCCESS;
      98             : }
      99             : 
     100             : /* {{{ proto Transliterator transliterator_create( string id [, int direction ] )
     101             :  *     proto Transliterator Transliterator::create( string id [, int direction ] )
     102             :  * Opens a transliterator by id.
     103             :  */
     104          17 : PHP_FUNCTION( transliterator_create )
     105             : {
     106             :         char     *str_id;
     107             :         size_t    str_id_len;
     108          17 :         zend_long direction   = TRANSLITERATOR_FORWARD;
     109             :         int res;
     110             : 
     111          17 :         TRANSLITERATOR_METHOD_INIT_VARS;
     112             : 
     113             :         (void) to; /* unused */
     114             : 
     115          17 :         if( zend_parse_parameters( ZEND_NUM_ARGS(), "s|l",
     116             :                 &str_id, &str_id_len, &direction ) == FAILURE )
     117             :         {
     118           1 :                 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
     119             :                         "transliterator_create: bad arguments", 0 );
     120           1 :                 RETURN_NULL();
     121             :         }
     122             : 
     123          16 :         object = return_value;
     124          16 :         res = create_transliterator( str_id, str_id_len, direction, object );
     125          16 :         if( res == FAILURE )
     126           2 :                 RETURN_NULL();
     127             : 
     128             :         /* success, leave return_value as it is (set by create_transliterator) */
     129             : }
     130             : /* }}} */
     131             : 
     132             : /* {{{ proto Transliterator transliterator_create_from_rules( string rules [, int direction ] )
     133             :  *     proto Transliterator Transliterator::createFromRules( string rules [, int direction ] )
     134             :  * Opens a transliterator by id.
     135             :  */
     136           8 : PHP_FUNCTION( transliterator_create_from_rules )
     137             : {
     138             :         char                *str_rules;
     139             :         size_t          str_rules_len;
     140           8 :         UChar               *ustr_rules    = NULL;
     141           8 :         int32_t         ustr_rules_len = 0;
     142           8 :         zend_long       direction      = TRANSLITERATOR_FORWARD;
     143           8 :         UParseError     parse_error    = {0, -1};
     144             :         UTransliterator *utrans;
     145             :         UChar           id[] = {0x52, 0x75, 0x6C, 0x65, 0x73, 0x54, 0x72,
     146           8 :                                                0x61, 0x6E, 0x73, 0x50, 0x48, 0x50, 0}; /* RulesTransPHP */
     147           8 :         TRANSLITERATOR_METHOD_INIT_VARS;
     148             : 
     149           8 :         if( zend_parse_parameters( ZEND_NUM_ARGS(), "s|l",
     150             :                 &str_rules, &str_rules_len, &direction ) == FAILURE )
     151             :         {
     152           3 :                 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
     153             :                         "transliterator_create_from_rules: bad arguments", 0 );
     154           3 :                 RETURN_NULL();
     155             :         }
     156             : 
     157           5 :         if( ( direction != TRANSLITERATOR_FORWARD ) && (direction != TRANSLITERATOR_REVERSE ) )
     158             :         {
     159           0 :                 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
     160             :                         "transliterator_create_from_rules: invalid direction", 0 );
     161           0 :                 RETURN_NULL();
     162             :         }
     163             : 
     164           5 :         object = return_value;
     165           5 :         object_init_ex( object, Transliterator_ce_ptr );
     166           5 :         TRANSLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK;
     167             : 
     168           5 :         intl_convert_utf8_to_utf16( &ustr_rules, &ustr_rules_len,
     169             :                 str_rules, str_rules_len, TRANSLITERATOR_ERROR_CODE_P( to ) );
     170             :         /* (I'm not a big fan of non-obvious flow control macros ).
     171             :          * This one checks the error value, destroys object and returns false */
     172           5 :         INTL_METHOD_CHECK_STATUS_OR_NULL( to, "String conversion of rules to UTF-16 failed" );
     173             : 
     174             :         /* Open ICU Transliterator. */
     175           4 :         utrans = utrans_openU( id, ( sizeof( id ) - 1 ) / ( sizeof( *id ) ), (UTransDirection ) direction,
     176             :                 ustr_rules, ustr_rules_len, &parse_error, TRANSLITERATOR_ERROR_CODE_P( to ) );
     177           4 :         if (ustr_rules) {
     178           4 :                 efree( ustr_rules );
     179             :         }
     180             : 
     181           4 :         intl_error_set_code( NULL, INTL_DATA_ERROR_CODE( to ) );
     182           4 :         if( U_FAILURE( INTL_DATA_ERROR_CODE( to ) ) )
     183             :         {
     184           2 :                 char *msg = NULL;
     185             :                 smart_str parse_error_str;
     186           2 :                 parse_error_str = intl_parse_error_to_string( &parse_error );
     187           4 :                 spprintf( &msg, 0, "transliterator_create_from_rules: unable to "
     188           4 :                         "create ICU transliterator from rules (%s)", parse_error_str.s? parse_error_str.s->val : "" );
     189             :                 smart_str_free( &parse_error_str );
     190           2 :                 if( msg != NULL )
     191             :                 {
     192           2 :                         intl_errors_set_custom_msg( INTL_DATA_ERROR_P( to ), msg, 1 );
     193           2 :                         efree( msg );
     194             :                 }
     195             :                 zval_dtor( return_value );
     196           2 :                 RETURN_NULL();
     197             :     }
     198           2 :         transliterator_object_construct( object, utrans, TRANSLITERATOR_ERROR_CODE_P( to ) );
     199             :         /* no need to close the transliterator manually on construction error */
     200           2 :         INTL_METHOD_CHECK_STATUS_OR_NULL( to, "transliterator_create_from_rules: internal constructor call failed" );
     201             : }
     202             : /* }}} */
     203             : 
     204             : /* {{{ proto Transliterator transliterator_create_inverse( Transliterator orig_trans )
     205             :  *     proto Transliterator Transliterator::createInverse()
     206             :  * Opens the inverse transliterator transliterator.
     207             :  */
     208           4 : PHP_FUNCTION( transliterator_create_inverse )
     209             : {
     210             :         Transliterator_object *to_orig;
     211             :         UTransliterator       *utrans;
     212           4 :         TRANSLITERATOR_METHOD_INIT_VARS;
     213             : 
     214           4 :         if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O",
     215             :                 &object, Transliterator_ce_ptr ) == FAILURE )
     216             :         {
     217           1 :                 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
     218             :                         "transliterator_create_inverse: bad arguments", 0 );
     219           1 :                 RETURN_NULL();
     220             :         }
     221             : 
     222           3 :         TRANSLITERATOR_METHOD_FETCH_OBJECT;
     223           3 :         to_orig = to;
     224             : 
     225           3 :         object = return_value;
     226           3 :         object_init_ex( object, Transliterator_ce_ptr );
     227           3 :         TRANSLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; /* change "to" into new object (from "object" ) */
     228             : 
     229           3 :         utrans = utrans_openInverse( to_orig->utrans, TRANSLITERATOR_ERROR_CODE_P( to ) );
     230           3 :         INTL_METHOD_CHECK_STATUS_OR_NULL( to, "transliterator_create_inverse: could not create "
     231             :                 "inverse ICU transliterator" );
     232           3 :         transliterator_object_construct( object, utrans, TRANSLITERATOR_ERROR_CODE_P( to ) );
     233             :         /* no need to close the transliterator manually on construction error */
     234           3 :         INTL_METHOD_CHECK_STATUS_OR_NULL( to, "transliterator_create: internal constructor call failed" );
     235             : }
     236             : /* }}} */
     237             : 
     238             : /* {{{ proto array transliterator_list_ids()
     239             :  *     proto array Transliterator::listIDs()
     240             :  * Return an array with the registered transliterator IDs.
     241             :  */
     242           3 : PHP_FUNCTION( transliterator_list_ids )
     243             : {
     244             :         UEnumeration  *en;
     245             :         const UChar       *elem;
     246             :         int32_t           elem_len;
     247           3 :         UErrorCode        status = U_ZERO_ERROR;
     248             : 
     249           3 :         intl_error_reset( NULL );
     250             : 
     251           3 :         if( zend_parse_parameters_none() == FAILURE )
     252             :         {
     253             :                 /* seems to be the convention in this lib to return false instead of
     254             :                  * null on bad parameter types, except on constructors and factory
     255             :                  * methods */
     256           1 :                 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
     257             :                         "transliterator_list_ids: bad arguments", 0 );
     258           1 :                 RETURN_FALSE;
     259             :         }
     260             : 
     261           2 :         en = utrans_openIDs( &status );
     262           2 :         INTL_CHECK_STATUS( status,
     263             :                 "transliterator_list_ids: Failed to obtain registered transliterators" );
     264             : 
     265           2 :         array_init( return_value );
     266         420 :         while( (elem = uenum_unext( en, &elem_len, &status )) )
     267             :         {
     268         416 :                 char *el_char = NULL;
     269         416 :                 size_t el_len   = 0;
     270             : 
     271         416 :                 intl_convert_utf16_to_utf8( &el_char, &el_len, elem, elem_len, &status );
     272             : 
     273         416 :                 if( U_FAILURE( status ) )
     274             :                 {
     275           0 :                         efree( el_char );
     276           0 :                         break;
     277             :                 }
     278             :                 else
     279             :                 {
     280             :                     // TODO: avoid reallocation ???
     281         416 :                         add_next_index_stringl( return_value, el_char, el_len);
     282         416 :                         efree(el_char);
     283             :                 }
     284             :         }
     285           2 :         uenum_close( en );
     286             : 
     287           2 :         intl_error_set_code( NULL, status );
     288           2 :         if( U_FAILURE( status ) )
     289             :         {
     290             :                 zval_dtor( return_value );
     291           0 :                 RETVAL_FALSE;
     292           0 :                 intl_error_set_custom_msg( NULL, "transliterator_list_ids: "
     293             :                         "Failed to build array of registered transliterators", 0 );
     294             :         }
     295             : }
     296             : /* }}} */
     297             : 
     298             : /* {{{ proto string transliterator_transliterate( Transliterator trans, string subject [, int start = 0 [, int end = -1 ]] )
     299             :  *     proto string Transliterator::transliterate( string subject [, int start = 0 [, int end = -1 ]] )
     300             :  * Transliterate a string. */
     301          29 : PHP_FUNCTION( transliterator_transliterate )
     302             : {
     303             :         char        *str;
     304          29 :         UChar           *ustr           = NULL,
     305          29 :                                 *uresult        = NULL;
     306             :         size_t      str_len;
     307          29 :         int32_t         ustr_len        = 0,
     308             :                                 capacity,
     309             :                                 uresult_len;
     310          29 :         zend_long       start           = 0,
     311          29 :                                 limit           = -1;
     312          29 :         int                     success     = 0;
     313             :         zval            tmp_object;
     314          29 :         TRANSLITERATOR_METHOD_INIT_VARS;
     315             : 
     316          29 :         object = getThis();
     317          29 :         ZVAL_UNDEF(&tmp_object);
     318             : 
     319          29 :         if( object == NULL )
     320             :         {
     321             :                 /* in non-OOP version, accept both a transliterator and a string */
     322             :                 zval *arg1;
     323          11 :                 if( zend_parse_parameters( ZEND_NUM_ARGS(), "zs|ll",
     324             :                         &arg1, &str, &str_len, &start, &limit ) == FAILURE )
     325             :                 {
     326           4 :                         intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
     327             :                                 "transliterator_transliterate: bad arguments", 0 );
     328           4 :                         RETURN_FALSE;
     329             :                 }
     330             : 
     331          23 :                 if( Z_TYPE_P( arg1 ) == IS_OBJECT &&
     332           5 :                         instanceof_function( Z_OBJCE_P( arg1 ), Transliterator_ce_ptr ) )
     333             :                 {
     334           4 :                         object = arg1;
     335             :                 }
     336             :                 else
     337             :                 { /* not a transliterator object as first argument */
     338             :                         int res;
     339           6 :                         if(Z_TYPE_P( arg1 ) != IS_STRING )
     340             :                         {
     341           2 :                                 SEPARATE_ZVAL( arg1 );
     342           2 :                                 convert_to_string( arg1 );
     343             :                         }
     344           3 :                         object = &tmp_object;
     345           3 :                         res = create_transliterator( Z_STRVAL_P( arg1 ), Z_STRLEN_P( arg1 ),
     346             :                                         TRANSLITERATOR_FORWARD, object );
     347           3 :                         if( res == FAILURE )
     348             :                         {
     349           2 :                                 zend_string *message = intl_error_get_message( NULL );
     350           4 :                                 php_error_docref0( NULL, E_WARNING, "Could not create "
     351           2 :                                         "transliterator with ID \"%s\" (%s)", Z_STRVAL_P( arg1 ), message->val );
     352             :                                 zend_string_free( message );
     353           2 :                                 ZVAL_UNDEF(&tmp_object);
     354             :                                 /* don't set U_ILLEGAL_ARGUMENT_ERROR to allow fetching of inner error */
     355           2 :                                 goto cleanup;
     356             :                         }
     357             :                 }
     358             :         }
     359          18 :         else if( zend_parse_parameters( ZEND_NUM_ARGS(), "s|ll",
     360             :                 &str, &str_len, &start, &limit ) == FAILURE )
     361             :         {
     362           2 :                 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
     363             :                         "transliterator_transliterate: bad arguments", 0 );
     364           2 :                 RETURN_FALSE;
     365             :         }
     366             : 
     367          21 :         if( limit < -1 )
     368             :         {
     369           0 :                 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
     370             :                         "transliterator_transliterate: \"end\" argument should be "
     371             :                         "either non-negative or -1", 0 );
     372           0 :                 RETURN_FALSE;
     373             :         }
     374             : 
     375          21 :         if( start < 0 || ((limit != -1 ) && (start > limit )) )
     376             :         {
     377           1 :                 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
     378             :                         "transliterator_transliterate: \"start\" argument should be "
     379             :                         "non-negative and not bigger than \"end\" (if defined)", 0 );
     380           1 :                 RETURN_FALSE;
     381             :         }
     382             : 
     383             :         /* end argument parsing/validation */
     384             : 
     385          20 :         TRANSLITERATOR_METHOD_FETCH_OBJECT;
     386             : 
     387          20 :         intl_convert_utf8_to_utf16( &ustr, &ustr_len, str, str_len,
     388             :                 TRANSLITERATOR_ERROR_CODE_P( to ) );
     389          20 :         INTL_METHOD_CHECK_STATUS( to, "String conversion of string to UTF-16 failed" );
     390             : 
     391             :         /* we've started allocating resources, goto from now on */
     392             : 
     393          17 :         if( ( start > ustr_len ) || (( limit != -1 ) && (limit > ustr_len ) ) )
     394             :         {
     395             :                 char *msg;
     396           3 :                 spprintf( &msg, 0,
     397             :                         "transliterator_transliterate: Neither \"start\" nor the \"end\" "
     398             :                         "arguments can exceed the number of UTF-16 code units "
     399             :                         "(in this case, %d)", (int) ustr_len );
     400           3 :                 if(msg != NULL )
     401             :                 {
     402           3 :                         intl_errors_set( TRANSLITERATOR_ERROR_P( to ), U_ILLEGAL_ARGUMENT_ERROR,
     403             :                                 msg, 1 );
     404           3 :                         efree( msg );
     405             :                 }
     406           3 :                 RETVAL_FALSE;
     407           3 :                 goto cleanup;
     408             :         }
     409             : 
     410          14 :         uresult = safe_emalloc( ustr_len, sizeof( UChar ), 1 * sizeof( UChar ) );
     411          14 :         capacity = ustr_len + 1;
     412             : 
     413             :         while( 1 )
     414             :         {
     415          15 :                 int32_t temp_limit = ( limit == -1 ? ustr_len : (int32_t) limit );
     416          15 :                 memcpy( uresult, ustr, ustr_len * sizeof( UChar ) );
     417          15 :                 uresult_len = ustr_len;
     418             : 
     419          15 :                 utrans_transUChars( to->utrans, uresult, &uresult_len, capacity, (int32_t) start,
     420             :                         &temp_limit, TRANSLITERATOR_ERROR_CODE_P( to ) );
     421          15 :                 if( TRANSLITERATOR_ERROR_CODE( to ) == U_BUFFER_OVERFLOW_ERROR )
     422             :                 {
     423           1 :                         efree( uresult );
     424             : 
     425           1 :                         uresult = safe_emalloc( uresult_len, sizeof( UChar ), 1 * sizeof( UChar ) );
     426           1 :                         capacity = uresult_len + 1;
     427             : 
     428           1 :                         intl_error_reset( TRANSLITERATOR_ERROR_P( to ) );
     429             :                 }
     430          14 :                 else if(TRANSLITERATOR_ERROR_CODE( to ) == U_STRING_NOT_TERMINATED_WARNING )
     431             :                 {
     432           0 :                         uresult = safe_erealloc( uresult, uresult_len, sizeof( UChar ), 1 * sizeof( UChar ) );
     433             : 
     434           0 :                         intl_error_reset( TRANSLITERATOR_ERROR_P( to ) );
     435           0 :                         break;
     436             :                 }
     437          14 :                 else if( U_FAILURE( TRANSLITERATOR_ERROR_CODE( to ) ) )
     438             :                 {
     439           0 :                         intl_error_set_code( NULL, TRANSLITERATOR_ERROR_CODE( to ) );
     440           0 :                         intl_errors_set_custom_msg( TRANSLITERATOR_ERROR_P( to ),
     441             :                                 "transliterator_transliterate: transliteration failed", 0 );
     442           0 :                         goto cleanup;
     443             :                 }
     444             :                 else
     445          14 :                         break;
     446           1 :         }
     447             : 
     448          14 :         uresult[uresult_len] = (UChar) 0;
     449             : 
     450          14 :         success = 1;
     451             : 
     452             : cleanup:
     453          19 :         if( ustr )
     454          17 :                 efree( ustr );
     455             : 
     456          19 :         if( success ) {
     457             :                 /* frees uresult even on error */
     458          28 :                 INTL_METHOD_RETVAL_UTF8( to, uresult, uresult_len, 1 );
     459             :         }
     460             :         else
     461             :         {
     462           5 :                 if( uresult )
     463           0 :                         efree( uresult );
     464           5 :                 RETVAL_FALSE;
     465             :         }
     466             : 
     467          19 :         zval_ptr_dtor( &tmp_object );
     468             : }
     469             : /* }}} */
     470             : 
     471           0 : PHP_METHOD( Transliterator, __construct )
     472             : {
     473             :         /* this constructor shouldn't be called as it's private */
     474           0 :         zend_throw_exception( NULL,
     475             :                 "An object of this type cannot be created with the new operator.",
     476             :                 0 );
     477           0 : }
     478             : 
     479             : /* {{{ proto int transliterator_get_error_code( Transliterator trans )
     480             :  *     proto int Transliterator::getErrorCode()
     481             :  * Get the last error code for this transliterator.
     482             :  */
     483           5 : PHP_FUNCTION( transliterator_get_error_code )
     484             : {
     485           5 :         TRANSLITERATOR_METHOD_INIT_VARS
     486             : 
     487           5 :         if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O",
     488             :                 &object, Transliterator_ce_ptr ) == FAILURE )
     489             :         {
     490           2 :                 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
     491             :                         "transliterator_get_error_code: unable to parse input params", 0 );
     492             : 
     493           2 :                 RETURN_FALSE;
     494             :         }
     495             : 
     496             :         /* Fetch the object (without resetting its last error code ). */
     497           3 :         to = Z_INTL_TRANSLITERATOR_P( object );
     498           3 :         if (to == NULL )
     499           0 :                 RETURN_FALSE;
     500             : 
     501           3 :         RETURN_LONG( (zend_long) TRANSLITERATOR_ERROR_CODE( to ) );
     502             : }
     503             : /* }}} */
     504             : 
     505             : 
     506             : /* {{{ proto string transliterator_get_error_message( Transliterator trans )
     507             :  *     proto string Transliterator::getErrorMessage()
     508             :  * Get the last error message for this transliterator.
     509             :  */
     510           5 : PHP_FUNCTION( transliterator_get_error_message )
     511             : {
     512           5 :         zend_string* message = NULL;
     513           5 :         TRANSLITERATOR_METHOD_INIT_VARS
     514             : 
     515           5 :         if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O",
     516             :                 &object, Transliterator_ce_ptr ) == FAILURE )
     517             :         {
     518           2 :                 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
     519             :                         "transliterator_get_error_message: unable to parse input params", 0 );
     520             : 
     521           2 :                 RETURN_FALSE;
     522             :         }
     523             : 
     524             : 
     525             :         /* Fetch the object (without resetting its last error code ). */
     526           3 :         to = Z_INTL_TRANSLITERATOR_P( object );
     527           3 :         if (to == NULL )
     528           0 :                 RETURN_FALSE;
     529             : 
     530             :         /* Return last error message. */
     531           3 :         message = intl_error_get_message( TRANSLITERATOR_ERROR_P( to ) );
     532           3 :         RETURN_STR( message );
     533             : }
     534             : /* }}} */
     535             : 
     536             : 
     537             : /*
     538             :  * Local variables:
     539             :  * tab-width: 4
     540             :  * c-basic-offset: 4
     541             :  * End:
     542             :  * vim600: noet sw=4 ts=4 fdm=marker
     543             :  * vim<600: noet sw=4 ts=4
     544             :  */

Generated by: LCOV version 1.10

Generated at Sat, 27 Jun 2015 09:41:11 +0000 (4 days ago)

Copyright © 2005-2015 The PHP Group
All rights reserved.