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