Annotation of embedaddon/php/ext/intl/transliterator/transliterator.c, revision 1.1.1.1

1.1       misho       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 "transliterator_class.h"
                     22: #include "transliterator.h"
                     23: #include "intl_convert.h"
                     24: 
                     25: #include <unicode/ustring.h>
                     26: 
                     27: /* {{{ transliterator_register_constants
                     28:  * Register constants common for both (OO and procedural) APIs.
                     29:  */
                     30: void transliterator_register_constants( INIT_FUNC_ARGS )
                     31: {
                     32:        if( !Transliterator_ce_ptr )
                     33:        {
                     34:                zend_error( E_ERROR, "Transliterator class not defined" );
                     35:                return;
                     36:        }
                     37: 
                     38:        #define TRANSLITERATOR_EXPOSE_CONST( x ) REGISTER_LONG_CONSTANT( #x, x, CONST_CS )
                     39:        #define TRANSLITERATOR_EXPOSE_CLASS_CONST( x ) zend_declare_class_constant_long( Transliterator_ce_ptr, ZEND_STRS( #x ) - 1, TRANSLITERATOR_##x TSRMLS_CC );
                     40:        #define TRANSLITERATOR_EXPOSE_CUSTOM_CLASS_CONST( name, value ) zend_declare_class_constant_long( Transliterator_ce_ptr, ZEND_STRS( name ) - 1, value TSRMLS_CC );*/
                     41: 
                     42:        /* Normalization form constants */
                     43:        TRANSLITERATOR_EXPOSE_CLASS_CONST( FORWARD );
                     44:        TRANSLITERATOR_EXPOSE_CLASS_CONST( REVERSE );
                     45: 
                     46:        #undef NORMALIZER_EXPOSE_CUSTOM_CLASS_CONST
                     47:        #undef NORMALIZER_EXPOSE_CLASS_CONST
                     48:        #undef NORMALIZER_EXPOSE_CONST
                     49: }
                     50: /* }}} */
                     51: 
                     52: /* {{{ transliterator_parse_error_to_string
                     53:  * Transforms parse errors in strings.
                     54:  */
                     55: smart_str transliterator_parse_error_to_string( UParseError* pe )
                     56: {
                     57:        smart_str  ret = {0};
                     58:        char       *buf;
                     59:        int        u8len;
                     60:        UErrorCode status;
                     61:        int        any = 0;
                     62: 
                     63:        assert( pe != NULL );
                     64: 
                     65:        smart_str_appends( &ret, "parse error " );
                     66:        if( pe->line > 0 )
                     67:        {
                     68:                smart_str_appends( &ret, "on line " );
                     69:                smart_str_append_long( &ret, (long ) pe->line );
                     70:                any = 1;
                     71:        }
                     72:        if( pe->offset >= 0 ) {
                     73:                if( any )
                     74:                        smart_str_appends( &ret, ", " );
                     75:                else
                     76:                        smart_str_appends( &ret, "at " );
                     77: 
                     78:                smart_str_appends( &ret, "offset " );
                     79:                smart_str_append_long( &ret, (long ) pe->offset ); 
                     80:                any = 1;
                     81:        }
                     82: 
                     83:        if (pe->preContext[0] != 0 ) {
                     84:                if( any )
                     85:                        smart_str_appends( &ret, ", " );
                     86: 
                     87:                smart_str_appends( &ret, "after \"" );
                     88:                intl_convert_utf16_to_utf8( &buf, &u8len, pe->preContext, -1, &status );
                     89:                if( U_FAILURE( status ) )
                     90:                {
                     91:                        smart_str_appends( &ret, "(could not convert parser error pre-context to UTF-8)" );
                     92:                }
                     93:                else {
                     94:                        smart_str_appendl( &ret, buf, u8len );
                     95:                        efree( buf );
                     96:                }
                     97:                smart_str_appends( &ret, "\"" );
                     98:                any = 1;
                     99:        }
                    100: 
                    101:        if( pe->postContext[0] != 0 )
                    102:        {
                    103:                if( any )
                    104:                        smart_str_appends( &ret, ", " );
                    105: 
                    106:                smart_str_appends( &ret, "before or at \"" );
                    107:                intl_convert_utf16_to_utf8( &buf, &u8len, pe->postContext, -1, &status );
                    108:                if( U_FAILURE( status ) )
                    109:                {
                    110:                        smart_str_appends( &ret, "(could not convert parser error post-context to UTF-8)" );
                    111:                }
                    112:                else
                    113:                {
                    114:                        smart_str_appendl( &ret, buf, u8len );
                    115:                        efree( buf );
                    116:                }
                    117:                smart_str_appends( &ret, "\"" );
                    118:                any = 1;
                    119:        }
                    120: 
                    121:        if( !any )
                    122:        {
                    123:                smart_str_free( &ret );
                    124:                smart_str_appends( &ret, "no parse error" );
                    125:        }
                    126:        
                    127:        smart_str_0( &ret );
                    128:        return ret;
                    129: }
                    130: 
                    131: /*
                    132:  * Local variables:
                    133:  * tab-width: 4
                    134:  * c-basic-offset: 4
                    135:  * End:
                    136:  * vim600: noet sw=4 ts=4 fdm=marker
                    137:  * vim<600: noet sw=4 ts=4
                    138:  */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>