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