php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
msgformat_attr.c
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | This source file is subject to version 3.01 of the PHP license, |
4 | that is bundled with this package in the file LICENSE, and is |
5 | available through the world-wide-web at the following url: |
6 | https://www.php.net/license/3_01.txt |
7 | If you did not receive a copy of the PHP license and are unable to |
8 | obtain it through the world-wide-web, please send a note to |
9 | license@php.net so we can mail you a copy immediately. |
10 +----------------------------------------------------------------------+
11 | Authors: Stanislav Malyshev <stas@zend.com> |
12 +----------------------------------------------------------------------+
13 */
14
15#ifdef HAVE_CONFIG_H
16#include <config.h>
17#endif
18
19#include "php_intl.h"
20#include "msgformat_class.h"
21#include "msgformat_data.h"
22#include "intl_convert.h"
23
24#include <unicode/ustring.h>
25
26/* {{{ Get formatter pattern. */
28{
30
31 /* Parse parameters. */
33 {
35 }
36
37 /* Fetch the object. */
39
40 if(mfo->mf_data.orig_format) {
41 RETURN_STRINGL(mfo->mf_data.orig_format, mfo->mf_data.orig_format_len);
42 }
43
45}
46/* }}} */
47
48/* {{{ Set formatter pattern. */
50{
51 char* value = NULL;
52 size_t value_len = 0;
53 int32_t spattern_len = 0;
54 UChar* spattern = NULL;
55 UParseError spattern_error = {0};
57
58 /* Parse parameters. */
60 &object, MessageFormatter_ce_ptr, &value, &value_len ) == FAILURE )
61 {
63 }
64
66
67 /* Convert given pattern to UTF-16. */
68 intl_convert_utf8_to_utf16(&spattern, &spattern_len, value, value_len, &INTL_DATA_ERROR_CODE(mfo));
69 INTL_METHOD_CHECK_STATUS(mfo, "Error converting pattern to UTF-16" );
70
71#ifdef MSG_FORMAT_QUOTE_APOS
72 if(msgformat_fix_quotes(&spattern, &spattern_len, &INTL_DATA_ERROR_CODE(mfo)) != SUCCESS) {
74 "msgfmt_set_pattern: error converting pattern to quote-friendly format", 0 );
76 }
77#endif
78
79 umsg_applyPattern(MSG_FORMAT_OBJECT(mfo), spattern, spattern_len, &spattern_error, &INTL_DATA_ERROR_CODE(mfo));
80 if (spattern) {
81 efree(spattern);
82 }
83 if (U_FAILURE(INTL_DATA_ERROR_CODE(mfo))) {
84 char *msg;
85 spprintf(&msg, 0, "Error setting symbol value at line %d, offset %d", spattern_error.line, spattern_error.offset);
87 efree(msg);
89 }
90
91 if(mfo->mf_data.orig_format) {
92 efree(mfo->mf_data.orig_format);
93 }
94 mfo->mf_data.orig_format = estrndup(value, value_len);
95 mfo->mf_data.orig_format_len = value_len;
96 /* invalidate cached format types */
97 if (mfo->mf_data.arg_types) {
98 zend_hash_destroy(mfo->mf_data.arg_types);
99 efree(mfo->mf_data.arg_types);
100 mfo->mf_data.arg_types = NULL;
101 }
102
104}
105/* }}} */
106
107/* {{{ Get formatter locale. */
109{
110 char *loc;
112
113 /* Parse parameters. */
115 &object, MessageFormatter_ce_ptr ) == FAILURE )
116 {
118 }
119
120 /* Fetch the object. */
122
123 loc = (char *)umsg_getLocale(MSG_FORMAT_OBJECT(mfo));
124 RETURN_STRING(loc);
125}
126/* }}} */
const U_INVALID_FORMAT_ERROR
#define NULL
Definition gdcache.h:45
#define SUCCESS
Definition hash_sha3.c:261
void intl_convert_utf8_to_utf16(UChar **target, int32_t *target_len, const char *src, size_t src_len, UErrorCode *status)
#define INTL_DATA_ERROR_P(obj)
Definition intl_data.h:39
#define INTL_DATA_ERROR_CODE(obj)
Definition intl_data.h:40
#define INTL_METHOD_CHECK_STATUS(obj, msg)
Definition intl_data.h:66
void intl_errors_set_custom_msg(intl_error *err, const char *msg, int copyMsg)
Definition intl_error.c:187
void intl_error_set(intl_error *err, UErrorCode code, const char *msg, int copyMsg)
Definition intl_error.c:161
zend_class_entry * MessageFormatter_ce_ptr
#define MSG_FORMAT_METHOD_INIT_VARS
#define MSG_FORMAT_METHOD_FETCH_OBJECT
#define MSG_FORMAT_OBJECT(mfo)
#define PHP_FUNCTION
Definition php.h:364
msgfmt_get_pattern(MessageFormatter $formatter)
msgfmt_set_pattern(MessageFormatter $formatter, string $pattern)
msgfmt_get_locale(MessageFormatter $formatter)
char * msg
Definition phpdbg.h:289
#define spprintf
Definition spprintf.h:29
ZEND_API zend_result zend_parse_method_parameters(uint32_t num_args, zval *this_ptr, const char *type_spec,...)
Definition zend_API.c:1314
#define ZEND_NUM_ARGS()
Definition zend_API.h:530
#define RETURN_STRING(s)
Definition zend_API.h:1043
#define RETURN_STRINGL(s, l)
Definition zend_API.h:1044
#define RETURN_FALSE
Definition zend_API.h:1058
#define RETURN_THROWS()
Definition zend_API.h:1060
#define getThis()
Definition zend_API.h:526
#define RETURN_TRUE
Definition zend_API.h:1059
#define estrndup(s, length)
Definition zend_alloc.h:165
#define efree(ptr)
Definition zend_alloc.h:155
ZEND_API void ZEND_FASTCALL zend_hash_destroy(HashTable *ht)
Definition zend_hash.c:1727
@ FAILURE
Definition zend_types.h:61
value