]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /* |
2 | ********************************************************************** | |
4388f060 | 3 | * Copyright (C) 2000-2011, International Business Machines |
b75a7d8f A |
4 | * Corporation and others. All Rights Reserved. |
5 | ********************************************************************** | |
6 | */ | |
7 | ||
8 | #ifndef URESIMP_H | |
9 | #define URESIMP_H | |
10 | ||
11 | #include "unicode/ures.h" | |
12 | ||
13 | #include "uresdata.h" | |
14 | ||
15 | #define kRootLocaleName "root" | |
729e4ab9 | 16 | #define kPoolBundleName "pool" |
b75a7d8f A |
17 | |
18 | /* | |
19 | The default minor version and the version separator must be exactly one | |
20 | character long. | |
21 | */ | |
22 | ||
23 | #define kDefaultMinorVersion "0" | |
24 | #define kVersionSeparator "." | |
25 | #define kVersionTag "Version" | |
26 | ||
27 | #define MAGIC1 19700503 | |
28 | #define MAGIC2 19641227 | |
29 | ||
30 | #define URES_MAX_ALIAS_LEVEL 256 | |
73c04bcf | 31 | #define URES_MAX_BUFFER_SIZE 256 |
b75a7d8f | 32 | |
4388f060 A |
33 | #define EMPTY_SET 0x2205 |
34 | ||
b75a7d8f A |
35 | /* |
36 | enum UResEntryType { | |
37 | ENTRY_OK = 0, | |
38 | ENTRY_GOTO_ROOT = 1, | |
39 | ENTRY_GOTO_DEFAULT = 2, | |
40 | ENTRY_INVALID = 3 | |
41 | }; | |
42 | ||
43 | typedef enum UResEntryType UResEntryType; | |
44 | */ | |
45 | ||
46 | struct UResourceDataEntry; | |
47 | typedef struct UResourceDataEntry UResourceDataEntry; | |
48 | ||
729e4ab9 A |
49 | /* |
50 | * Note: If we wanted to make this structure smaller, then we could try | |
51 | * to use one UResourceDataEntry pointer for fAlias and fPool, with a separate | |
52 | * flag to distinguish whether this struct is for a real bundle with a pool, | |
53 | * or for an alias entry for which we won't use the pool after loading. | |
54 | */ | |
b75a7d8f A |
55 | struct UResourceDataEntry { |
56 | char *fName; /* name of the locale for bundle - still to decide whether it is original or fallback */ | |
57 | char *fPath; /* path to bundle - used for distinguishing between resources with the same name */ | |
b75a7d8f | 58 | UResourceDataEntry *fParent; /*next resource in fallback chain*/ |
729e4ab9 A |
59 | UResourceDataEntry *fAlias; |
60 | UResourceDataEntry *fPool; | |
46f4442e A |
61 | ResourceData fData; /* data for low level access */ |
62 | char fNameBuffer[3]; /* A small buffer of free space for fName. The free space is due to struct padding. */ | |
63 | uint32_t fCountExisting; /* how much is this resource used */ | |
b75a7d8f | 64 | UErrorCode fBogus; |
46f4442e | 65 | /* int32_t fHashKey;*/ /* for faster access in the hashtable */ |
b75a7d8f A |
66 | }; |
67 | ||
374ca955 | 68 | #define RES_BUFSIZE 64 |
b75a7d8f A |
69 | #define RES_PATH_SEPARATOR '/' |
70 | #define RES_PATH_SEPARATOR_S "/" | |
71 | ||
72 | struct UResourceBundle { | |
73 | const char *fKey; /*tag*/ | |
74 | UResourceDataEntry *fData; /*for low-level access*/ | |
75 | char *fVersion; | |
46f4442e | 76 | UResourceDataEntry *fTopLevelData; /* for getting the valid locale */ |
b75a7d8f | 77 | char *fResPath; /* full path to the resource: "zh_TW/CollationElements/Sequence" */ |
46f4442e | 78 | ResourceData fResData; |
b75a7d8f A |
79 | char fResBuf[RES_BUFSIZE]; |
80 | int32_t fResPathLen; | |
46f4442e | 81 | Resource fRes; |
b75a7d8f A |
82 | UBool fHasFallback; |
83 | UBool fIsTopLevel; | |
84 | uint32_t fMagic1; /* For determining if it's a stack object */ | |
85 | uint32_t fMagic2; /* For determining if it's a stack object */ | |
86 | int32_t fIndex; | |
87 | int32_t fSize; | |
374ca955 | 88 | |
46f4442e | 89 | /*const UResourceBundle *fParentRes;*/ /* needed to get the actual locale for a child resource */ |
b75a7d8f A |
90 | }; |
91 | ||
374ca955 | 92 | U_CAPI void U_EXPORT2 ures_initStackObject(UResourceBundle* resB); |
b75a7d8f A |
93 | |
94 | /* Some getters used by the copy constructor */ | |
95 | U_CFUNC const char* ures_getName(const UResourceBundle* resB); | |
46f4442e | 96 | #ifdef URES_DEBUG |
b75a7d8f | 97 | U_CFUNC const char* ures_getPath(const UResourceBundle* resB); |
729e4ab9 A |
98 | /** |
99 | * If anything was in the RB cache, dump it to the screen. | |
100 | * @return TRUE if there was anything into the cache | |
101 | */ | |
102 | U_CAPI UBool U_EXPORT2 ures_dumpCacheContents(void); | |
46f4442e | 103 | #endif |
73c04bcf | 104 | /*U_CFUNC void ures_appendResPath(UResourceBundle *resB, const char* toAdd, int32_t lenToAdd);*/ |
b75a7d8f | 105 | /*U_CFUNC void ures_setResPath(UResourceBundle *resB, const char* toAdd);*/ |
73c04bcf | 106 | /*U_CFUNC void ures_freeResPath(UResourceBundle *resB);*/ |
b75a7d8f A |
107 | |
108 | /* Candidates for export */ | |
109 | U_CFUNC UResourceBundle *ures_copyResb(UResourceBundle *r, const UResourceBundle *original, UErrorCode *status); | |
110 | ||
111 | /** | |
112 | * Returns a resource that can be located using the pathToResource argument. One needs optional package, locale | |
113 | * and path inside the locale, for example: "/myData/en/zoneStrings/3". Keys and indexes are supported. Keys | |
114 | * need to reference data in named structures, while indexes can reference both named and anonymous resources. | |
115 | * Features a fill-in parameter. | |
374ca955 A |
116 | * |
117 | * Note, this function does NOT have a syntax for specifying items within a tree. May want to consider a | |
118 | * syntax that delineates between package/tree and resource. | |
b75a7d8f A |
119 | * |
120 | * @param pathToResource a path that will lead to the requested resource | |
121 | * @param fillIn if NULL a new UResourceBundle struct is allocated and must be deleted by the caller. | |
122 | * Alternatively, you can supply a struct to be filled by this function. | |
123 | * @param status fills in the outgoing error code. | |
124 | * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it | |
b75a7d8f A |
125 | */ |
126 | U_CAPI UResourceBundle* U_EXPORT2 | |
127 | ures_findResource(const char* pathToResource, | |
128 | UResourceBundle *fillIn, UErrorCode *status); | |
129 | ||
130 | /** | |
131 | * Returns a sub resource that can be located using the pathToResource argument. One needs a path inside | |
132 | * the supplied resource, for example, if you have "en_US" resource bundle opened, you might ask for | |
133 | * "zoneStrings/3". Keys and indexes are supported. Keys | |
134 | * need to reference data in named structures, while indexes can reference both | |
135 | * named and anonymous resources. | |
136 | * Features a fill-in parameter. | |
137 | * | |
138 | * @param resourceBundle a resource | |
139 | * @param pathToResource a path that will lead to the requested resource | |
140 | * @param fillIn if NULL a new UResourceBundle struct is allocated and must be deleted by the caller. | |
141 | * Alternatively, you can supply a struct to be filled by this function. | |
142 | * @param status fills in the outgoing error code. | |
143 | * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it | |
b75a7d8f A |
144 | */ |
145 | U_CAPI UResourceBundle* U_EXPORT2 | |
146 | ures_findSubResource(const UResourceBundle *resB, | |
374ca955 | 147 | char* pathToResource, |
b75a7d8f A |
148 | UResourceBundle *fillIn, UErrorCode *status); |
149 | ||
374ca955 A |
150 | /** |
151 | * Returns a functionally equivalent locale (considering keywords) for the specified keyword. | |
152 | * @param result fillin for the equivalent locale | |
153 | * @param resultCapacity capacity of the fillin buffer | |
154 | * @param path path to the tree, or NULL for ICU data | |
155 | * @param resName top level resource. Example: "collations" | |
156 | * @param keyword locale keyword. Example: "collation" | |
157 | * @param locid The requested locale | |
158 | * @param isAvailable If non-null, pointer to fillin parameter that indicates whether the | |
159 | * requested locale was available. The locale is defined as 'available' if it physically | |
160 | * exists within the specified tree. | |
161 | * @param omitDefault if TRUE, omit keyword and value if default. 'de_DE\@collation=standard' -> 'de_DE' | |
162 | * @param status error code | |
163 | * @return the actual buffer size needed for the full locale. If it's greater | |
164 | * than resultCapacity, the returned full name will be truncated and an error code will be returned. | |
374ca955 | 165 | */ |
4388f060 | 166 | U_CAPI int32_t U_EXPORT2 |
374ca955 A |
167 | ures_getFunctionalEquivalent(char *result, int32_t resultCapacity, |
168 | const char *path, const char *resName, const char *keyword, const char *locid, | |
169 | UBool *isAvailable, UBool omitDefault, UErrorCode *status); | |
170 | ||
171 | /** | |
172 | * Given a tree path and keyword, return a string enumeration of all possible values for that keyword. | |
173 | * @param path path to the tree, or NULL for ICU data | |
174 | * @param keyword a particular keyword to consider, must match a top level resource name | |
175 | * within the tree. | |
176 | * @param status error code | |
374ca955 | 177 | */ |
4388f060 | 178 | U_CAPI UEnumeration* U_EXPORT2 |
374ca955 A |
179 | ures_getKeywordValues(const char *path, const char *keyword, UErrorCode *status); |
180 | ||
73c04bcf A |
181 | |
182 | /** | |
183 | * Get a resource with multi-level fallback. Normally only the top level resources will | |
184 | * fallback to its parent. This performs fallback on subresources. For example, when a table | |
185 | * is defined in a resource bundle and a parent resource bundle, normally no fallback occurs | |
186 | * on the sub-resources because the table is defined in the current resource bundle, but this | |
187 | * function can perform fallback on the sub-resources of the table. | |
188 | * @param resB a resource | |
189 | * @param inKey a key associated with the requested resource | |
190 | * @param fillIn if NULL a new UResourceBundle struct is allocated and must be deleted by the caller. | |
191 | * Alternatively, you can supply a struct to be filled by this function. | |
192 | * @param status: fills in the outgoing error code | |
193 | * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found | |
194 | * could be a non-failing error | |
195 | * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT> | |
196 | * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it | |
73c04bcf | 197 | */ |
4388f060 | 198 | U_CAPI UResourceBundle* U_EXPORT2 |
73c04bcf A |
199 | ures_getByKeyWithFallback(const UResourceBundle *resB, |
200 | const char* inKey, | |
201 | UResourceBundle *fillIn, | |
202 | UErrorCode *status); | |
203 | ||
204 | ||
205 | /** | |
206 | * Get a String with multi-level fallback. Normally only the top level resources will | |
207 | * fallback to its parent. This performs fallback on subresources. For example, when a table | |
208 | * is defined in a resource bundle and a parent resource bundle, normally no fallback occurs | |
209 | * on the sub-resources because the table is defined in the current resource bundle, but this | |
210 | * function can perform fallback on the sub-resources of the table. | |
211 | * @param resB a resource | |
212 | * @param inKey a key associated with the requested resource | |
213 | * @param status: fills in the outgoing error code | |
214 | * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found | |
215 | * could be a non-failing error | |
216 | * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT> | |
217 | * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it | |
73c04bcf | 218 | */ |
4388f060 | 219 | U_CAPI const UChar* U_EXPORT2 |
73c04bcf A |
220 | ures_getStringByKeyWithFallback(const UResourceBundle *resB, |
221 | const char* inKey, | |
222 | int32_t* len, | |
223 | UErrorCode *status); | |
729e4ab9 A |
224 | |
225 | /** | |
226 | * Get a version number by key | |
227 | * @param resB bundle containing version number | |
228 | * @param key the key for the version number | |
229 | * @param ver fillin for the version number | |
230 | * @param status error code | |
729e4ab9 | 231 | */ |
4388f060 | 232 | U_CAPI void U_EXPORT2 |
729e4ab9 A |
233 | ures_getVersionByKey(const UResourceBundle *resB, |
234 | const char *key, | |
235 | UVersionInfo ver, | |
236 | UErrorCode *status); | |
237 | ||
238 | ||
239 | /** | |
240 | * Internal function. | |
241 | * Return the version number associated with this ResourceBundle as a string. | |
242 | * | |
243 | * @param resourceBundle The resource bundle for which the version is checked. | |
244 | * @return A version number string as specified in the resource bundle or its parent. | |
245 | * The caller does not own this string. | |
246 | * @see ures_getVersion | |
729e4ab9 | 247 | */ |
4388f060 | 248 | U_CAPI const char* U_EXPORT2 |
729e4ab9 A |
249 | ures_getVersionNumberInternal(const UResourceBundle *resourceBundle); |
250 | ||
251 | /** | |
252 | * Return the name of the Locale associated with this ResourceBundle. This API allows | |
253 | * you to query for the real locale of the resource. For example, if you requested | |
254 | * "en_US_CALIFORNIA" and only "en_US" bundle exists, "en_US" will be returned. | |
255 | * For subresources, the locale where this resource comes from will be returned. | |
256 | * If fallback has occured, getLocale will reflect this. | |
257 | * | |
4388f060 A |
258 | * This internal version avoids deprecated-warnings in ICU code. |
259 | * | |
729e4ab9 A |
260 | * @param resourceBundle resource bundle in question |
261 | * @param status just for catching illegal arguments | |
262 | * @return A Locale name | |
729e4ab9 | 263 | */ |
4388f060 | 264 | U_CAPI const char* U_EXPORT2 |
729e4ab9 A |
265 | ures_getLocaleInternal(const UResourceBundle* resourceBundle, |
266 | UErrorCode* status); | |
267 | ||
b75a7d8f | 268 | #endif /*URESIMP_H*/ |