First public contribution.
2 **********************************************************************
3 * Copyright (C) 2000-2005, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
11 #include "unicode/ures.h"
15 #define kRootLocaleName "root"
18 The default minor version and the version separator must be exactly one
22 #define kDefaultMinorVersion "0"
23 #define kVersionSeparator "."
24 #define kVersionTag "Version"
26 #define MAGIC1 19700503
27 #define MAGIC2 19641227
29 #define URES_MAX_ALIAS_LEVEL 256
30 #define URES_MAX_BUFFER_SIZE 256
36 ENTRY_GOTO_DEFAULT = 2,
40 typedef enum UResEntryType UResEntryType;
43 struct UResourceDataEntry;
44 typedef struct UResourceDataEntry UResourceDataEntry;
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;*/
54 int32_t fHashKey; /* for faster access in the hashtable */
57 #define RES_BUFSIZE 64
58 #define RES_PATH_SEPARATOR '/'
59 #define RES_PATH_SEPARATOR_S "/"
61 struct UResourceBundle {
62 const char *fKey; /*tag*/
63 UResourceDataEntry *fData; /*for low-level access*/
65 char *fResPath; /* full path to the resource: "zh_TW/CollationElements/Sequence" */
66 char fResBuf[RES_BUFSIZE];
70 uint32_t fMagic1; /* For determining if it's a stack object */
71 uint32_t fMagic2; /* For determining if it's a stack object */
74 ResourceData fResData;
77 UResourceDataEntry *fTopLevelData; /* for getting the valid locale */
78 const UResourceBundle *fParentRes; /* needed to get the actual locale for a child resource */
82 U_CAPI void U_EXPORT2 ures_initStackObject(UResourceBundle* resB);
84 /* Some getters used by the copy constructor */
85 U_CFUNC const char* ures_getName(const UResourceBundle* resB);
86 U_CFUNC const char* ures_getPath(const UResourceBundle* resB);
87 U_CFUNC void ures_appendResPath(UResourceBundle *resB, const char* toAdd, int32_t lenToAdd);
88 /*U_CFUNC void ures_setResPath(UResourceBundle *resB, const char* toAdd);*/
89 U_CFUNC void ures_freeResPath(UResourceBundle *resB);
91 /* Candidates for export */
92 U_CFUNC UResourceBundle *ures_copyResb(UResourceBundle *r, const UResourceBundle *original, UErrorCode *status);
95 * Returns a resource that can be located using the pathToResource argument. One needs optional package, locale
96 * and path inside the locale, for example: "/myData/en/zoneStrings/3". Keys and indexes are supported. Keys
97 * need to reference data in named structures, while indexes can reference both named and anonymous resources.
98 * Features a fill-in parameter.
100 * Note, this function does NOT have a syntax for specifying items within a tree. May want to consider a
101 * syntax that delineates between package/tree and resource.
103 * @param pathToResource a path that will lead to the requested resource
104 * @param fillIn if NULL a new UResourceBundle struct is allocated and must be deleted by the caller.
105 * Alternatively, you can supply a struct to be filled by this function.
106 * @param status fills in the outgoing error code.
107 * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
110 U_CAPI UResourceBundle* U_EXPORT2
111 ures_findResource(const char* pathToResource,
112 UResourceBundle *fillIn, UErrorCode *status);
115 * Returns a sub resource that can be located using the pathToResource argument. One needs a path inside
116 * the supplied resource, for example, if you have "en_US" resource bundle opened, you might ask for
117 * "zoneStrings/3". Keys and indexes are supported. Keys
118 * need to reference data in named structures, while indexes can reference both
119 * named and anonymous resources.
120 * Features a fill-in parameter.
122 * @param resourceBundle a resource
123 * @param pathToResource a path that will lead to the requested resource
124 * @param fillIn if NULL a new UResourceBundle struct is allocated and must be deleted by the caller.
125 * Alternatively, you can supply a struct to be filled by this function.
126 * @param status fills in the outgoing error code.
127 * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
130 U_CAPI UResourceBundle* U_EXPORT2
131 ures_findSubResource(const UResourceBundle *resB,
132 char* pathToResource,
133 UResourceBundle *fillIn, UErrorCode *status);
136 * Returns a functionally equivalent locale (considering keywords) for the specified keyword.
137 * @param result fillin for the equivalent locale
138 * @param resultCapacity capacity of the fillin buffer
139 * @param path path to the tree, or NULL for ICU data
140 * @param resName top level resource. Example: "collations"
141 * @param keyword locale keyword. Example: "collation"
142 * @param locid The requested locale
143 * @param isAvailable If non-null, pointer to fillin parameter that indicates whether the
144 * requested locale was available. The locale is defined as 'available' if it physically
145 * exists within the specified tree.
146 * @param omitDefault if TRUE, omit keyword and value if default. 'de_DE\@collation=standard' -> 'de_DE'
147 * @param status error code
148 * @return the actual buffer size needed for the full locale. If it's greater
149 * than resultCapacity, the returned full name will be truncated and an error code will be returned.
152 U_INTERNAL int32_t U_EXPORT2
153 ures_getFunctionalEquivalent(char *result, int32_t resultCapacity,
154 const char *path, const char *resName, const char *keyword, const char *locid,
155 UBool *isAvailable, UBool omitDefault, UErrorCode *status);
158 * Given a tree path and keyword, return a string enumeration of all possible values for that keyword.
159 * @param path path to the tree, or NULL for ICU data
160 * @param keyword a particular keyword to consider, must match a top level resource name
162 * @param status error code
165 U_INTERNAL UEnumeration* U_EXPORT2
166 ures_getKeywordValues(const char *path, const char *keyword, UErrorCode *status);