/*
+----------------------------------------------------------------------+
| Copyright © The PHP Group and Contributors. |
+----------------------------------------------------------------------+
| This source file is subject to the Modified BSD License that is |
| bundled with this package in the file LICENSE, and is available |
| through the World Wide Web at . |
| |
| SPDX-License-Identifier: BSD-3-Clause |
+----------------------------------------------------------------------+
| Authors: Stanislav Malyshev |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include
#endif
#include
extern "C" {
#include "php_intl.h"
#include "msgformat_class.h"
#include "msgformat_data.h"
#include "msgformat_helpers.h"
#include "intl_convert.h"
}
/* {{{ */
static void msgfmt_do_parse(MessageFormatter_object *mfo, char *source, size_t src_len, zval *return_value)
{
zval *fargs;
int count = 0;
int i;
UChar *usource = NULL;
int usrc_len = 0;
intl_convert_utf8_to_utf16(&usource, &usrc_len, source, src_len, &INTL_DATA_ERROR_CODE(mfo));
INTL_METHOD_CHECK_STATUS(mfo, "Converting parse string failed");
umsg_parse_helper(MSG_FORMAT_OBJECT(mfo), &count, &fargs, usource, usrc_len, &INTL_DATA_ERROR_CODE(mfo));
if (usource) {
efree(usource);
}
INTL_METHOD_CHECK_STATUS(mfo, "Parsing failed");
array_init_size(return_value, count);
zend_hash_real_init_packed(Z_ARRVAL_P(return_value));
for(i=0;imf_data);
if(pattern && pattern_len) {
intl_convert_utf8_to_utf16(&spattern, &spattern_len, pattern, pattern_len, &INTL_DATA_ERROR_CODE(mfo));
if( U_FAILURE(INTL_DATA_ERROR_CODE((mfo))) )
{
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
"error converting pattern to UTF-16");
RETURN_FALSE;
}
} else {
spattern_len = 0;
spattern = NULL;
}
if(slocale_len == 0) {
slocale = (char *)intl_locale_get_default();
}
#ifdef MSG_FORMAT_QUOTE_APOS
if(msgformat_fix_quotes(&spattern, &spattern_len, &INTL_DATA_ERROR_CODE(mfo)) != SUCCESS) {
intl_error_set( NULL, U_INVALID_FORMAT_ERROR,
"msgfmt_parse_message: error converting pattern to quote-friendly format", 0 );
RETURN_FALSE;
}
#endif
/* Create an ICU message formatter. */
MSG_FORMAT_OBJECT(mfo) = umsg_open(spattern, spattern_len, slocale, NULL, &INTL_DATA_ERROR_CODE(mfo));
if(spattern && spattern_len) {
efree(spattern);
}
INTL_METHOD_CHECK_STATUS_OR_GOTO(mfo, "Creating message formatter failed", clean);
msgfmt_do_parse(mfo, source, src_len, return_value);
clean:
/* drop the temporary formatter */
msgformat_data_free(&mfo->mf_data);
}
/* }}} */