Back to index

php5  5.3.10
msgformat_attr.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 "php_intl.h"
00022 #include "msgformat_class.h"
00023 #include "msgformat_attr.h"
00024 #include "intl_convert.h"
00025 
00026 #include <unicode/ustring.h>
00027 
00028 
00029 /* {{{ proto string MessageFormatter::getPattern( )
00030  * Get formatter pattern. }}} */
00031 /* {{{ proto string msgfmt_get_pattern( MessageFormatter $mf )
00032  * Get formatter pattern.
00033  */
00034 PHP_FUNCTION( msgfmt_get_pattern )
00035 {
00036        MSG_FORMAT_METHOD_INIT_VARS;
00037 
00038        /* Parse parameters. */
00039        if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &object, MessageFormatter_ce_ptr ) == FAILURE )
00040        {
00041               intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,   
00042                      "msgfmt_get_pattern: unable to parse input params", 0 TSRMLS_CC );
00043               RETURN_FALSE;
00044        }
00045 
00046        /* Fetch the object. */
00047        MSG_FORMAT_METHOD_FETCH_OBJECT;
00048 
00049        if(mfo->mf_data.orig_format) {
00050               RETURN_STRINGL(mfo->mf_data.orig_format, mfo->mf_data.orig_format_len, 1);
00051        }
00052 
00053        RETURN_FALSE;
00054 }
00055 /* }}} */
00056 
00057 /* {{{ proto bool MessageFormatter::setPattern( string $pattern )
00058  * Set formatter pattern. }}} */
00059 /* {{{ proto bool msgfmt_set_pattern( MessageFormatter $mf, string $pattern )
00060  * Set formatter pattern.
00061  */
00062 PHP_FUNCTION( msgfmt_set_pattern )
00063 {
00064        char*       value = NULL;
00065        int         value_len = 0;
00066        int         spattern_len = 0;
00067        UChar*     spattern  = NULL;
00068        MSG_FORMAT_METHOD_INIT_VARS;
00069 
00070        /* Parse parameters. */
00071        if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
00072               &object, MessageFormatter_ce_ptr, &value, &value_len ) == FAILURE )
00073        {
00074               intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,   
00075                      "msgfmt_set_pattern: unable to parse input params", 0 TSRMLS_CC);
00076               RETURN_FALSE;
00077        }
00078 
00079        MSG_FORMAT_METHOD_FETCH_OBJECT;
00080 
00081        /* Convert given pattern to UTF-16. */
00082        intl_convert_utf8_to_utf16(&spattern, &spattern_len, value, value_len, &INTL_DATA_ERROR_CODE(mfo));
00083        INTL_METHOD_CHECK_STATUS(mfo, "Error converting pattern to UTF-16" );
00084 
00085        if(msgformat_fix_quotes(&spattern, &spattern_len, &INTL_DATA_ERROR_CODE(mfo)) != SUCCESS) {
00086               intl_error_set( NULL, U_INVALID_FORMAT_ERROR,
00087                      "msgfmt_set_pattern: error converting pattern to quote-friendly format", 0 TSRMLS_CC );
00088               RETURN_FALSE;
00089        }
00090 
00091        /* TODO: add parse error information */
00092        umsg_applyPattern(MSG_FORMAT_OBJECT(mfo), spattern, spattern_len, NULL, &INTL_DATA_ERROR_CODE(mfo));
00093        if (spattern) {
00094               efree(spattern);
00095        }
00096        INTL_METHOD_CHECK_STATUS(mfo, "Error setting symbol value");
00097 
00098        if(mfo->mf_data.orig_format) {
00099               efree(mfo->mf_data.orig_format);
00100        }
00101        mfo->mf_data.orig_format = estrndup(value, value_len);
00102        mfo->mf_data.orig_format_len = value_len;
00103 
00104        RETURN_TRUE;
00105 }
00106 /* }}} */
00107 
00108 /* {{{ proto string MessageFormatter::getLocale()
00109  * Get formatter locale. }}} */
00110 /* {{{ proto string msgfmt_get_locale(MessageFormatter $mf)
00111  * Get formatter locale.
00112  */
00113 PHP_FUNCTION( msgfmt_get_locale )
00114 {
00115        char *loc;
00116        MSG_FORMAT_METHOD_INIT_VARS;
00117 
00118        /* Parse parameters. */
00119        if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
00120               &object, MessageFormatter_ce_ptr ) == FAILURE )
00121        {
00122               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
00123                      "msgfmt_get_locale: unable to parse input params", 0 TSRMLS_CC );
00124 
00125               RETURN_FALSE;
00126        }
00127 
00128        /* Fetch the object. */
00129        MSG_FORMAT_METHOD_FETCH_OBJECT;
00130 
00131        loc = (char *)umsg_getLocale(MSG_FORMAT_OBJECT(mfo));
00132        RETURN_STRING(loc, 1);
00133 }
00134 /* }}} */
00135 
00136 /*
00137  * Local variables:
00138  * tab-width: 4
00139  * c-basic-offset: 4
00140  * End:
00141  * vim600: noet sw=4 ts=4 fdm=marker
00142  * vim<600: noet sw=4 ts=4
00143  */