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