php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
msgformat_data.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 <unicode/ustring.h>
20#include "msgformat_data.h"
21
22#include "msgformat_class.h"
23
24/* {{{ void msgformat_data_init( msgformat_data* mf_data )
25 * Initialize internals of msgformat_data.
26 */
28{
29 if( !mf_data )
30 return;
31
32 mf_data->umsgf = NULL;
33 mf_data->orig_format = NULL;
34 mf_data->arg_types = NULL;
35 mf_data->tz_set = 0;
36 intl_error_reset( &mf_data->error );
37}
38/* }}} */
39
40/* {{{ void msgformat_data_free( msgformat_data* mf_data )
41 * Clean up memory allocated for msgformat_data
42 */
44{
45 if (!mf_data)
46 return;
47
48 if (mf_data->umsgf)
49 umsg_close(mf_data->umsgf);
50
51 if (mf_data->orig_format) {
52 efree(mf_data->orig_format);
53 mf_data->orig_format = NULL;
54 }
55
56 if (mf_data->arg_types) {
58 efree(mf_data->arg_types);
59 mf_data->arg_types = NULL;
60 }
61
62 mf_data->umsgf = NULL;
63 intl_error_reset(&mf_data->error);
64}
65/* }}} */
66
67/* {{{ msgformat_data* msgformat_data_create()
68 * Allocate memory for msgformat_data and initialize it with default values.
69 */
71{
72 msgformat_data* mf_data = ecalloc( 1, sizeof(msgformat_data) );
73
74 msgformat_data_init( mf_data );
75
76 return mf_data;
77}
78/* }}} */
79
80#ifdef MSG_FORMAT_QUOTE_APOS
81int msgformat_fix_quotes(UChar **spattern, uint32_t *spattern_len, UErrorCode *ec)
82{
83 if(*spattern && *spattern_len && u_strchr(*spattern, (UChar)'\'')) {
84 UChar *npattern = safe_emalloc(sizeof(UChar)*2, *spattern_len, sizeof(UChar));
85 uint32_t npattern_len;
86 npattern_len = umsg_autoQuoteApostrophe(*spattern, *spattern_len, npattern, 2*(*spattern_len)+1, ec);
87 efree(*spattern);
88 if( U_FAILURE(*ec) )
89 {
90 return FAILURE;
91 }
92 npattern = erealloc(npattern, sizeof(UChar)*(npattern_len+1));
93 *spattern = npattern;
94 *spattern_len = npattern_len;
95 }
96 return SUCCESS;
97}
98#endif
#define NULL
Definition gdcache.h:45
#define SUCCESS
Definition hash_sha3.c:261
void intl_error_reset(intl_error *err)
Definition intl_error.c:78
void msgformat_data_free(msgformat_data *mf_data)
msgformat_data * msgformat_data_create(void)
void msgformat_data_init(msgformat_data *mf_data)
UMessageFormat * umsgf
intl_error error
HashTable * arg_types
#define ecalloc(nmemb, size)
Definition zend_alloc.h:158
#define efree(ptr)
Definition zend_alloc.h:155
#define erealloc(ptr, size)
Definition zend_alloc.h:159
#define safe_emalloc(nmemb, size, offset)
Definition zend_alloc.h:154
ZEND_API void ZEND_FASTCALL zend_hash_destroy(HashTable *ht)
Definition zend_hash.c:1727
@ FAILURE
Definition zend_types.h:61