]> git.saurik.com Git - apple/icu.git/blob - icuSources/common/uresimp.h
ICU-511.35.tar.gz
[apple/icu.git] / icuSources / common / uresimp.h
1 /*
2 **********************************************************************
3 * Copyright (C) 2000-2011, International Business Machines
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"
16 #define kPoolBundleName "pool"
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
31 #define URES_MAX_BUFFER_SIZE 256
32
33 #define EMPTY_SET 0x2205
34
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
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 */
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 */
58 UResourceDataEntry *fParent; /*next resource in fallback chain*/
59 UResourceDataEntry *fAlias;
60 UResourceDataEntry *fPool;
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 */
64 UErrorCode fBogus;
65 /* int32_t fHashKey;*/ /* for faster access in the hashtable */
66 };
67
68 #define RES_BUFSIZE 64
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;
76 UResourceDataEntry *fTopLevelData; /* for getting the valid locale */
77 char *fResPath; /* full path to the resource: "zh_TW/CollationElements/Sequence" */
78 ResourceData fResData;
79 char fResBuf[RES_BUFSIZE];
80 int32_t fResPathLen;
81 Resource fRes;
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;
88
89 /*const UResourceBundle *fParentRes;*/ /* needed to get the actual locale for a child resource */
90 };
91
92 U_CAPI void U_EXPORT2 ures_initStackObject(UResourceBundle* resB);
93
94 /* Some getters used by the copy constructor */
95 U_CFUNC const char* ures_getName(const UResourceBundle* resB);
96 #ifdef URES_DEBUG
97 U_CFUNC const char* ures_getPath(const UResourceBundle* resB);
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);
103 #endif
104 /*U_CFUNC void ures_appendResPath(UResourceBundle *resB, const char* toAdd, int32_t lenToAdd);*/
105 /*U_CFUNC void ures_setResPath(UResourceBundle *resB, const char* toAdd);*/
106 /*U_CFUNC void ures_freeResPath(UResourceBundle *resB);*/
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.
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.
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
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
144 */
145 U_CAPI UResourceBundle* U_EXPORT2
146 ures_findSubResource(const UResourceBundle *resB,
147 char* pathToResource,
148 UResourceBundle *fillIn, UErrorCode *status);
149
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 */
166 U_CAPI int32_t U_EXPORT2
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
177 */
178 U_CAPI UEnumeration* U_EXPORT2
179 ures_getKeywordValues(const char *path, const char *keyword, UErrorCode *status);
180
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
197 */
198 U_CAPI UResourceBundle* U_EXPORT2
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
218 */
219 U_CAPI const UChar* U_EXPORT2
220 ures_getStringByKeyWithFallback(const UResourceBundle *resB,
221 const char* inKey,
222 int32_t* len,
223 UErrorCode *status);
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
231 */
232 U_CAPI void U_EXPORT2
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
247 */
248 U_CAPI const char* U_EXPORT2
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 *
258 * This internal version avoids deprecated-warnings in ICU code.
259 *
260 * @param resourceBundle resource bundle in question
261 * @param status just for catching illegal arguments
262 * @return A Locale name
263 */
264 U_CAPI const char* U_EXPORT2
265 ures_getLocaleInternal(const UResourceBundle* resourceBundle,
266 UErrorCode* status);
267
268 #endif /*URESIMP_H*/