collator_attr.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | This source file is subject to version 3.01 of the PHP license, |
  6. | that is bundled with this package in the file LICENSE, and is |
  7. | available through the world-wide-web at the following url: |
  8. | http://www.php.net/license/3_01.txt |
  9. | If you did not receive a copy of the PHP license and are unable to |
  10. | obtain it through the world-wide-web, please send a note to |
  11. | license@php.net so we can mail you a copy immediately. |
  12. +----------------------------------------------------------------------+
  13. | Authors: Vadim Savchuk <vsavchuk@productengine.com> |
  14. | Dmitry Lakhtyuk <dlakhtyuk@productengine.com> |
  15. +----------------------------------------------------------------------+
  16. */
  17. #ifdef HAVE_CONFIG_H
  18. #include "config.h"
  19. #endif
  20. #include "php_intl.h"
  21. #include "collator_class.h"
  22. #include "collator_convert.h"
  23. #include "collator_attr.h"
  24. #include <unicode/ustring.h>
  25. /* {{{ proto int Collator::getAttribute( int $attr )
  26. * Get collation attribute value. }}} */
  27. /* {{{ proto int collator_get_attribute( Collator $coll, int $attr )
  28. * Get collation attribute value.
  29. */
  30. PHP_FUNCTION( collator_get_attribute )
  31. {
  32. long attribute, value;
  33. COLLATOR_METHOD_INIT_VARS
  34. /* Parse parameters. */
  35. if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol",
  36. &object, Collator_ce_ptr, &attribute ) == FAILURE )
  37. {
  38. intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
  39. "collator_get_attribute: unable to parse input params", 0 TSRMLS_CC );
  40. RETURN_FALSE;
  41. }
  42. /* Fetch the object. */
  43. COLLATOR_METHOD_FETCH_OBJECT;
  44. value = ucol_getAttribute( co->ucoll, attribute, COLLATOR_ERROR_CODE_P( co ) );
  45. COLLATOR_CHECK_STATUS( co, "Error getting attribute value" );
  46. RETURN_LONG( value );
  47. }
  48. /* }}} */
  49. /* {{{ proto bool Collator::getAttribute( int $attr )
  50. * Get collation attribute value. }}} */
  51. /* {{{ proto bool collator_set_attribute( Collator $coll, int $attr, int $val )
  52. * Set collation attribute.
  53. */
  54. PHP_FUNCTION( collator_set_attribute )
  55. {
  56. long attribute, value;
  57. COLLATOR_METHOD_INIT_VARS
  58. /* Parse parameters. */
  59. if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oll",
  60. &object, Collator_ce_ptr, &attribute, &value ) == FAILURE)
  61. {
  62. intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
  63. "collator_set_attribute: unable to parse input params", 0 TSRMLS_CC );
  64. RETURN_FALSE;
  65. }
  66. /* Fetch the object. */
  67. COLLATOR_METHOD_FETCH_OBJECT;
  68. /* Set new value for the given attribute. */
  69. ucol_setAttribute( co->ucoll, attribute, value, COLLATOR_ERROR_CODE_P( co ) );
  70. COLLATOR_CHECK_STATUS( co, "Error setting attribute value" );
  71. RETURN_TRUE;
  72. }
  73. /* }}} */
  74. /* {{{ proto int Collator::getStrength()
  75. * Returns the current collation strength. }}} */
  76. /* {{{ proto int collator_get_strength(Collator coll)
  77. * Returns the current collation strength.
  78. */
  79. PHP_FUNCTION( collator_get_strength )
  80. {
  81. COLLATOR_METHOD_INIT_VARS
  82. /* Parse parameters. */
  83. if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
  84. &object, Collator_ce_ptr ) == FAILURE )
  85. {
  86. intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
  87. "collator_get_strength: unable to parse input params", 0 TSRMLS_CC );
  88. RETURN_FALSE;
  89. }
  90. /* Fetch the object. */
  91. COLLATOR_METHOD_FETCH_OBJECT;
  92. /* Get current strength and return it. */
  93. RETURN_LONG( ucol_getStrength( co->ucoll ) );
  94. }
  95. /* }}} */
  96. /* {{{ proto bool Collator::setStrength(int strength)
  97. * Set the collation strength. }}} */
  98. /* {{{ proto bool collator_set_strength(Collator coll, int strength)
  99. * Set the collation strength.
  100. */
  101. PHP_FUNCTION( collator_set_strength )
  102. {
  103. long strength;
  104. COLLATOR_METHOD_INIT_VARS
  105. /* Parse parameters. */
  106. if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol",
  107. &object, Collator_ce_ptr, &strength ) == FAILURE )
  108. {
  109. intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
  110. "collator_set_strength: unable to parse input params", 0 TSRMLS_CC );
  111. RETURN_FALSE;
  112. }
  113. /* Fetch the object. */
  114. COLLATOR_METHOD_FETCH_OBJECT;
  115. /* Set given strength. */
  116. ucol_setStrength( co->ucoll, strength );
  117. RETURN_TRUE;
  118. }
  119. /* }}} */
  120. /*
  121. * Local variables:
  122. * tab-width: 4
  123. * c-basic-offset: 4
  124. * End:
  125. * vim600: noet sw=4 ts=4 fdm=marker
  126. * vim<600: noet sw=4 ts=4
  127. */