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: 189 215 87.9 %
Date: 2014-10-24 Functions: 8 9 88.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 5                                                        |
       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          18 : static int create_transliterator( char *str_id, int str_id_len, long direction, zval *object TSRMLS_DC )
      31             : {
      32             :         Transliterator_object *to;
      33          18 :         UChar                 *ustr_id    = NULL;
      34          18 :         int32_t               ustr_id_len = 0;
      35             :         UTransliterator       *utrans;
      36          18 :         UParseError           parse_error   = {0, -1};
      37             : 
      38          18 :         intl_error_reset( NULL TSRMLS_CC );
      39             : 
      40          18 :         if( ( direction != TRANSLITERATOR_FORWARD ) && (direction != TRANSLITERATOR_REVERSE ) )
      41             :         {
      42           0 :                 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
      43             :                         "transliterator_create: invalid direction", 0 TSRMLS_CC );
      44           0 :                 return FAILURE;
      45             :         }
      46             : 
      47          18 :         object_init_ex( object, Transliterator_ce_ptr );
      48          18 :         TRANSLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; /* fetch zend object from zval "object" into "to" */
      49             : 
      50             :         /* Convert transliterator id to UTF-16 */
      51          18 :         intl_convert_utf8_to_utf16( &ustr_id, &ustr_id_len, str_id, str_id_len, TRANSLITERATOR_ERROR_CODE_P( to ) );
      52          18 :         if( U_FAILURE( TRANSLITERATOR_ERROR_CODE( to ) ) )
      53             :         {
      54           2 :                 intl_error_set_code( NULL, TRANSLITERATOR_ERROR_CODE( to ) TSRMLS_CC );
      55           2 :                 intl_error_set_custom_msg( NULL, "String conversion of id to UTF-16 failed", 0 TSRMLS_CC );
      56             :                 zval_dtor( object );
      57           2 :                 return FAILURE;
      58             :         }
      59             : 
      60             :         /* Open ICU Transliterator. */
      61          16 :         utrans = utrans_openU( ustr_id, ustr_id_len, (UTransDirection ) direction,
      62             :                 NULL, -1, &parse_error, TRANSLITERATOR_ERROR_CODE_P( to ) );
      63          16 :         if (ustr_id) {
      64          16 :                 efree( ustr_id );
      65             :         }
      66             :         
      67          16 :         if( U_FAILURE( TRANSLITERATOR_ERROR_CODE( to ) ) )
      68             :         {
      69           2 :                 char *buf = NULL;
      70           2 :                 intl_error_set_code( NULL, TRANSLITERATOR_ERROR_CODE( to ) TSRMLS_CC );
      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 TSRMLS_CC );
      76             :                 }
      77             :                 else
      78             :                 {
      79           2 :                         intl_error_set_custom_msg( NULL, buf, /* copy message */ 1 TSRMLS_CC );
      80           2 :                         efree( buf );
      81             :                 }
      82             :                 zval_dtor( object );
      83           2 :                 return FAILURE;
      84             :         }
      85             :         
      86          14 :         transliterator_object_construct( object, utrans, TRANSLITERATOR_ERROR_CODE_P( to ) TSRMLS_CC );
      87             :         /* no need to close the transliterator manually on construction error */
      88          14 :         if( U_FAILURE( TRANSLITERATOR_ERROR_CODE( to ) ) )
      89             :         {
      90           0 :                 intl_error_set_code( NULL, TRANSLITERATOR_ERROR_CODE( to ) TSRMLS_CC );
      91           0 :                 intl_error_set_custom_msg( NULL,
      92             :                         "transliterator_create: internal constructor call failed", 0 TSRMLS_CC );
      93             :                 zval_dtor( object );
      94           0 :                 return FAILURE;
      95             :         }
      96             : 
      97          14 :         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          16 : PHP_FUNCTION( transliterator_create )
     105             : {
     106             :         char  *str_id;
     107             :         int   str_id_len;
     108          16 :         long  direction   = TRANSLITERATOR_FORWARD;
     109             :         int res;
     110             : 
     111          16 :         TRANSLITERATOR_METHOD_INIT_VARS;
     112             :         
     113             :         (void) to; /* unused */
     114             : 
     115          16 :         if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "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 TSRMLS_CC );
     120           1 :                 RETURN_NULL();
     121             :         }
     122             : 
     123          15 :         object = return_value;
     124          15 :         res = create_transliterator( str_id, str_id_len, direction, object TSRMLS_CC );
     125          15 :         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             :         int             str_rules_len;
     140           8 :         UChar               *ustr_rules    = NULL;
     141           8 :         int32_t         ustr_rules_len = 0;
     142           8 :         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() TSRMLS_CC, "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 TSRMLS_CC );
     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 TSRMLS_CC );
     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           6 :         INTL_CTOR_CHECK_STATUS( 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 ) TSRMLS_CC );
     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 = transliterator_parse_error_to_string( &parse_error );
     187           2 :                 spprintf( &msg, 0, "transliterator_create_from_rules: unable to "
     188             :                         "create ICU transliterator from rules (%s)", parse_error_str.c );
     189           2 :                 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 TSRMLS_CC );
     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 ) TSRMLS_CC );
     199             :         /* no need to close the transliterator manually on construction error */
     200           2 :         INTL_CTOR_CHECK_STATUS( 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           5 : PHP_FUNCTION( transliterator_create_inverse )
     209             : {
     210             :         Transliterator_object *to_orig;
     211             :         UTransliterator       *utrans;
     212           5 :         TRANSLITERATOR_METHOD_INIT_VARS;
     213             : 
     214           5 :         if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
     215             :                 &object, Transliterator_ce_ptr ) == FAILURE )
     216             :         {
     217           2 :                 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
     218             :                         "transliterator_create_inverse: bad arguments", 0 TSRMLS_CC );
     219           2 :                 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_CTOR_CHECK_STATUS( to, "transliterator_create_inverse: could not create "
     231             :                 "inverse ICU transliterator" );
     232           3 :         transliterator_object_construct( object, utrans, TRANSLITERATOR_ERROR_CODE_P( to ) TSRMLS_CC );
     233             :         /* no need to close the transliterator manually on construction error */
     234           3 :         INTL_CTOR_CHECK_STATUS( 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 TSRMLS_CC );
     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 TSRMLS_CC );
     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 :                 int  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         416 :                         add_next_index_stringl( return_value, el_char, el_len, 0 );
     281             :                 }
     282             :         }
     283           2 :         uenum_close( en );
     284             : 
     285           2 :         intl_error_set_code( NULL, status TSRMLS_CC );
     286           2 :         if( U_FAILURE( status ) )
     287             :         {
     288             :                 zval_dtor( return_value );
     289           0 :                 RETVAL_FALSE;
     290           0 :                 intl_error_set_custom_msg( NULL, "transliterator_list_ids: "
     291             :                         "Failed to build array of registered transliterators", 0 TSRMLS_CC );
     292             :         }
     293             : }
     294             : /* }}} */
     295             : 
     296             : /* {{{ proto string transliterator_transliterate( Transliterator trans, string subject [, int start = 0 [, int end = -1 ]] )
     297             :  *     proto string Transliterator::transliterate( string subject [, int start = 0 [, int end = -1 ]] )
     298             :  * Transliterate a string. */
     299          27 : PHP_FUNCTION( transliterator_transliterate )
     300             : {
     301             :         char        *str;
     302          27 :         UChar           *ustr           = NULL,
     303          27 :                                 *uresult        = NULL;
     304             :         int                     str_len;
     305          27 :         int32_t         ustr_len        = 0,
     306             :                                 capacity,
     307             :                                 uresult_len;
     308          27 :         long            start           = 0,
     309          27 :                                 limit           = -1;
     310          27 :         int                     success     = 0,
     311          27 :                                 temp_trans  = 0;
     312          27 :         TRANSLITERATOR_METHOD_INIT_VARS;
     313             : 
     314          27 :         object = getThis();
     315             : 
     316          27 :         if( object == NULL )
     317             :         {
     318             :                 /* in non-OOP version, accept both a transliterator and a string */
     319             :                 zval **arg1;
     320          11 :                 if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "Zs|ll",
     321             :                         &arg1, &str, &str_len, &start, &limit ) == FAILURE )
     322             :                 {
     323           4 :                         intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
     324             :                                 "transliterator_transliterate: bad arguments", 0 TSRMLS_CC );
     325           4 :                         RETURN_FALSE;
     326             :                 }
     327             :                 
     328          16 :                 if( Z_TYPE_PP( arg1 ) == IS_OBJECT &&
     329           5 :                         instanceof_function( Z_OBJCE_PP( arg1 ), Transliterator_ce_ptr TSRMLS_CC ) )
     330             :                 {
     331           4 :                         object = *arg1;
     332             :                 }
     333             :                 else
     334             :                 { /* not a transliterator object as first argument */
     335             :                         int res;
     336           3 :                         if(Z_TYPE_PP( arg1 ) != IS_STRING )
     337             :                         {
     338           2 :                                 SEPARATE_ZVAL( arg1 );
     339           1 :                                 convert_to_string( *arg1 );
     340             :                         }
     341           3 :                         ALLOC_INIT_ZVAL( object );
     342           3 :                         temp_trans = 1;
     343           3 :                         res = create_transliterator( Z_STRVAL_PP( arg1 ), Z_STRLEN_PP( arg1 ),
     344             :                                         TRANSLITERATOR_FORWARD, object TSRMLS_CC );
     345           3 :                         if( res == FAILURE )
     346             :                         {
     347           2 :                                 char *message = intl_error_get_message( NULL TSRMLS_CC );
     348           2 :                                 php_error_docref0( NULL TSRMLS_CC, E_WARNING, "Could not create "
     349           2 :                                         "transliterator with ID \"%s\" (%s)", Z_STRVAL_PP( arg1 ), message );
     350           2 :                                 efree( message );
     351             :                                 /* don't set U_ILLEGAL_ARGUMENT_ERROR to allow fetching of inner error */
     352           2 :                                 goto cleanup;
     353             :                         }
     354             :                 }
     355             :         }
     356          16 :         else if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "s|ll",
     357             :                 &str, &str_len, &start, &limit ) == FAILURE )
     358             :         {
     359           2 :                 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
     360             :                         "transliterator_transliterate: bad arguments", 0 TSRMLS_CC );
     361           2 :                 RETURN_FALSE;
     362             :         }
     363             :         
     364          19 :         if( limit < -1 )
     365             :         {
     366           0 :                 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
     367             :                         "transliterator_transliterate: \"end\" argument should be "
     368             :                         "either non-negative or -1", 0 TSRMLS_CC );
     369           0 :                 RETURN_FALSE;
     370             :         }
     371             : 
     372          19 :         if( start < 0 || ((limit != -1 ) && (start > limit )) )
     373             :         {
     374           1 :                 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
     375             :                         "transliterator_transliterate: \"start\" argument should be "
     376             :                         "non-negative and not bigger than \"end\" (if defined)", 0 TSRMLS_CC );
     377           1 :                 RETURN_FALSE;
     378             :         }
     379             : 
     380             :         /* end argument parsing/validation */
     381             : 
     382          18 :         TRANSLITERATOR_METHOD_FETCH_OBJECT;
     383             :         
     384          18 :         intl_convert_utf8_to_utf16( &ustr, &ustr_len, str, str_len,
     385             :                 TRANSLITERATOR_ERROR_CODE_P( to ) );
     386          18 :         INTL_METHOD_CHECK_STATUS( to, "String conversion of string to UTF-16 failed" );
     387             : 
     388             :         /* we've started allocating resources, goto from now on */
     389             : 
     390          15 :         if( ( start > ustr_len ) || (( limit != -1 ) && (limit > ustr_len ) ) )
     391             :         {
     392             :                 char *msg;
     393           1 :                 spprintf( &msg, 0,
     394             :                         "transliterator_transliterate: Neither \"start\" nor the \"end\" "
     395             :                         "arguments can exceed the number of UTF-16 code units "
     396             :                         "(in this case, %d)", (int) ustr_len );
     397           1 :                 if(msg != NULL )
     398             :                 {
     399           1 :                         intl_errors_set( TRANSLITERATOR_ERROR_P( to ), U_ILLEGAL_ARGUMENT_ERROR,
     400             :                                 msg, 1 TSRMLS_CC );
     401           1 :                         efree( msg );
     402             :                 }
     403           1 :                 RETVAL_FALSE;
     404           1 :                 goto cleanup;
     405             :         }
     406             : 
     407          14 :         uresult = safe_emalloc( ustr_len, sizeof( UChar ), 1 * sizeof( UChar ) );
     408          14 :         capacity = ustr_len + 1;
     409             : 
     410             :         while( 1 )
     411             :         {
     412          15 :                 int32_t temp_limit = ( limit == -1 ? ustr_len : (int32_t) limit );
     413          15 :                 memcpy( uresult, ustr, ustr_len * sizeof( UChar ) );
     414          15 :                 uresult_len = ustr_len;
     415             : 
     416          15 :                 utrans_transUChars( to->utrans, uresult, &uresult_len, capacity, (int32_t) start,
     417             :                         &temp_limit, TRANSLITERATOR_ERROR_CODE_P( to ) );
     418          15 :                 if( TRANSLITERATOR_ERROR_CODE( to ) == U_BUFFER_OVERFLOW_ERROR )
     419             :                 {
     420           1 :                         efree( uresult );
     421             : 
     422           1 :                         uresult = safe_emalloc( uresult_len, sizeof( UChar ), 1 * sizeof( UChar ) );
     423           1 :                         capacity = uresult_len + 1;
     424             : 
     425           1 :                         intl_error_reset( TRANSLITERATOR_ERROR_P( to ) TSRMLS_CC );
     426             :                 }
     427          14 :                 else if(TRANSLITERATOR_ERROR_CODE( to ) == U_STRING_NOT_TERMINATED_WARNING )
     428             :                 {
     429           0 :                         uresult = safe_erealloc( uresult, uresult_len, sizeof( UChar ), 1 * sizeof( UChar ) );
     430             :                         
     431           0 :                         intl_error_reset( TRANSLITERATOR_ERROR_P( to ) TSRMLS_CC );
     432           0 :                         break;
     433             :                 }
     434          14 :                 else if( U_FAILURE( TRANSLITERATOR_ERROR_CODE( to ) ) )
     435             :                 {
     436           0 :                         intl_error_set_code( NULL, TRANSLITERATOR_ERROR_CODE( to ) TSRMLS_CC );
     437           0 :                         intl_errors_set_custom_msg( TRANSLITERATOR_ERROR_P( to ),
     438             :                                 "transliterator_transliterate: transliteration failed", 0 TSRMLS_CC );
     439           0 :                         goto cleanup;
     440             :                 }
     441             :                 else
     442          14 :                         break;
     443           1 :         }
     444             : 
     445          14 :         uresult[uresult_len] = (UChar) 0;
     446             :         
     447          14 :         success = 1;
     448             : 
     449             : cleanup:
     450          17 :         if( ustr )
     451          15 :                 efree( ustr );
     452             : 
     453          17 :         if( success ) {
     454             :                 /* frees uresult even on error */
     455          14 :                 INTL_METHOD_RETVAL_UTF8( to, uresult, uresult_len, 1 );
     456             :         }
     457             :         else
     458             :         {
     459           3 :                 if( uresult )
     460           0 :                         efree( uresult );
     461           3 :                 RETVAL_FALSE;
     462             :         }
     463             : 
     464          17 :         if (temp_trans )
     465           3 :                 zval_ptr_dtor( &object );
     466             : }
     467             : /* }}} */
     468             : 
     469           0 : PHP_METHOD( Transliterator, __construct )
     470             : {
     471             :         /* this constructor shouldn't be called as it's private */
     472           0 :         zend_throw_exception( NULL,
     473             :                 "An object of this type cannot be created with the new operator.",
     474             :                 0 TSRMLS_CC );
     475           0 : }
     476             : 
     477             : /* {{{ proto int transliterator_get_error_code( Transliterator trans )
     478             :  *     proto int Transliterator::getErrorCode()
     479             :  * Get the last error code for this transliterator.
     480             :  */
     481           6 : PHP_FUNCTION( transliterator_get_error_code )
     482             : {
     483           6 :         TRANSLITERATOR_METHOD_INIT_VARS
     484             : 
     485           6 :         if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
     486             :                 &object, Transliterator_ce_ptr ) == FAILURE )
     487             :         {
     488           3 :                 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
     489             :                         "transliterator_get_error_code: unable to parse input params", 0 TSRMLS_CC );
     490             : 
     491           3 :                 RETURN_FALSE;
     492             :         }
     493             : 
     494             :         /* Fetch the object (without resetting its last error code ). */
     495           3 :         to = zend_object_store_get_object( object TSRMLS_CC );
     496           3 :         if (to == NULL )
     497           0 :                 RETURN_FALSE;
     498             : 
     499           3 :         RETURN_LONG( (long) TRANSLITERATOR_ERROR_CODE( to ) );
     500             : }
     501             : /* }}} */
     502             : 
     503             : 
     504             : /* {{{ proto string transliterator_get_error_message( Transliterator trans )
     505             :  *     proto string Transliterator::getErrorMessage()
     506             :  * Get the last error message for this transliterator.
     507             :  */
     508           6 : PHP_FUNCTION( transliterator_get_error_message )
     509             : {
     510           6 :         const char* message = NULL;
     511           6 :         TRANSLITERATOR_METHOD_INIT_VARS
     512             : 
     513           6 :         if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
     514             :                 &object, Transliterator_ce_ptr ) == FAILURE )
     515             :         {
     516           3 :                 intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
     517             :                         "transliterator_get_error_message: unable to parse input params", 0 TSRMLS_CC );
     518             : 
     519           3 :                 RETURN_FALSE;
     520             :         }
     521             : 
     522             : 
     523             :         /* Fetch the object (without resetting its last error code ). */
     524           3 :         to = zend_object_store_get_object( object TSRMLS_CC );
     525           3 :         if (to == NULL )
     526           0 :                 RETURN_FALSE;
     527             : 
     528             :         /* Return last error message. */
     529           3 :         message = intl_error_get_message( TRANSLITERATOR_ERROR_P( to ) TSRMLS_CC );
     530           3 :         RETURN_STRING( message, 0 );
     531             : }
     532             : /* }}} */
     533             : 
     534             : 
     535             : /*
     536             :  * Local variables:
     537             :  * tab-width: 4
     538             :  * c-basic-offset: 4
     539             :  * End:
     540             :  * vim600: noet sw=4 ts=4 fdm=marker
     541             :  * vim<600: noet sw=4 ts=4
     542             :  */

Generated by: LCOV version 1.10

Generated at Fri, 24 Oct 2014 05:21:48 +0000 (19 hours ago)

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