• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 **********************************************************************
3 *   Copyright (C) 2000-2006, 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 
17 /*
18  The default minor version and the version separator must be exactly one
19  character long.
20 */
21 
22 #define kDefaultMinorVersion    "0"
23 #define kVersionSeparator       "."
24 #define kVersionTag             "Version"
25 
26 #define MAGIC1 19700503
27 #define MAGIC2 19641227
28 
29 #define URES_MAX_ALIAS_LEVEL 256
30 #define URES_MAX_BUFFER_SIZE 256
31 
32 /*
33 enum UResEntryType {
34     ENTRY_OK = 0,
35     ENTRY_GOTO_ROOT = 1,
36     ENTRY_GOTO_DEFAULT = 2,
37     ENTRY_INVALID = 3
38 };
39 
40 typedef enum UResEntryType UResEntryType;
41 */
42 
43 struct UResourceDataEntry;
44 typedef struct UResourceDataEntry UResourceDataEntry;
45 
46 struct UResourceDataEntry {
47     char *fName; /* name of the locale for bundle - still to decide whether it is original or fallback */
48     char *fPath; /* path to bundle - used for distinguishing between resources with the same name */
49     uint32_t fCountExisting; /* how much is this resource used */
50     ResourceData fData; /* data for low level access */
51     UResourceDataEntry *fParent; /*next resource in fallback chain*/
52 /*    UResEntryType fStatus;*/
53     UErrorCode fBogus;
54     int32_t fHashKey; /* for faster access in the hashtable */
55 };
56 
57 #define RES_BUFSIZE 64
58 #define RES_PATH_SEPARATOR   '/'
59 #define RES_PATH_SEPARATOR_S   "/"
60 
61 struct UResourceBundle {
62     const char *fKey; /*tag*/
63     UResourceDataEntry *fData; /*for low-level access*/
64     char *fVersion;
65     char *fResPath; /* full path to the resource: "zh_TW/CollationElements/Sequence" */
66     char fResBuf[RES_BUFSIZE];
67     int32_t fResPathLen;
68     UBool fHasFallback;
69     UBool fIsTopLevel;
70     uint32_t fMagic1;   /* For determining if it's a stack object */
71     uint32_t fMagic2;   /* For determining if it's a stack object */
72     int32_t fIndex;
73     int32_t fSize;
74     ResourceData fResData;
75     Resource fRes;
76 
77     UResourceDataEntry *fTopLevelData; /* for getting the valid locale */
78     const UResourceBundle *fParentRes; /* needed to get the actual locale for a child resource */
79 
80 };
81 
82 U_CAPI void U_EXPORT2 ures_initStackObject(UResourceBundle* resB);
83 
84 /* Some getters used by the copy constructor */
85 U_CFUNC const char* ures_getName(const UResourceBundle* resB);
86 #ifdef URES_DEBUG
87 U_CFUNC const char* ures_getPath(const UResourceBundle* resB);
88 #endif
89 /*U_CFUNC void ures_appendResPath(UResourceBundle *resB, const char* toAdd, int32_t lenToAdd);*/
90 /*U_CFUNC void ures_setResPath(UResourceBundle *resB, const char* toAdd);*/
91 /*U_CFUNC void ures_freeResPath(UResourceBundle *resB);*/
92 
93 /* Candidates for export */
94 U_CFUNC UResourceBundle *ures_copyResb(UResourceBundle *r, const UResourceBundle *original, UErrorCode *status);
95 
96 /**
97  * Returns a resource that can be located using the pathToResource argument. One needs optional package, locale
98  * and path inside the locale, for example: "/myData/en/zoneStrings/3". Keys and indexes are supported. Keys
99  * need to reference data in named structures, while indexes can reference both named and anonymous resources.
100  * Features a fill-in parameter.
101  *
102  * Note, this function does NOT have a syntax for specifying items within a tree.  May want to consider a
103  * syntax that delineates between package/tree and resource.
104  *
105  * @param pathToResource    a path that will lead to the requested resource
106  * @param fillIn            if NULL a new UResourceBundle struct is allocated and must be deleted by the caller.
107  *                          Alternatively, you can supply a struct to be filled by this function.
108  * @param status            fills in the outgoing error code.
109  * @return                  a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
110  * @draft ICU 2.2
111  */
112 U_CAPI UResourceBundle* U_EXPORT2
113 ures_findResource(const char* pathToResource,
114                   UResourceBundle *fillIn, UErrorCode *status);
115 
116 /**
117  * Returns a sub resource that can be located using the pathToResource argument. One needs a path inside
118  * the supplied resource, for example, if you have "en_US" resource bundle opened, you might ask for
119  * "zoneStrings/3". Keys and indexes are supported. Keys
120  * need to reference data in named structures, while indexes can reference both
121  * named and anonymous resources.
122  * Features a fill-in parameter.
123  *
124  * @param resourceBundle    a resource
125  * @param pathToResource    a path that will lead to the requested resource
126  * @param fillIn            if NULL a new UResourceBundle struct is allocated and must be deleted by the caller.
127  *                          Alternatively, you can supply a struct to be filled by this function.
128  * @param status            fills in the outgoing error code.
129  * @return                  a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
130  * @draft ICU 2.2
131  */
132 U_CAPI UResourceBundle* U_EXPORT2
133 ures_findSubResource(const UResourceBundle *resB,
134                      char* pathToResource,
135                      UResourceBundle *fillIn, UErrorCode *status);
136 
137 /**
138  * Returns a functionally equivalent locale (considering keywords) for the specified keyword.
139  * @param result fillin for the equivalent locale
140  * @param resultCapacity capacity of the fillin buffer
141  * @param path path to the tree, or NULL for ICU data
142  * @param resName top level resource. Example: "collations"
143  * @param keyword locale keyword. Example: "collation"
144  * @param locid The requested locale
145  * @param isAvailable If non-null, pointer to fillin parameter that indicates whether the
146  * requested locale was available. The locale is defined as 'available' if it physically
147  * exists within the specified tree.
148  * @param omitDefault if TRUE, omit keyword and value if default. 'de_DE\@collation=standard' -> 'de_DE'
149  * @param status error code
150  * @return  the actual buffer size needed for the full locale.  If it's greater
151  * than resultCapacity, the returned full name will be truncated and an error code will be returned.
152  * @internal ICU 3.0
153  */
154 U_INTERNAL int32_t U_EXPORT2
155 ures_getFunctionalEquivalent(char *result, int32_t resultCapacity,
156                              const char *path, const char *resName, const char *keyword, const char *locid,
157                              UBool *isAvailable, UBool omitDefault, UErrorCode *status);
158 
159 /**
160  * Given a tree path and keyword, return a string enumeration of all possible values for that keyword.
161  * @param path path to the tree, or NULL for ICU data
162  * @param keyword a particular keyword to consider, must match a top level resource name
163  * within the tree.
164  * @param status error code
165  * @internal ICU 3.0
166  */
167 U_INTERNAL UEnumeration* U_EXPORT2
168 ures_getKeywordValues(const char *path, const char *keyword, UErrorCode *status);
169 
170 /**
171  * Test if 2 resource bundles are equal
172  * @param res1
173  * @param res2
174  * @param status error code
175  * @internal ICU 3.6
176  */
177 U_INTERNAL UBool U_EXPORT2
178 ures_equal(const UResourceBundle* res1, const UResourceBundle* res2);
179 
180 /**
181  * Clones the given resource bundle
182  * @param res
183  * @param status error code
184  * @internal ICU 3.6
185  */
186 U_INTERNAL UResourceBundle* U_EXPORT2
187 ures_clone(const UResourceBundle* res, UErrorCode* status);
188 
189 /**
190  * Returns the parent bundle. Internal. DONOT close the returned bundle!!!
191  * @param res
192  * @internal ICU 3.6
193  */
194 U_INTERNAL const UResourceBundle* U_EXPORT2
195 ures_getParentBundle(const UResourceBundle* res);
196 
197 
198 /**
199  * Get a resource with multi-level fallback. Normally only the top level resources will
200  * fallback to its parent. This performs fallback on subresources. For example, when a table
201  * is defined in a resource bundle and a parent resource bundle, normally no fallback occurs
202  * on the sub-resources because the table is defined in the current resource bundle, but this
203  * function can perform fallback on the sub-resources of the table.
204  * @param resB              a resource
205  * @param inKey             a key associated with the requested resource
206  * @param fillIn            if NULL a new UResourceBundle struct is allocated and must be deleted by the caller.
207  *                          Alternatively, you can supply a struct to be filled by this function.
208  * @param status: fills in the outgoing error code
209  *                could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
210  *                could be a non-failing error
211  *                e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
212  * @return                  a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
213  * @internal ICU 3.0
214  */
215 U_INTERNAL UResourceBundle* U_EXPORT2
216 ures_getByKeyWithFallback(const UResourceBundle *resB,
217                           const char* inKey,
218                           UResourceBundle *fillIn,
219                           UErrorCode *status);
220 
221 
222 /**
223  * Get a String with multi-level fallback. Normally only the top level resources will
224  * fallback to its parent. This performs fallback on subresources. For example, when a table
225  * is defined in a resource bundle and a parent resource bundle, normally no fallback occurs
226  * on the sub-resources because the table is defined in the current resource bundle, but this
227  * function can perform fallback on the sub-resources of the table.
228  * @param resB              a resource
229  * @param inKey             a key associated with the requested resource
230  * @param status: fills in the outgoing error code
231  *                could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
232  *                could be a non-failing error
233  *                e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
234  * @return                  a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
235  * @internal ICU 3.4
236  * @draft ICU 3.4
237  */
238 U_INTERNAL const UChar* U_EXPORT2
239 ures_getStringByKeyWithFallback(const UResourceBundle *resB,
240                           const char* inKey,
241                           int32_t* len,
242                           UErrorCode *status);
243 #endif /*URESIMP_H*/
244