Back to index

php5  5.3.10
msgformat_data.c
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | This source file is subject to version 3.01 of the PHP license,      |
00006    | that is bundled with this package in the file LICENSE, and is        |
00007    | available through the world-wide-web at the following url:           |
00008    | http://www.php.net/license/3_01.txt                                  |
00009    | If you did not receive a copy of the PHP license and are unable to   |
00010    | obtain it through the world-wide-web, please send a note to          |
00011    | license@php.net so we can mail you a copy immediately.               |
00012    +----------------------------------------------------------------------+
00013    | Authors: Stanislav Malyshev <stas@zend.com>                          |
00014    +----------------------------------------------------------------------+
00015  */
00016 
00017 #ifdef HAVE_CONFIG_H
00018 #include "config.h"
00019 #endif
00020 
00021 #include <unicode/ustring.h>
00022 #include "msgformat_data.h"
00023 
00024 /* {{{ void msgformat_data_init( msgformat_data* mf_data )
00025  * Initialize internals of msgformat_data.
00026  */
00027 void msgformat_data_init( msgformat_data* mf_data TSRMLS_DC )
00028 {
00029        if( !mf_data )
00030               return;
00031 
00032        mf_data->umsgf = NULL;
00033        mf_data->orig_format = NULL;
00034        intl_error_reset( &mf_data->error TSRMLS_CC );
00035 }
00036 /* }}} */
00037 
00038 /* {{{ void msgformat_data_free( msgformat_data* mf_data )
00039  * Clean up memory allocated for msgformat_data
00040  */
00041 void msgformat_data_free( msgformat_data* mf_data TSRMLS_DC )
00042 {
00043        if( !mf_data )
00044               return;
00045 
00046        if( mf_data->umsgf )
00047               umsg_close( mf_data->umsgf );
00048 
00049        if(mf_data->orig_format) {
00050               efree(mf_data->orig_format);
00051               mf_data->orig_format = NULL;
00052        }
00053 
00054        mf_data->umsgf = NULL;
00055        intl_error_reset( &mf_data->error TSRMLS_CC );
00056 }
00057 /* }}} */
00058 
00059 /* {{{ msgformat_data* msgformat_data_create()
00060  * Allocate memory for msgformat_data and initialize it with default values.
00061  */
00062 msgformat_data* msgformat_data_create( TSRMLS_D )
00063 {
00064        msgformat_data* mf_data = ecalloc( 1, sizeof(msgformat_data) );
00065 
00066        msgformat_data_init( mf_data TSRMLS_CC );
00067 
00068        return mf_data;
00069 }
00070 /* }}} */
00071 
00072 int msgformat_fix_quotes(UChar **spattern, uint32_t *spattern_len, UErrorCode *ec) 
00073 {
00074        if(*spattern && *spattern_len && u_strchr(*spattern, (UChar)'\'')) {
00075               UChar *npattern = emalloc(sizeof(UChar)*(2*(*spattern_len)+1));
00076               uint32_t npattern_len;
00077               npattern_len = umsg_autoQuoteApostrophe(*spattern, *spattern_len, npattern, 2*(*spattern_len)+1, ec);
00078               efree(*spattern);
00079               if( U_FAILURE(*ec) )
00080               {
00081                      return FAILURE;
00082               }
00083               npattern = erealloc(npattern, sizeof(UChar)*(npattern_len+1));
00084               *spattern = npattern;
00085               *spattern_len = npattern_len;
00086        }
00087        return SUCCESS;
00088 }
00089 
00090 
00091 /*
00092  * Local variables:
00093  * tab-width: 4
00094  * c-basic-offset: 4
00095  * End:
00096  * vim600: noet sw=4 ts=4 fdm=marker
00097  * vim<600: noet sw=4 ts=4
00098  */