resourcebundle.c 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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: Hans-Peter Oeri (University of St.Gallen) <hp@oeri.ch> |
  14. +----------------------------------------------------------------------+
  15. */
  16. #include <unicode/ures.h>
  17. #include <zend.h>
  18. #include <zend_API.h>
  19. #include "intl_convert.h"
  20. #include "intl_data.h"
  21. #include "resourcebundle/resourcebundle_class.h"
  22. /* {{{ ResourceBundle_extract_value */
  23. void resourcebundle_extract_value( zval *return_value, ResourceBundle_object *source TSRMLS_DC )
  24. {
  25. UResType restype;
  26. const UChar* ufield;
  27. const uint8_t* bfield;
  28. const int32_t* vfield;
  29. int32_t ilen;
  30. int i;
  31. long lfield;
  32. ResourceBundle_object* newrb;
  33. restype = ures_getType( source->child );
  34. switch (restype)
  35. {
  36. case URES_STRING:
  37. ufield = ures_getString( source->child, &ilen, &INTL_DATA_ERROR_CODE(source) );
  38. INTL_METHOD_CHECK_STATUS(source, "Failed to retrieve string value");
  39. INTL_METHOD_RETVAL_UTF8(source, (UChar *)ufield, ilen, 0);
  40. break;
  41. case URES_BINARY:
  42. bfield = ures_getBinary( source->child, &ilen, &INTL_DATA_ERROR_CODE(source) );
  43. INTL_METHOD_CHECK_STATUS(source, "Failed to retrieve binary value");
  44. ZVAL_STRINGL( return_value, (char *) bfield, ilen, 1 );
  45. break;
  46. case URES_INT:
  47. lfield = ures_getInt( source->child, &INTL_DATA_ERROR_CODE(source) );
  48. INTL_METHOD_CHECK_STATUS(source, "Failed to retrieve integer value");
  49. ZVAL_LONG( return_value, lfield );
  50. break;
  51. case URES_INT_VECTOR:
  52. vfield = ures_getIntVector( source->child, &ilen, &INTL_DATA_ERROR_CODE(source) );
  53. INTL_METHOD_CHECK_STATUS(source, "Failed to retrieve vector value");
  54. array_init( return_value );
  55. for (i=0; i<ilen; i++) {
  56. add_next_index_long( return_value, vfield[i] );
  57. }
  58. break;
  59. case URES_ARRAY:
  60. case URES_TABLE:
  61. object_init_ex( return_value, ResourceBundle_ce_ptr );
  62. newrb = (ResourceBundle_object *) zend_object_store_get_object( return_value TSRMLS_CC );
  63. newrb->me = source->child;
  64. source->child = NULL;
  65. intl_errors_reset(INTL_DATA_ERROR_P(source) TSRMLS_CC);
  66. break;
  67. default:
  68. intl_errors_set(INTL_DATA_ERROR_P(source), U_ILLEGAL_ARGUMENT_ERROR, "Unknown resource type", 0 TSRMLS_CC);
  69. RETURN_FALSE;
  70. break;
  71. }
  72. }
  73. /* }}} */
  74. /*
  75. * Local variables:
  76. * tab-width: 4
  77. * c-basic-offset: 4
  78. * End:
  79. * vim600: noet sw=4 ts=4 fdm=marker
  80. * vim<600: noet sw=4 ts=4
  81. */