xref: /php-src/ext/intl/common/common_error.c (revision 11accb5c)
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 "intl_error.h"
22 
23 /* {{{ Get code of the last occurred error. */
PHP_FUNCTION(intl_get_error_code)24 PHP_FUNCTION( intl_get_error_code )
25 {
26 	ZEND_PARSE_PARAMETERS_NONE();
27 
28 	RETURN_LONG( intl_error_get_code( NULL ) );
29 }
30 /* }}} */
31 
32 /* {{{ Get text description of the last occurred error. */
PHP_FUNCTION(intl_get_error_message)33 PHP_FUNCTION( intl_get_error_message )
34 {
35 	ZEND_PARSE_PARAMETERS_NONE();
36 
37 	RETURN_STR(intl_error_get_message( NULL ));
38 }
39 /* }}} */
40 
41 /* {{{ Check whether the given error code indicates a failure.
42  * Returns true if it does, and false if the code
43  * indicates success or a warning.
44  */
PHP_FUNCTION(intl_is_failure)45 PHP_FUNCTION( intl_is_failure )
46 {
47 	zend_long err_code;
48 
49 	ZEND_PARSE_PARAMETERS_START(1, 1)
50 		Z_PARAM_LONG(err_code)
51 	ZEND_PARSE_PARAMETERS_END();
52 
53 	RETURN_BOOL( U_FAILURE( err_code ) );
54 }
55 /* }}} */
56 
57 /* {{{ Return a string for a given error code.
58  * The string will be the same as the name of the error code constant.
59  */
PHP_FUNCTION(intl_error_name)60 PHP_FUNCTION( intl_error_name )
61 {
62 	zend_long err_code;
63 
64 	ZEND_PARSE_PARAMETERS_START(1, 1)
65 		Z_PARAM_LONG(err_code)
66 	ZEND_PARSE_PARAMETERS_END();
67 
68 	RETURN_STRING( (char*)u_errorName( err_code ) );
69 }
70 /* }}} */
71