resourcebundle.c 2.8 KB

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