2001-03-21 20:44:20 +00:00
|
|
|
/*
|
|
|
|
**********************************************************************
|
2010-03-11 20:05:42 +00:00
|
|
|
* Copyright (C) 2000-2010, International Business Machines
|
2001-03-21 20:44:20 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
**********************************************************************
|
|
|
|
*/
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
#ifndef URESIMP_H
|
|
|
|
#define URESIMP_H
|
|
|
|
|
|
|
|
#include "unicode/ures.h"
|
|
|
|
|
|
|
|
#include "uresdata.h"
|
|
|
|
|
|
|
|
#define kRootLocaleName "root"
|
2009-07-17 22:57:26 +00:00
|
|
|
#define kPoolBundleName "pool"
|
2000-05-15 18:39:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
The default minor version and the version separator must be exactly one
|
|
|
|
character long.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define kDefaultMinorVersion "0"
|
|
|
|
#define kVersionSeparator "."
|
|
|
|
#define kVersionTag "Version"
|
|
|
|
|
2000-07-12 22:59:57 +00:00
|
|
|
#define MAGIC1 19700503
|
|
|
|
#define MAGIC2 19641227
|
|
|
|
|
2002-06-24 20:58:17 +00:00
|
|
|
#define URES_MAX_ALIAS_LEVEL 256
|
2005-04-01 07:57:40 +00:00
|
|
|
#define URES_MAX_BUFFER_SIZE 256
|
2002-06-24 20:58:17 +00:00
|
|
|
|
2001-10-10 18:05:10 +00:00
|
|
|
/*
|
2000-05-15 18:39:17 +00:00
|
|
|
enum UResEntryType {
|
|
|
|
ENTRY_OK = 0,
|
|
|
|
ENTRY_GOTO_ROOT = 1,
|
|
|
|
ENTRY_GOTO_DEFAULT = 2,
|
|
|
|
ENTRY_INVALID = 3
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef enum UResEntryType UResEntryType;
|
2001-10-10 18:05:10 +00:00
|
|
|
*/
|
2000-05-15 18:39:17 +00:00
|
|
|
|
|
|
|
struct UResourceDataEntry;
|
|
|
|
typedef struct UResourceDataEntry UResourceDataEntry;
|
|
|
|
|
2009-07-17 22:57:26 +00:00
|
|
|
/*
|
|
|
|
* Note: If we wanted to make this structure smaller, then we could try
|
|
|
|
* to use one UResourceDataEntry pointer for fAlias and fPool, with a separate
|
|
|
|
* flag to distinguish whether this struct is for a real bundle with a pool,
|
|
|
|
* or for an alias entry for which we won't use the pool after loading.
|
|
|
|
*/
|
2000-05-15 18:39:17 +00:00
|
|
|
struct UResourceDataEntry {
|
|
|
|
char *fName; /* name of the locale for bundle - still to decide whether it is original or fallback */
|
|
|
|
char *fPath; /* path to bundle - used for distinguishing between resources with the same name */
|
|
|
|
UResourceDataEntry *fParent; /*next resource in fallback chain*/
|
2009-07-17 22:57:26 +00:00
|
|
|
UResourceDataEntry *fAlias;
|
|
|
|
UResourceDataEntry *fPool;
|
2008-02-19 05:59:10 +00:00
|
|
|
ResourceData fData; /* data for low level access */
|
2008-02-19 07:09:38 +00:00
|
|
|
char fNameBuffer[3]; /* A small buffer of free space for fName. The free space is due to struct padding. */
|
2008-02-19 05:59:10 +00:00
|
|
|
uint32_t fCountExisting; /* how much is this resource used */
|
2000-05-15 18:39:17 +00:00
|
|
|
UErrorCode fBogus;
|
2008-02-19 05:59:10 +00:00
|
|
|
/* int32_t fHashKey;*/ /* for faster access in the hashtable */
|
2000-05-15 18:39:17 +00:00
|
|
|
};
|
|
|
|
|
2003-11-07 08:59:52 +00:00
|
|
|
#define RES_BUFSIZE 64
|
2002-06-24 20:58:17 +00:00
|
|
|
#define RES_PATH_SEPARATOR '/'
|
|
|
|
#define RES_PATH_SEPARATOR_S "/"
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
struct UResourceBundle {
|
|
|
|
const char *fKey; /*tag*/
|
2003-02-28 05:59:24 +00:00
|
|
|
UResourceDataEntry *fData; /*for low-level access*/
|
|
|
|
char *fVersion;
|
2008-02-19 17:27:59 +00:00
|
|
|
UResourceDataEntry *fTopLevelData; /* for getting the valid locale */
|
2002-06-24 20:58:17 +00:00
|
|
|
char *fResPath; /* full path to the resource: "zh_TW/CollationElements/Sequence" */
|
2008-02-19 17:27:59 +00:00
|
|
|
ResourceData fResData;
|
2002-06-24 20:58:17 +00:00
|
|
|
char fResBuf[RES_BUFSIZE];
|
|
|
|
int32_t fResPathLen;
|
2008-02-19 17:27:59 +00:00
|
|
|
Resource fRes;
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool fHasFallback;
|
|
|
|
UBool fIsTopLevel;
|
2003-02-28 05:59:24 +00:00
|
|
|
uint32_t fMagic1; /* For determining if it's a stack object */
|
|
|
|
uint32_t fMagic2; /* For determining if it's a stack object */
|
2000-05-15 18:39:17 +00:00
|
|
|
int32_t fIndex;
|
|
|
|
int32_t fSize;
|
2003-11-07 08:59:52 +00:00
|
|
|
|
2008-02-19 17:27:59 +00:00
|
|
|
/*const UResourceBundle *fParentRes;*/ /* needed to get the actual locale for a child resource */
|
2000-05-15 18:39:17 +00:00
|
|
|
};
|
|
|
|
|
2003-08-13 20:52:53 +00:00
|
|
|
U_CAPI void U_EXPORT2 ures_initStackObject(UResourceBundle* resB);
|
2000-05-15 18:39:17 +00:00
|
|
|
|
2001-07-27 17:15:30 +00:00
|
|
|
/* Some getters used by the copy constructor */
|
|
|
|
U_CFUNC const char* ures_getName(const UResourceBundle* resB);
|
2006-11-15 00:38:04 +00:00
|
|
|
#ifdef URES_DEBUG
|
2001-07-27 17:15:30 +00:00
|
|
|
U_CFUNC const char* ures_getPath(const UResourceBundle* resB);
|
2010-03-11 20:05:42 +00:00
|
|
|
/**
|
|
|
|
* If anything was in the RB cache, dump it to the screen.
|
|
|
|
* @return TRUE if there was anything into the cache
|
|
|
|
*/
|
|
|
|
U_CAPI UBool U_EXPORT2 ures_dumpCacheContents(void);
|
2006-11-15 00:38:04 +00:00
|
|
|
#endif
|
2006-04-25 19:32:35 +00:00
|
|
|
/*U_CFUNC void ures_appendResPath(UResourceBundle *resB, const char* toAdd, int32_t lenToAdd);*/
|
2002-06-24 20:58:17 +00:00
|
|
|
/*U_CFUNC void ures_setResPath(UResourceBundle *resB, const char* toAdd);*/
|
2006-04-25 19:32:35 +00:00
|
|
|
/*U_CFUNC void ures_freeResPath(UResourceBundle *resB);*/
|
2001-07-27 17:15:30 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
/* Candidates for export */
|
2001-10-04 00:12:19 +00:00
|
|
|
U_CFUNC UResourceBundle *ures_copyResb(UResourceBundle *r, const UResourceBundle *original, UErrorCode *status);
|
2002-07-13 05:36:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a resource that can be located using the pathToResource argument. One needs optional package, locale
|
|
|
|
* and path inside the locale, for example: "/myData/en/zoneStrings/3". Keys and indexes are supported. Keys
|
|
|
|
* need to reference data in named structures, while indexes can reference both named and anonymous resources.
|
|
|
|
* Features a fill-in parameter.
|
2004-04-15 07:55:48 +00:00
|
|
|
*
|
|
|
|
* Note, this function does NOT have a syntax for specifying items within a tree. May want to consider a
|
|
|
|
* syntax that delineates between package/tree and resource.
|
2002-07-13 05:36:27 +00:00
|
|
|
*
|
|
|
|
* @param pathToResource a path that will lead to the requested resource
|
|
|
|
* @param fillIn if NULL a new UResourceBundle struct is allocated and must be deleted by the caller.
|
|
|
|
* Alternatively, you can supply a struct to be filled by this function.
|
|
|
|
* @param status fills in the outgoing error code.
|
|
|
|
* @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
|
|
|
|
* @draft ICU 2.2
|
|
|
|
*/
|
|
|
|
U_CAPI UResourceBundle* U_EXPORT2
|
|
|
|
ures_findResource(const char* pathToResource,
|
|
|
|
UResourceBundle *fillIn, UErrorCode *status);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a sub resource that can be located using the pathToResource argument. One needs a path inside
|
|
|
|
* the supplied resource, for example, if you have "en_US" resource bundle opened, you might ask for
|
|
|
|
* "zoneStrings/3". Keys and indexes are supported. Keys
|
|
|
|
* need to reference data in named structures, while indexes can reference both
|
|
|
|
* named and anonymous resources.
|
|
|
|
* Features a fill-in parameter.
|
|
|
|
*
|
|
|
|
* @param resourceBundle a resource
|
|
|
|
* @param pathToResource a path that will lead to the requested resource
|
|
|
|
* @param fillIn if NULL a new UResourceBundle struct is allocated and must be deleted by the caller.
|
|
|
|
* Alternatively, you can supply a struct to be filled by this function.
|
|
|
|
* @param status fills in the outgoing error code.
|
|
|
|
* @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
|
|
|
|
* @draft ICU 2.2
|
|
|
|
*/
|
|
|
|
U_CAPI UResourceBundle* U_EXPORT2
|
|
|
|
ures_findSubResource(const UResourceBundle *resB,
|
2003-10-17 23:58:52 +00:00
|
|
|
char* pathToResource,
|
2002-07-13 05:36:27 +00:00
|
|
|
UResourceBundle *fillIn, UErrorCode *status);
|
|
|
|
|
2004-08-31 17:49:04 +00:00
|
|
|
/**
|
|
|
|
* Returns a functionally equivalent locale (considering keywords) for the specified keyword.
|
|
|
|
* @param result fillin for the equivalent locale
|
|
|
|
* @param resultCapacity capacity of the fillin buffer
|
|
|
|
* @param path path to the tree, or NULL for ICU data
|
|
|
|
* @param resName top level resource. Example: "collations"
|
|
|
|
* @param keyword locale keyword. Example: "collation"
|
|
|
|
* @param locid The requested locale
|
|
|
|
* @param isAvailable If non-null, pointer to fillin parameter that indicates whether the
|
|
|
|
* requested locale was available. The locale is defined as 'available' if it physically
|
|
|
|
* exists within the specified tree.
|
|
|
|
* @param omitDefault if TRUE, omit keyword and value if default. 'de_DE\@collation=standard' -> 'de_DE'
|
|
|
|
* @param status error code
|
|
|
|
* @return the actual buffer size needed for the full locale. If it's greater
|
|
|
|
* than resultCapacity, the returned full name will be truncated and an error code will be returned.
|
|
|
|
* @internal ICU 3.0
|
|
|
|
*/
|
|
|
|
U_INTERNAL int32_t U_EXPORT2
|
|
|
|
ures_getFunctionalEquivalent(char *result, int32_t resultCapacity,
|
|
|
|
const char *path, const char *resName, const char *keyword, const char *locid,
|
|
|
|
UBool *isAvailable, UBool omitDefault, UErrorCode *status);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a tree path and keyword, return a string enumeration of all possible values for that keyword.
|
|
|
|
* @param path path to the tree, or NULL for ICU data
|
|
|
|
* @param keyword a particular keyword to consider, must match a top level resource name
|
|
|
|
* within the tree.
|
|
|
|
* @param status error code
|
|
|
|
* @internal ICU 3.0
|
|
|
|
*/
|
|
|
|
U_INTERNAL UEnumeration* U_EXPORT2
|
|
|
|
ures_getKeywordValues(const char *path, const char *keyword, UErrorCode *status);
|
2003-11-08 08:30:31 +00:00
|
|
|
|
2005-10-11 23:59:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a resource with multi-level fallback. Normally only the top level resources will
|
|
|
|
* fallback to its parent. This performs fallback on subresources. For example, when a table
|
|
|
|
* is defined in a resource bundle and a parent resource bundle, normally no fallback occurs
|
|
|
|
* on the sub-resources because the table is defined in the current resource bundle, but this
|
|
|
|
* function can perform fallback on the sub-resources of the table.
|
|
|
|
* @param resB a resource
|
|
|
|
* @param inKey a key associated with the requested resource
|
|
|
|
* @param fillIn if NULL a new UResourceBundle struct is allocated and must be deleted by the caller.
|
|
|
|
* Alternatively, you can supply a struct to be filled by this function.
|
|
|
|
* @param status: fills in the outgoing error code
|
|
|
|
* could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
|
|
|
|
* could be a non-failing error
|
|
|
|
* e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
|
|
|
|
* @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
|
|
|
|
* @internal ICU 3.0
|
|
|
|
*/
|
|
|
|
U_INTERNAL UResourceBundle* U_EXPORT2
|
|
|
|
ures_getByKeyWithFallback(const UResourceBundle *resB,
|
|
|
|
const char* inKey,
|
|
|
|
UResourceBundle *fillIn,
|
|
|
|
UErrorCode *status);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a String with multi-level fallback. Normally only the top level resources will
|
|
|
|
* fallback to its parent. This performs fallback on subresources. For example, when a table
|
|
|
|
* is defined in a resource bundle and a parent resource bundle, normally no fallback occurs
|
|
|
|
* on the sub-resources because the table is defined in the current resource bundle, but this
|
|
|
|
* function can perform fallback on the sub-resources of the table.
|
|
|
|
* @param resB a resource
|
|
|
|
* @param inKey a key associated with the requested resource
|
|
|
|
* @param status: fills in the outgoing error code
|
|
|
|
* could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
|
|
|
|
* could be a non-failing error
|
|
|
|
* e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
|
|
|
|
* @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
|
|
|
|
* @internal ICU 3.4
|
|
|
|
* @draft ICU 3.4
|
|
|
|
*/
|
|
|
|
U_INTERNAL const UChar* U_EXPORT2
|
|
|
|
ures_getStringByKeyWithFallback(const UResourceBundle *resB,
|
|
|
|
const char* inKey,
|
|
|
|
int32_t* len,
|
|
|
|
UErrorCode *status);
|
2009-01-29 00:17:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a version number by key
|
|
|
|
* @param resB bundle containing version number
|
|
|
|
* @param key the key for the version number
|
|
|
|
* @param ver fillin for the version number
|
|
|
|
* @param status error code
|
|
|
|
* @internal ICU 4.2
|
|
|
|
*/
|
|
|
|
U_INTERNAL void U_EXPORT2
|
|
|
|
ures_getVersionByKey(const UResourceBundle *resB,
|
|
|
|
const char *key,
|
|
|
|
UVersionInfo ver,
|
|
|
|
UErrorCode *status);
|
|
|
|
|
|
|
|
|
2010-05-25 22:17:12 +00:00
|
|
|
/**
|
|
|
|
* Internal function.
|
|
|
|
* Return the version number associated with this ResourceBundle as a string.
|
|
|
|
*
|
|
|
|
* @param resourceBundle The resource bundle for which the version is checked.
|
|
|
|
* @return A version number string as specified in the resource bundle or its parent.
|
|
|
|
* The caller does not own this string.
|
|
|
|
* @see ures_getVersion
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
U_INTERNAL const char* U_EXPORT2
|
|
|
|
ures_getVersionNumberInternal(const UResourceBundle *resourceBundle);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the name of the Locale associated with this ResourceBundle. This API allows
|
|
|
|
* you to query for the real locale of the resource. For example, if you requested
|
|
|
|
* "en_US_CALIFORNIA" and only "en_US" bundle exists, "en_US" will be returned.
|
|
|
|
* For subresources, the locale where this resource comes from will be returned.
|
|
|
|
* If fallback has occured, getLocale will reflect this.
|
|
|
|
*
|
|
|
|
* @param resourceBundle resource bundle in question
|
|
|
|
* @param status just for catching illegal arguments
|
|
|
|
* @return A Locale name
|
|
|
|
* @deprecated ICU 2.8 Use ures_getLocaleByType instead.
|
|
|
|
*/
|
|
|
|
U_INTERNAL const char* U_EXPORT2
|
|
|
|
ures_getLocaleInternal(const UResourceBundle* resourceBundle,
|
|
|
|
UErrorCode* status);
|
|
|
|
|
2006-04-25 19:41:17 +00:00
|
|
|
#endif /*URESIMP_H*/
|