Back to index

php5  5.3.10
common_error.c
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | This source file is subject to version 3.01 of the PHP license,      |
00006    | that is bundled with this package in the file LICENSE, and is        |
00007    | available through the world-wide-web at the following url:           |
00008    | http://www.php.net/license/3_01.txt                                  |
00009    | If you did not receive a copy of the PHP license and are unable to   |
00010    | obtain it through the world-wide-web, please send a note to          |
00011    | license@php.net so we can mail you a copy immediately.               |
00012    +----------------------------------------------------------------------+
00013    | Authors: Vadim Savchuk <vsavchuk@productengine.com>                  |
00014    |          Dmitry Lakhtyuk <dlakhtyuk@productengine.com>               |
00015    +----------------------------------------------------------------------+
00016  */
00017 
00018 #ifdef HAVE_CONFIG_H
00019 #include "config.h"
00020 #endif
00021 
00022 #include "php_intl.h"
00023 #include "intl_error.h"
00024 #include "common_error.h"
00025 
00026 /* {{{ proto int intl_get_error_code()
00027  * Get code of the last occured error.
00028  */
00029 PHP_FUNCTION( intl_get_error_code )
00030 {
00031        RETURN_LONG( intl_error_get_code( NULL TSRMLS_CC ) );
00032 }
00033 /* }}} */
00034 
00035 /* {{{ proto string intl_get_error_message()
00036  * Get text description of the last occured error.
00037  */
00038 PHP_FUNCTION( intl_get_error_message )
00039 {
00040        char* message = intl_error_get_message( NULL TSRMLS_CC );
00041        RETURN_STRING( message, FALSE );
00042 }
00043 /* }}} */
00044 
00045 /* {{{ proto bool intl_is_failure()
00046  * Check whether the given error code indicates a failure.
00047  * Returns true if it does, and false if the code
00048  * indicates success or a warning.
00049  */
00050 PHP_FUNCTION( intl_is_failure )
00051 {
00052        long err_code;
00053 
00054        /* Parse parameters. */
00055        if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "l",
00056               &err_code ) == FAILURE )
00057        {
00058               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
00059                      "intl_is_failure: unable to parse input params", 0 TSRMLS_CC );
00060 
00061               RETURN_FALSE;
00062        }
00063 
00064        RETURN_BOOL( U_FAILURE( err_code ) );
00065 }
00066 
00067 /* {{{ proto string intl_error_name()
00068  * Return a string for a given error code.
00069  * The string will be the same as the name of the error code constant.
00070  */
00071 PHP_FUNCTION( intl_error_name )
00072 {
00073        long err_code;
00074 
00075        /* Parse parameters. */
00076        if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "l",
00077               &err_code ) == FAILURE )
00078        {
00079               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
00080                      "intl_error_name: unable to parse input params", 0 TSRMLS_CC );
00081 
00082               RETURN_FALSE;
00083        }
00084 
00085        RETURN_STRING( (char*)u_errorName( err_code ), 1 );
00086 }
00087 /* }}} */
00088 
00089 /* {{{ intl_expose_icu_error_codes
00090  * Expose ICU error codes
00091  */
00092 void intl_expose_icu_error_codes( INIT_FUNC_ARGS )
00093 {
00094        #define INTL_EXPOSE_CONST(x) REGISTER_LONG_CONSTANT(#x, x, CONST_CS)
00095 
00096        /* Warnings */
00097        INTL_EXPOSE_CONST( U_USING_FALLBACK_WARNING );
00098        INTL_EXPOSE_CONST( U_ERROR_WARNING_START );
00099        INTL_EXPOSE_CONST( U_USING_DEFAULT_WARNING );
00100        INTL_EXPOSE_CONST( U_SAFECLONE_ALLOCATED_WARNING );
00101        INTL_EXPOSE_CONST( U_STATE_OLD_WARNING );
00102        INTL_EXPOSE_CONST( U_STRING_NOT_TERMINATED_WARNING );
00103        INTL_EXPOSE_CONST( U_SORT_KEY_TOO_SHORT_WARNING );
00104        INTL_EXPOSE_CONST( U_AMBIGUOUS_ALIAS_WARNING );
00105        INTL_EXPOSE_CONST( U_DIFFERENT_UCA_VERSION );
00106        INTL_EXPOSE_CONST( U_ERROR_WARNING_LIMIT );
00107 
00108        /* Standard errors */
00109        INTL_EXPOSE_CONST( U_ZERO_ERROR );
00110        INTL_EXPOSE_CONST( U_ILLEGAL_ARGUMENT_ERROR );
00111        INTL_EXPOSE_CONST( U_MISSING_RESOURCE_ERROR );
00112        INTL_EXPOSE_CONST( U_INVALID_FORMAT_ERROR );
00113        INTL_EXPOSE_CONST( U_FILE_ACCESS_ERROR );
00114        INTL_EXPOSE_CONST( U_INTERNAL_PROGRAM_ERROR );
00115        INTL_EXPOSE_CONST( U_MESSAGE_PARSE_ERROR );
00116        INTL_EXPOSE_CONST( U_MEMORY_ALLOCATION_ERROR );
00117        INTL_EXPOSE_CONST( U_INDEX_OUTOFBOUNDS_ERROR );
00118        INTL_EXPOSE_CONST( U_PARSE_ERROR );
00119        INTL_EXPOSE_CONST( U_INVALID_CHAR_FOUND );
00120        INTL_EXPOSE_CONST( U_TRUNCATED_CHAR_FOUND );
00121        INTL_EXPOSE_CONST( U_ILLEGAL_CHAR_FOUND );
00122        INTL_EXPOSE_CONST( U_INVALID_TABLE_FORMAT );
00123        INTL_EXPOSE_CONST( U_INVALID_TABLE_FILE );
00124        INTL_EXPOSE_CONST( U_BUFFER_OVERFLOW_ERROR );
00125        INTL_EXPOSE_CONST( U_UNSUPPORTED_ERROR );
00126        INTL_EXPOSE_CONST( U_RESOURCE_TYPE_MISMATCH );
00127        INTL_EXPOSE_CONST( U_ILLEGAL_ESCAPE_SEQUENCE );
00128        INTL_EXPOSE_CONST( U_UNSUPPORTED_ESCAPE_SEQUENCE );
00129        INTL_EXPOSE_CONST( U_NO_SPACE_AVAILABLE );
00130        INTL_EXPOSE_CONST( U_CE_NOT_FOUND_ERROR );
00131        INTL_EXPOSE_CONST( U_PRIMARY_TOO_LONG_ERROR );
00132        INTL_EXPOSE_CONST( U_STATE_TOO_OLD_ERROR );
00133        INTL_EXPOSE_CONST( U_TOO_MANY_ALIASES_ERROR );
00134        INTL_EXPOSE_CONST( U_ENUM_OUT_OF_SYNC_ERROR );
00135        INTL_EXPOSE_CONST( U_INVARIANT_CONVERSION_ERROR );
00136        INTL_EXPOSE_CONST( U_INVALID_STATE_ERROR );
00137        INTL_EXPOSE_CONST( U_COLLATOR_VERSION_MISMATCH );
00138        INTL_EXPOSE_CONST( U_USELESS_COLLATOR_ERROR );
00139        INTL_EXPOSE_CONST( U_NO_WRITE_PERMISSION );
00140        INTL_EXPOSE_CONST( U_STANDARD_ERROR_LIMIT );
00141 
00142        /* The error code range 0x10000 0x10100 are reserved for Transliterator */
00143        INTL_EXPOSE_CONST( U_BAD_VARIABLE_DEFINITION );
00144        INTL_EXPOSE_CONST( U_PARSE_ERROR_START );
00145        INTL_EXPOSE_CONST( U_MALFORMED_RULE );
00146        INTL_EXPOSE_CONST( U_MALFORMED_SET );
00147        INTL_EXPOSE_CONST( U_MALFORMED_SYMBOL_REFERENCE );
00148        INTL_EXPOSE_CONST( U_MALFORMED_UNICODE_ESCAPE );
00149        INTL_EXPOSE_CONST( U_MALFORMED_VARIABLE_DEFINITION );
00150        INTL_EXPOSE_CONST( U_MALFORMED_VARIABLE_REFERENCE );
00151        INTL_EXPOSE_CONST( U_MISMATCHED_SEGMENT_DELIMITERS );
00152        INTL_EXPOSE_CONST( U_MISPLACED_ANCHOR_START );
00153        INTL_EXPOSE_CONST( U_MISPLACED_CURSOR_OFFSET );
00154        INTL_EXPOSE_CONST( U_MISPLACED_QUANTIFIER );
00155        INTL_EXPOSE_CONST( U_MISSING_OPERATOR );
00156        INTL_EXPOSE_CONST( U_MISSING_SEGMENT_CLOSE );
00157        INTL_EXPOSE_CONST( U_MULTIPLE_ANTE_CONTEXTS );
00158        INTL_EXPOSE_CONST( U_MULTIPLE_CURSORS );
00159        INTL_EXPOSE_CONST( U_MULTIPLE_POST_CONTEXTS );
00160        INTL_EXPOSE_CONST( U_TRAILING_BACKSLASH );
00161        INTL_EXPOSE_CONST( U_UNDEFINED_SEGMENT_REFERENCE );
00162        INTL_EXPOSE_CONST( U_UNDEFINED_VARIABLE );
00163        INTL_EXPOSE_CONST( U_UNQUOTED_SPECIAL );
00164        INTL_EXPOSE_CONST( U_UNTERMINATED_QUOTE );
00165        INTL_EXPOSE_CONST( U_RULE_MASK_ERROR );
00166        INTL_EXPOSE_CONST( U_MISPLACED_COMPOUND_FILTER );
00167        INTL_EXPOSE_CONST( U_MULTIPLE_COMPOUND_FILTERS );
00168        INTL_EXPOSE_CONST( U_INVALID_RBT_SYNTAX );
00169        INTL_EXPOSE_CONST( U_INVALID_PROPERTY_PATTERN );
00170        INTL_EXPOSE_CONST( U_MALFORMED_PRAGMA );
00171        INTL_EXPOSE_CONST( U_UNCLOSED_SEGMENT );
00172        INTL_EXPOSE_CONST( U_ILLEGAL_CHAR_IN_SEGMENT );
00173        INTL_EXPOSE_CONST( U_VARIABLE_RANGE_EXHAUSTED );
00174        INTL_EXPOSE_CONST( U_VARIABLE_RANGE_OVERLAP );
00175        INTL_EXPOSE_CONST( U_ILLEGAL_CHARACTER );
00176        INTL_EXPOSE_CONST( U_INTERNAL_TRANSLITERATOR_ERROR );
00177        INTL_EXPOSE_CONST( U_INVALID_ID );
00178        INTL_EXPOSE_CONST( U_INVALID_FUNCTION );
00179        INTL_EXPOSE_CONST( U_PARSE_ERROR_LIMIT );
00180 
00181        /* The error code range 0x10100 0x10200 are reserved for formatting API parsing error */
00182        INTL_EXPOSE_CONST( U_UNEXPECTED_TOKEN );
00183        INTL_EXPOSE_CONST( U_FMT_PARSE_ERROR_START );
00184        INTL_EXPOSE_CONST( U_MULTIPLE_DECIMAL_SEPARATORS );
00185        INTL_EXPOSE_CONST( U_MULTIPLE_DECIMAL_SEPERATORS );    /* Typo: kept for backward compatibility. Use U_MULTIPLE_DECIMAL_SEPARATORS */
00186        INTL_EXPOSE_CONST( U_MULTIPLE_EXPONENTIAL_SYMBOLS );
00187        INTL_EXPOSE_CONST( U_MALFORMED_EXPONENTIAL_PATTERN );
00188        INTL_EXPOSE_CONST( U_MULTIPLE_PERCENT_SYMBOLS );
00189        INTL_EXPOSE_CONST( U_MULTIPLE_PERMILL_SYMBOLS );
00190        INTL_EXPOSE_CONST( U_MULTIPLE_PAD_SPECIFIERS );
00191        INTL_EXPOSE_CONST( U_PATTERN_SYNTAX_ERROR );
00192        INTL_EXPOSE_CONST( U_ILLEGAL_PAD_POSITION );
00193        INTL_EXPOSE_CONST( U_UNMATCHED_BRACES );
00194        INTL_EXPOSE_CONST( U_UNSUPPORTED_PROPERTY );
00195        INTL_EXPOSE_CONST( U_UNSUPPORTED_ATTRIBUTE );
00196        INTL_EXPOSE_CONST( U_FMT_PARSE_ERROR_LIMIT );
00197 
00198        /* The error code range 0x10200 0x102ff are reserved for Break Iterator related error */
00199        INTL_EXPOSE_CONST( U_BRK_INTERNAL_ERROR );
00200        INTL_EXPOSE_CONST( U_BRK_ERROR_START );
00201        INTL_EXPOSE_CONST( U_BRK_HEX_DIGITS_EXPECTED );
00202        INTL_EXPOSE_CONST( U_BRK_SEMICOLON_EXPECTED );
00203        INTL_EXPOSE_CONST( U_BRK_RULE_SYNTAX );
00204        INTL_EXPOSE_CONST( U_BRK_UNCLOSED_SET );
00205        INTL_EXPOSE_CONST( U_BRK_ASSIGN_ERROR );
00206        INTL_EXPOSE_CONST( U_BRK_VARIABLE_REDFINITION );
00207        INTL_EXPOSE_CONST( U_BRK_MISMATCHED_PAREN );
00208        INTL_EXPOSE_CONST( U_BRK_NEW_LINE_IN_QUOTED_STRING );
00209        INTL_EXPOSE_CONST( U_BRK_UNDEFINED_VARIABLE );
00210        INTL_EXPOSE_CONST( U_BRK_INIT_ERROR );
00211        INTL_EXPOSE_CONST( U_BRK_RULE_EMPTY_SET );
00212        INTL_EXPOSE_CONST( U_BRK_UNRECOGNIZED_OPTION );
00213        INTL_EXPOSE_CONST( U_BRK_MALFORMED_RULE_TAG );
00214        INTL_EXPOSE_CONST( U_BRK_ERROR_LIMIT );
00215 
00216        /* The error codes in the range 0x10300-0x103ff are reserved for regular expression related errrs */
00217        INTL_EXPOSE_CONST( U_REGEX_INTERNAL_ERROR );
00218        INTL_EXPOSE_CONST( U_REGEX_ERROR_START );
00219        INTL_EXPOSE_CONST( U_REGEX_RULE_SYNTAX );
00220        INTL_EXPOSE_CONST( U_REGEX_INVALID_STATE );
00221        INTL_EXPOSE_CONST( U_REGEX_BAD_ESCAPE_SEQUENCE );
00222        INTL_EXPOSE_CONST( U_REGEX_PROPERTY_SYNTAX );
00223        INTL_EXPOSE_CONST( U_REGEX_UNIMPLEMENTED );
00224        INTL_EXPOSE_CONST( U_REGEX_MISMATCHED_PAREN );
00225        INTL_EXPOSE_CONST( U_REGEX_NUMBER_TOO_BIG );
00226        INTL_EXPOSE_CONST( U_REGEX_BAD_INTERVAL );
00227        INTL_EXPOSE_CONST( U_REGEX_MAX_LT_MIN );
00228        INTL_EXPOSE_CONST( U_REGEX_INVALID_BACK_REF );
00229        INTL_EXPOSE_CONST( U_REGEX_INVALID_FLAG );
00230        INTL_EXPOSE_CONST( U_REGEX_LOOK_BEHIND_LIMIT );
00231        INTL_EXPOSE_CONST( U_REGEX_SET_CONTAINS_STRING );
00232        INTL_EXPOSE_CONST( U_REGEX_ERROR_LIMIT );
00233 
00234        /* The error code in the range 0x10400-0x104ff are reserved for IDNA related error codes */
00235 #if defined(U_IDNA_PROHIBITED_ERROR)
00236        INTL_EXPOSE_CONST( U_IDNA_PROHIBITED_ERROR );
00237        INTL_EXPOSE_CONST( U_IDNA_ERROR_START );
00238        INTL_EXPOSE_CONST( U_IDNA_UNASSIGNED_ERROR );
00239        INTL_EXPOSE_CONST( U_IDNA_CHECK_BIDI_ERROR );
00240        INTL_EXPOSE_CONST( U_IDNA_STD3_ASCII_RULES_ERROR );
00241        INTL_EXPOSE_CONST( U_IDNA_ACE_PREFIX_ERROR );
00242        INTL_EXPOSE_CONST( U_IDNA_VERIFICATION_ERROR );
00243        INTL_EXPOSE_CONST( U_IDNA_LABEL_TOO_LONG_ERROR );
00244        INTL_EXPOSE_CONST( U_IDNA_ZERO_LENGTH_LABEL_ERROR );
00245        INTL_EXPOSE_CONST( U_IDNA_ERROR_LIMIT );
00246 #endif
00247 
00248        /* Aliases for StringPrep */
00249        INTL_EXPOSE_CONST( U_STRINGPREP_PROHIBITED_ERROR );
00250        INTL_EXPOSE_CONST( U_STRINGPREP_UNASSIGNED_ERROR );
00251        INTL_EXPOSE_CONST( U_STRINGPREP_CHECK_BIDI_ERROR );
00252 
00253        INTL_EXPOSE_CONST( U_ERROR_LIMIT );
00254 
00255        #undef INTL_EXPOSE_CONST
00256 }
00257 /* }}} */
00258 
00259 /*
00260  * Local variables:
00261  * tab-width: 4
00262  * c-basic-offset: 4
00263  * End:
00264  * vim600: noet sw=4 ts=4 fdm=marker
00265  * vim<600: noet sw=4 ts=4
00266  */