Back to index

php5  5.3.10
collator_attr.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 "collator_class.h"
00024 #include "collator_convert.h"
00025 #include "collator_attr.h"
00026 
00027 #include <unicode/ustring.h>
00028 
00029 /* {{{ proto int Collator::getAttribute( int $attr )
00030  * Get collation attribute value. }}} */
00031 /* {{{ proto int collator_get_attribute( Collator $coll, int $attr )
00032  * Get collation attribute value.
00033  */
00034 PHP_FUNCTION( collator_get_attribute )
00035 {
00036        long attribute, value;
00037 
00038        COLLATOR_METHOD_INIT_VARS
00039 
00040        /* Parse parameters. */
00041        if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol",
00042               &object, Collator_ce_ptr, &attribute ) == FAILURE )
00043        {
00044               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
00045                      "collator_get_attribute: unable to parse input params", 0 TSRMLS_CC );
00046 
00047               RETURN_FALSE;
00048        }
00049 
00050        /* Fetch the object. */
00051        COLLATOR_METHOD_FETCH_OBJECT;
00052 
00053        value = ucol_getAttribute( co->ucoll, attribute, COLLATOR_ERROR_CODE_P( co ) );
00054        COLLATOR_CHECK_STATUS( co, "Error getting attribute value" );
00055 
00056        RETURN_LONG( value );
00057 }
00058 /* }}} */
00059 
00060 /* {{{ proto bool Collator::getAttribute( int $attr )
00061  * Get collation attribute value. }}} */
00062 /* {{{ proto bool collator_set_attribute( Collator $coll, int $attr, int $val )
00063  * Set collation attribute.
00064  */
00065 PHP_FUNCTION( collator_set_attribute )
00066 {
00067        long attribute, value;
00068        COLLATOR_METHOD_INIT_VARS
00069 
00070 
00071        /* Parse parameters. */
00072        if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oll",
00073               &object, Collator_ce_ptr, &attribute, &value ) == FAILURE)
00074        {
00075               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
00076                       "collator_set_attribute: unable to parse input params", 0 TSRMLS_CC );
00077 
00078               RETURN_FALSE;
00079        }
00080 
00081        /* Fetch the object. */
00082        COLLATOR_METHOD_FETCH_OBJECT;
00083 
00084        /* Set new value for the given attribute. */
00085        ucol_setAttribute( co->ucoll, attribute, value, COLLATOR_ERROR_CODE_P( co ) );
00086        COLLATOR_CHECK_STATUS( co, "Error setting attribute value" );
00087 
00088        RETURN_TRUE;
00089 }
00090 /* }}} */
00091 
00092 /* {{{ proto int Collator::getStrength()
00093  * Returns the current collation strength. }}} */
00094 /* {{{ proto int collator_get_strength(Collator coll)
00095  * Returns the current collation strength.
00096  */
00097 PHP_FUNCTION( collator_get_strength )
00098 {
00099        COLLATOR_METHOD_INIT_VARS
00100 
00101        /* Parse parameters. */
00102        if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
00103               &object, Collator_ce_ptr ) == FAILURE )
00104        {
00105               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
00106                       "collator_get_strength: unable to parse input params", 0 TSRMLS_CC );
00107 
00108               RETURN_FALSE;
00109        }
00110 
00111        /* Fetch the object. */
00112        COLLATOR_METHOD_FETCH_OBJECT;
00113 
00114        /* Get current strength and return it. */
00115        RETURN_LONG( ucol_getStrength( co->ucoll ) );
00116 }
00117 /* }}} */
00118 
00119 /* {{{ proto bool Collator::setStrength(int strength)
00120  * Set the collation strength. }}} */
00121 /* {{{ proto bool collator_set_strength(Collator coll, int strength)
00122  * Set the collation strength.
00123  */
00124 PHP_FUNCTION( collator_set_strength )
00125 {
00126        long strength;
00127 
00128        COLLATOR_METHOD_INIT_VARS
00129 
00130        /* Parse parameters. */
00131        if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol",
00132               &object, Collator_ce_ptr, &strength ) == FAILURE )
00133        {
00134               intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
00135                       "collator_set_strength: unable to parse input params", 0 TSRMLS_CC );
00136 
00137               RETURN_FALSE;
00138        }
00139 
00140        /* Fetch the object. */
00141        COLLATOR_METHOD_FETCH_OBJECT;
00142 
00143        /* Set given strength. */
00144        ucol_setStrength( co->ucoll, strength );
00145 
00146        RETURN_TRUE;
00147 }
00148 /* }}} */
00149 
00150 /*
00151  * Local variables:
00152  * tab-width: 4
00153  * c-basic-offset: 4
00154  * End:
00155  * vim600: noet sw=4 ts=4 fdm=marker
00156  * vim<600: noet sw=4 ts=4
00157  */