php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
collator_create.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: Vadim Savchuk <vsavchuk@productengine.com> |
12 | Dmitry Lakhtyuk <dlakhtyuk@productengine.com> |
13 +----------------------------------------------------------------------+
14 */
15
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "php_intl.h"
21#include "collator_class.h"
22#include "intl_data.h"
23
24/* {{{ */
25static int collator_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handling *error_handling, bool *error_handling_replaced)
26{
27 char* locale;
28 size_t locale_len = 0;
29 zval* object;
31
33 object = return_value;
35 Z_PARAM_STRING(locale, locale_len)
37
38 if (error_handling != NULL) {
40 *error_handling_replaced = 1;
41 }
42
45
46 if(locale_len == 0) {
47 locale = (char *)intl_locale_get_default();
48 }
49
50 /* Open ICU collator. */
51 co->ucoll = ucol_open( locale, COLLATOR_ERROR_CODE_P( co ) );
52 INTL_CTOR_CHECK_STATUS(co, "collator_create: unable to open ICU collator");
53 return SUCCESS;
54}
55/* }}} */
56
57/* {{{ Create collator. */
66/* }}} */
67
68/* {{{ Collator object constructor. */
69PHP_METHOD( Collator, __construct )
70{
71 zend_error_handling error_handling;
72 bool error_handling_replaced = 0;
73
75 if (collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, &error_handling, &error_handling_replaced) == FAILURE) {
76 if (!EG(exception)) {
77 zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
78 }
79 }
80 if (error_handling_replaced) {
81 zend_restore_error_handling(&error_handling);
82 }
83}
84/* }}} */
bool exception
Definition assert.c:30
zend_class_entry * Collator_ce_ptr
#define COLLATOR_ERROR_CODE_P(co)
#define COLLATOR_METHOD_FETCH_OBJECT
#define NULL
Definition gdcache.h:45
#define SUCCESS
Definition hash_sha3.c:261
foreach($dp as $el) foreach( $dp as $el) if( $pass2< 2) echo ""
zend_class_entry * IntlException_ce_ptr
Definition intl_error.c:30
#define INTL_CTOR_CHECK_STATUS(obj, msg)
Definition intl_data.h:95
#define INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len)
Definition intl_data.h:125
void intl_error_reset(intl_error *err)
Definition intl_error.c:78
#define PHP_FUNCTION
Definition php.h:364
#define PHP_METHOD
Definition php.h:365
const char * intl_locale_get_default(void)
Definition php_intl.c:91
collator_create(string $locale)
UCollator * ucoll
#define INTERNAL_FUNCTION_PARAMETERS
Definition zend.h:49
@ EH_THROW
Definition zend.h:433
ZEND_API void zend_replace_error_handling(zend_error_handling_t error_handling, zend_class_entry *exception_class, zend_error_handling *current)
Definition zend_API.c:5242
ZEND_API void zend_restore_error_handling(zend_error_handling *saved)
Definition zend_API.c:5253
#define INTERNAL_FUNCTION_PARAM_PASSTHRU
Definition zend.h:50
ZEND_API zend_result object_init_ex(zval *arg, zend_class_entry *class_type)
Definition zend_API.c:1849
#define RETURN_NULL()
Definition zend_API.h:1036
#define Z_PARAM_STRING(dest, dest_len)
Definition zend_API.h:2071
#define ZEND_PARSE_PARAMETERS_END_EX(failure)
Definition zend_API.h:1630
#define ZEND_PARSE_PARAMETERS_START(min_num_args, max_num_args)
Definition zend_API.h:1620
#define ZEND_THIS
Definition zend_API.h:523
struct _zval_struct zval
ZEND_API ZEND_COLD zend_object * zend_throw_exception(zend_class_entry *exception_ce, const char *message, zend_long code)
#define EG(v)
@ FAILURE
Definition zend_types.h:61
ZEND_API void zval_ptr_dtor(zval *zval_ptr)
zval * return_value
object