2 **********************************************************************
3 * Copyright (C) 2000-2003, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
11 #include "unicode/ures.h"
15 #define kRootLocaleName "root"
18 The default minor version and the version separator must be exactly one
22 #define kDefaultMinorVersion "0"
23 #define kVersionSeparator "."
24 #define kVersionTag "Version"
26 #define MAGIC1 19700503
27 #define MAGIC2 19641227
29 #define URES_MAX_ALIAS_LEVEL 256
35 ENTRY_GOTO_DEFAULT = 2,
39 typedef enum UResEntryType UResEntryType;
42 struct UResourceDataEntry
;
43 typedef struct UResourceDataEntry UResourceDataEntry
;
45 struct UResourceDataEntry
{
46 char *fName
; /* name of the locale for bundle - still to decide whether it is original or fallback */
47 char *fPath
; /* path to bundle - used for distinguishing between resources with the same name */
48 uint32_t fCountExisting
; /* how much is this resource used */
49 ResourceData fData
; /* data for low level access */
50 UResourceDataEntry
*fParent
; /*next resource in fallback chain*/
51 /* UResEntryType fStatus;*/
53 int32_t fHashKey
; /* for faster access in the hashtable */
56 #define RES_BUFSIZE 256
57 #define RES_PATH_SEPARATOR '/'
58 #define RES_PATH_SEPARATOR_S "/"
60 struct UResourceBundle
{
61 const char *fKey
; /*tag*/
62 UResourceDataEntry
*fData
; /*for low-level access*/
64 char *fResPath
; /* full path to the resource: "zh_TW/CollationElements/Sequence" */
65 char fResBuf
[RES_BUFSIZE
];
69 uint32_t fMagic1
; /* For determining if it's a stack object */
70 uint32_t fMagic2
; /* For determining if it's a stack object */
73 ResourceData fResData
;
76 /* parent of this resource -
77 * lives in the same data entry
79 /* This cannot be done right now - need support in genrb */
80 /*Resource fParent; */
83 U_CFUNC
void ures_initStackObject(UResourceBundle
* resB
);
84 U_CFUNC
void ures_setIsStackObject( UResourceBundle
* resB
, UBool state
);
85 U_CFUNC UBool
ures_isStackObject( UResourceBundle
* resB
);
87 /* Some getters used by the copy constructor */
88 U_CFUNC
const char* ures_getName(const UResourceBundle
* resB
);
89 U_CFUNC
const char* ures_getPath(const UResourceBundle
* resB
);
90 U_CFUNC
void ures_appendResPath(UResourceBundle
*resB
, const char* toAdd
, int32_t lenToAdd
);
91 /*U_CFUNC void ures_setResPath(UResourceBundle *resB, const char* toAdd);*/
92 U_CFUNC
void ures_freeResPath(UResourceBundle
*resB
);
94 /* Candidates for export */
95 U_CFUNC UResourceBundle
*ures_copyResb(UResourceBundle
*r
, const UResourceBundle
*original
, UErrorCode
*status
);
98 * Returns a resource that can be located using the pathToResource argument. One needs optional package, locale
99 * and path inside the locale, for example: "/myData/en/zoneStrings/3". Keys and indexes are supported. Keys
100 * need to reference data in named structures, while indexes can reference both named and anonymous resources.
101 * Features a fill-in parameter.
103 * @param pathToResource a path that will lead to the requested resource
104 * @param fillIn if NULL a new UResourceBundle struct is allocated and must be deleted by the caller.
105 * Alternatively, you can supply a struct to be filled by this function.
106 * @param status fills in the outgoing error code.
107 * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
110 U_CAPI UResourceBundle
* U_EXPORT2
111 ures_findResource(const char* pathToResource
,
112 UResourceBundle
*fillIn
, UErrorCode
*status
);
115 * Returns a sub resource that can be located using the pathToResource argument. One needs a path inside
116 * the supplied resource, for example, if you have "en_US" resource bundle opened, you might ask for
117 * "zoneStrings/3". Keys and indexes are supported. Keys
118 * need to reference data in named structures, while indexes can reference both
119 * named and anonymous resources.
120 * Features a fill-in parameter.
122 * @param resourceBundle a resource
123 * @param pathToResource a path that will lead to the requested resource
124 * @param fillIn if NULL a new UResourceBundle struct is allocated and must be deleted by the caller.
125 * Alternatively, you can supply a struct to be filled by this function.
126 * @param status fills in the outgoing error code.
127 * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
130 U_CAPI UResourceBundle
* U_EXPORT2
131 ures_findSubResource(const UResourceBundle
*resB
,
132 const char* pathToResource
,
133 UResourceBundle
*fillIn
, UErrorCode
*status
);