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