• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 **********************************************************************
3 *   Copyright (C) 2000-2009, 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     UResourceDataEntry *fParent; /*next resource in fallback chain*/
50     ResourceData fData; /* data for low level access */
51     char fNameBuffer[3]; /* A small buffer of free space for fName. The free space is due to struct padding. */
52     uint32_t fCountExisting; /* how much is this resource used */
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     UResourceDataEntry *fTopLevelData; /* for getting the valid locale */
66     char *fResPath; /* full path to the resource: "zh_TW/CollationElements/Sequence" */
67     ResourceData fResData;
68     char fResBuf[RES_BUFSIZE];
69     int32_t fResPathLen;
70     Resource fRes;
71     UBool fHasFallback;
72     UBool fIsTopLevel;
73     uint32_t fMagic1;   /* For determining if it's a stack object */
74     uint32_t fMagic2;   /* For determining if it's a stack object */
75     int32_t fIndex;
76     int32_t fSize;
77 
78     /*const UResourceBundle *fParentRes;*/ /* needed to get the actual locale for a child resource */
79 };
80 
81 U_CAPI void U_EXPORT2 ures_initStackObject(UResourceBundle* resB);
82 
83 /* Some getters used by the copy constructor */
84 U_CFUNC const char* ures_getName(const UResourceBundle* resB);
85 #ifdef URES_DEBUG
86 U_CFUNC const char* ures_getPath(const UResourceBundle* resB);
87 #endif
88 /*U_CFUNC void ures_appendResPath(UResourceBundle *resB, const char* toAdd, int32_t lenToAdd);*/
89 /*U_CFUNC void ures_setResPath(UResourceBundle *resB, const char* toAdd);*/
90 /*U_CFUNC void ures_freeResPath(UResourceBundle *resB);*/
91 
92 /* Candidates for export */
93 U_CFUNC UResourceBundle *ures_copyResb(UResourceBundle *r, const UResourceBundle *original, UErrorCode *status);
94 
95 /**
96  * Returns a resource that can be located using the pathToResource argument. One needs optional package, locale
97  * and path inside the locale, for example: "/myData/en/zoneStrings/3". Keys and indexes are supported. Keys
98  * need to reference data in named structures, while indexes can reference both named and anonymous resources.
99  * Features a fill-in parameter.
100  *
101  * Note, this function does NOT have a syntax for specifying items within a tree.  May want to consider a
102  * syntax that delineates between package/tree and resource.
103  *
104  * @param pathToResource    a path that will lead to the requested resource
105  * @param fillIn            if NULL a new UResourceBundle struct is allocated and must be deleted by the caller.
106  *                          Alternatively, you can supply a struct to be filled by this function.
107  * @param status            fills in the outgoing error code.
108  * @return                  a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
109  * @draft ICU 2.2
110  */
111 U_CAPI UResourceBundle* U_EXPORT2
112 ures_findResource(const char* pathToResource,
113                   UResourceBundle *fillIn, UErrorCode *status);
114 
115 /**
116  * Returns a sub resource that can be located using the pathToResource argument. One needs a path inside
117  * the supplied resource, for example, if you have "en_US" resource bundle opened, you might ask for
118  * "zoneStrings/3". Keys and indexes are supported. Keys
119  * need to reference data in named structures, while indexes can reference both
120  * named and anonymous resources.
121  * Features a fill-in parameter.
122  *
123  * @param resourceBundle    a resource
124  * @param pathToResource    a path that will lead to the requested resource
125  * @param fillIn            if NULL a new UResourceBundle struct is allocated and must be deleted by the caller.
126  *                          Alternatively, you can supply a struct to be filled by this function.
127  * @param status            fills in the outgoing error code.
128  * @return                  a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
129  * @draft ICU 2.2
130  */
131 U_CAPI UResourceBundle* U_EXPORT2
132 ures_findSubResource(const UResourceBundle *resB,
133                      char* pathToResource,
134                      UResourceBundle *fillIn, UErrorCode *status);
135 
136 /**
137  * Returns a functionally equivalent locale (considering keywords) for the specified keyword.
138  * @param result fillin for the equivalent locale
139  * @param resultCapacity capacity of the fillin buffer
140  * @param path path to the tree, or NULL for ICU data
141  * @param resName top level resource. Example: "collations"
142  * @param keyword locale keyword. Example: "collation"
143  * @param locid The requested locale
144  * @param isAvailable If non-null, pointer to fillin parameter that indicates whether the
145  * requested locale was available. The locale is defined as 'available' if it physically
146  * exists within the specified tree.
147  * @param omitDefault if TRUE, omit keyword and value if default. 'de_DE\@collation=standard' -> 'de_DE'
148  * @param status error code
149  * @return  the actual buffer size needed for the full locale.  If it's greater
150  * than resultCapacity, the returned full name will be truncated and an error code will be returned.
151  * @internal ICU 3.0
152  */
153 U_INTERNAL int32_t U_EXPORT2
154 ures_getFunctionalEquivalent(char *result, int32_t resultCapacity,
155                              const char *path, const char *resName, const char *keyword, const char *locid,
156                              UBool *isAvailable, UBool omitDefault, UErrorCode *status);
157 
158 /**
159  * Given a tree path and keyword, return a string enumeration of all possible values for that keyword.
160  * @param path path to the tree, or NULL for ICU data
161  * @param keyword a particular keyword to consider, must match a top level resource name
162  * within the tree.
163  * @param status error code
164  * @internal ICU 3.0
165  */
166 U_INTERNAL UEnumeration* U_EXPORT2
167 ures_getKeywordValues(const char *path, const char *keyword, UErrorCode *status);
168 
169 
170 /**
171  * Get a resource with multi-level fallback. Normally only the top level resources will
172  * fallback to its parent. This performs fallback on subresources. For example, when a table
173  * is defined in a resource bundle and a parent resource bundle, normally no fallback occurs
174  * on the sub-resources because the table is defined in the current resource bundle, but this
175  * function can perform fallback on the sub-resources of the table.
176  * @param resB              a resource
177  * @param inKey             a key associated with the requested resource
178  * @param fillIn            if NULL a new UResourceBundle struct is allocated and must be deleted by the caller.
179  *                          Alternatively, you can supply a struct to be filled by this function.
180  * @param status: fills in the outgoing error code
181  *                could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
182  *                could be a non-failing error
183  *                e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
184  * @return                  a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
185  * @internal ICU 3.0
186  */
187 U_INTERNAL UResourceBundle* U_EXPORT2
188 ures_getByKeyWithFallback(const UResourceBundle *resB,
189                           const char* inKey,
190                           UResourceBundle *fillIn,
191                           UErrorCode *status);
192 
193 
194 /**
195  * Get a String with multi-level fallback. Normally only the top level resources will
196  * fallback to its parent. This performs fallback on subresources. For example, when a table
197  * is defined in a resource bundle and a parent resource bundle, normally no fallback occurs
198  * on the sub-resources because the table is defined in the current resource bundle, but this
199  * function can perform fallback on the sub-resources of the table.
200  * @param resB              a resource
201  * @param inKey             a key associated with the requested resource
202  * @param status: fills in the outgoing error code
203  *                could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
204  *                could be a non-failing error
205  *                e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
206  * @return                  a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
207  * @internal ICU 3.4
208  * @draft ICU 3.4
209  */
210 U_INTERNAL const UChar* U_EXPORT2
211 ures_getStringByKeyWithFallback(const UResourceBundle *resB,
212                           const char* inKey,
213                           int32_t* len,
214                           UErrorCode *status);
215 
216 /**
217  * Get a version number by key
218  * @param resB bundle containing version number
219  * @param key the key for the version number
220  * @param ver fillin for the version number
221  * @param status error code
222  * @internal ICU 4.2
223  */
224 U_INTERNAL void U_EXPORT2
225 ures_getVersionByKey(const UResourceBundle *resB,
226                      const char *key,
227                      UVersionInfo ver,
228                      UErrorCode *status);
229 
230 
231 #endif /*URESIMP_H*/
232