intl/icu/source/common/uresimp.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/common/uresimp.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,268 @@
     1.4 +/*
     1.5 +**********************************************************************
     1.6 +*   Copyright (C) 2000-2011, International Business Machines
     1.7 +*   Corporation and others.  All Rights Reserved.
     1.8 +**********************************************************************
     1.9 +*/
    1.10 +
    1.11 +#ifndef URESIMP_H
    1.12 +#define URESIMP_H
    1.13 +
    1.14 +#include "unicode/ures.h"
    1.15 +
    1.16 +#include "uresdata.h"
    1.17 +
    1.18 +#define kRootLocaleName         "root"
    1.19 +#define kPoolBundleName         "pool"
    1.20 +
    1.21 +/*
    1.22 + The default minor version and the version separator must be exactly one
    1.23 + character long.
    1.24 +*/
    1.25 +
    1.26 +#define kDefaultMinorVersion    "0"
    1.27 +#define kVersionSeparator       "."
    1.28 +#define kVersionTag             "Version"
    1.29 +
    1.30 +#define MAGIC1 19700503
    1.31 +#define MAGIC2 19641227
    1.32 +
    1.33 +#define URES_MAX_ALIAS_LEVEL 256
    1.34 +#define URES_MAX_BUFFER_SIZE 256
    1.35 +
    1.36 +#define EMPTY_SET 0x2205
    1.37 +
    1.38 +/*
    1.39 +enum UResEntryType {
    1.40 +    ENTRY_OK = 0,
    1.41 +    ENTRY_GOTO_ROOT = 1,
    1.42 +    ENTRY_GOTO_DEFAULT = 2,
    1.43 +    ENTRY_INVALID = 3
    1.44 +};
    1.45 +
    1.46 +typedef enum UResEntryType UResEntryType;
    1.47 +*/
    1.48 +
    1.49 +struct UResourceDataEntry;
    1.50 +typedef struct UResourceDataEntry UResourceDataEntry;
    1.51 +
    1.52 +/*
    1.53 + * Note: If we wanted to make this structure smaller, then we could try
    1.54 + * to use one UResourceDataEntry pointer for fAlias and fPool, with a separate
    1.55 + * flag to distinguish whether this struct is for a real bundle with a pool,
    1.56 + * or for an alias entry for which we won't use the pool after loading.
    1.57 + */
    1.58 +struct UResourceDataEntry {
    1.59 +    char *fName; /* name of the locale for bundle - still to decide whether it is original or fallback */
    1.60 +    char *fPath; /* path to bundle - used for distinguishing between resources with the same name */
    1.61 +    UResourceDataEntry *fParent; /*next resource in fallback chain*/
    1.62 +    UResourceDataEntry *fAlias;
    1.63 +    UResourceDataEntry *fPool;
    1.64 +    ResourceData fData; /* data for low level access */
    1.65 +    char fNameBuffer[3]; /* A small buffer of free space for fName. The free space is due to struct padding. */
    1.66 +    uint32_t fCountExisting; /* how much is this resource used */
    1.67 +    UErrorCode fBogus;
    1.68 +    /* int32_t fHashKey;*/ /* for faster access in the hashtable */
    1.69 +};
    1.70 +
    1.71 +#define RES_BUFSIZE 64
    1.72 +#define RES_PATH_SEPARATOR   '/'
    1.73 +#define RES_PATH_SEPARATOR_S   "/"
    1.74 +
    1.75 +struct UResourceBundle {
    1.76 +    const char *fKey; /*tag*/
    1.77 +    UResourceDataEntry *fData; /*for low-level access*/
    1.78 +    char *fVersion;
    1.79 +    UResourceDataEntry *fTopLevelData; /* for getting the valid locale */
    1.80 +    char *fResPath; /* full path to the resource: "zh_TW/CollationElements/Sequence" */
    1.81 +    ResourceData fResData;
    1.82 +    char fResBuf[RES_BUFSIZE];
    1.83 +    int32_t fResPathLen;
    1.84 +    Resource fRes;
    1.85 +    UBool fHasFallback;
    1.86 +    UBool fIsTopLevel;
    1.87 +    uint32_t fMagic1;   /* For determining if it's a stack object */
    1.88 +    uint32_t fMagic2;   /* For determining if it's a stack object */
    1.89 +    int32_t fIndex;
    1.90 +    int32_t fSize;
    1.91 +
    1.92 +    /*const UResourceBundle *fParentRes;*/ /* needed to get the actual locale for a child resource */
    1.93 +};
    1.94 +
    1.95 +U_CAPI void U_EXPORT2 ures_initStackObject(UResourceBundle* resB);
    1.96 +
    1.97 +/* Some getters used by the copy constructor */
    1.98 +U_CFUNC const char* ures_getName(const UResourceBundle* resB);
    1.99 +#ifdef URES_DEBUG
   1.100 +U_CFUNC const char* ures_getPath(const UResourceBundle* resB);
   1.101 +/**
   1.102 + * If anything was in the RB cache, dump it to the screen.
   1.103 + * @return TRUE if there was anything into the cache
   1.104 + */
   1.105 +U_CAPI UBool U_EXPORT2 ures_dumpCacheContents(void);
   1.106 +#endif
   1.107 +/*U_CFUNC void ures_appendResPath(UResourceBundle *resB, const char* toAdd, int32_t lenToAdd);*/
   1.108 +/*U_CFUNC void ures_setResPath(UResourceBundle *resB, const char* toAdd);*/
   1.109 +/*U_CFUNC void ures_freeResPath(UResourceBundle *resB);*/
   1.110 +
   1.111 +/* Candidates for export */
   1.112 +U_CFUNC UResourceBundle *ures_copyResb(UResourceBundle *r, const UResourceBundle *original, UErrorCode *status);
   1.113 +
   1.114 +/**
   1.115 + * Returns a resource that can be located using the pathToResource argument. One needs optional package, locale
   1.116 + * and path inside the locale, for example: "/myData/en/zoneStrings/3". Keys and indexes are supported. Keys
   1.117 + * need to reference data in named structures, while indexes can reference both named and anonymous resources.
   1.118 + * Features a fill-in parameter. 
   1.119 + * 
   1.120 + * Note, this function does NOT have a syntax for specifying items within a tree.  May want to consider a
   1.121 + * syntax that delineates between package/tree and resource.  
   1.122 + *
   1.123 + * @param pathToResource    a path that will lead to the requested resource
   1.124 + * @param fillIn            if NULL a new UResourceBundle struct is allocated and must be deleted by the caller.
   1.125 + *                          Alternatively, you can supply a struct to be filled by this function.
   1.126 + * @param status            fills in the outgoing error code.
   1.127 + * @return                  a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
   1.128 + */
   1.129 +U_CAPI UResourceBundle* U_EXPORT2
   1.130 +ures_findResource(const char* pathToResource, 
   1.131 +                  UResourceBundle *fillIn, UErrorCode *status); 
   1.132 +
   1.133 +/**
   1.134 + * Returns a sub resource that can be located using the pathToResource argument. One needs a path inside 
   1.135 + * the supplied resource, for example, if you have "en_US" resource bundle opened, you might ask for
   1.136 + * "zoneStrings/3". Keys and indexes are supported. Keys
   1.137 + * need to reference data in named structures, while indexes can reference both 
   1.138 + * named and anonymous resources.
   1.139 + * Features a fill-in parameter. 
   1.140 + *
   1.141 + * @param resourceBundle    a resource
   1.142 + * @param pathToResource    a path that will lead to the requested resource
   1.143 + * @param fillIn            if NULL a new UResourceBundle struct is allocated and must be deleted by the caller.
   1.144 + *                          Alternatively, you can supply a struct to be filled by this function.
   1.145 + * @param status            fills in the outgoing error code.
   1.146 + * @return                  a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
   1.147 + */
   1.148 +U_CAPI UResourceBundle* U_EXPORT2
   1.149 +ures_findSubResource(const UResourceBundle *resB, 
   1.150 +                     char* pathToResource, 
   1.151 +                     UResourceBundle *fillIn, UErrorCode *status);
   1.152 +
   1.153 +/**
   1.154 + * Returns a functionally equivalent locale (considering keywords) for the specified keyword.
   1.155 + * @param result fillin for the equivalent locale
   1.156 + * @param resultCapacity capacity of the fillin buffer
   1.157 + * @param path path to the tree, or NULL for ICU data
   1.158 + * @param resName top level resource. Example: "collations"
   1.159 + * @param keyword locale keyword. Example: "collation"
   1.160 + * @param locid The requested locale
   1.161 + * @param isAvailable If non-null, pointer to fillin parameter that indicates whether the 
   1.162 + * requested locale was available. The locale is defined as 'available' if it physically 
   1.163 + * exists within the specified tree.
   1.164 + * @param omitDefault if TRUE, omit keyword and value if default. 'de_DE\@collation=standard' -> 'de_DE'
   1.165 + * @param status error code
   1.166 + * @return  the actual buffer size needed for the full locale.  If it's greater 
   1.167 + * than resultCapacity, the returned full name will be truncated and an error code will be returned.
   1.168 + */
   1.169 +U_CAPI int32_t U_EXPORT2
   1.170 +ures_getFunctionalEquivalent(char *result, int32_t resultCapacity, 
   1.171 +                             const char *path, const char *resName, const char *keyword, const char *locid,
   1.172 +                             UBool *isAvailable, UBool omitDefault, UErrorCode *status);
   1.173 +
   1.174 +/**
   1.175 + * Given a tree path and keyword, return a string enumeration of all possible values for that keyword.
   1.176 + * @param path path to the tree, or NULL for ICU data
   1.177 + * @param keyword a particular keyword to consider, must match a top level resource name 
   1.178 + * within the tree.
   1.179 + * @param status error code
   1.180 + */
   1.181 +U_CAPI UEnumeration* U_EXPORT2
   1.182 +ures_getKeywordValues(const char *path, const char *keyword, UErrorCode *status);
   1.183 +
   1.184 +
   1.185 +/**
   1.186 + * Get a resource with multi-level fallback. Normally only the top level resources will
   1.187 + * fallback to its parent. This performs fallback on subresources. For example, when a table
   1.188 + * is defined in a resource bundle and a parent resource bundle, normally no fallback occurs
   1.189 + * on the sub-resources because the table is defined in the current resource bundle, but this
   1.190 + * function can perform fallback on the sub-resources of the table.
   1.191 + * @param resB              a resource
   1.192 + * @param inKey             a key associated with the requested resource
   1.193 + * @param fillIn            if NULL a new UResourceBundle struct is allocated and must be deleted by the caller.
   1.194 + *                          Alternatively, you can supply a struct to be filled by this function.
   1.195 + * @param status: fills in the outgoing error code
   1.196 + *                could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
   1.197 + *                could be a non-failing error 
   1.198 + *                e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
   1.199 + * @return                  a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
   1.200 + */
   1.201 +U_CAPI UResourceBundle* U_EXPORT2 
   1.202 +ures_getByKeyWithFallback(const UResourceBundle *resB, 
   1.203 +                          const char* inKey, 
   1.204 +                          UResourceBundle *fillIn, 
   1.205 +                          UErrorCode *status);
   1.206 +
   1.207 +
   1.208 +/**
   1.209 + * Get a String with multi-level fallback. Normally only the top level resources will
   1.210 + * fallback to its parent. This performs fallback on subresources. For example, when a table
   1.211 + * is defined in a resource bundle and a parent resource bundle, normally no fallback occurs
   1.212 + * on the sub-resources because the table is defined in the current resource bundle, but this
   1.213 + * function can perform fallback on the sub-resources of the table.
   1.214 + * @param resB              a resource
   1.215 + * @param inKey             a key associated with the requested resource
   1.216 + * @param status: fills in the outgoing error code
   1.217 + *                could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
   1.218 + *                could be a non-failing error 
   1.219 + *                e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
   1.220 + * @return                  a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it
   1.221 + */
   1.222 +U_CAPI const UChar* U_EXPORT2 
   1.223 +ures_getStringByKeyWithFallback(const UResourceBundle *resB, 
   1.224 +                          const char* inKey,  
   1.225 +                          int32_t* len,
   1.226 +                          UErrorCode *status);
   1.227 +
   1.228 +/**
   1.229 + * Get a version number by key
   1.230 + * @param resB bundle containing version number
   1.231 + * @param key the key for the version number
   1.232 + * @param ver fillin for the version number
   1.233 + * @param status error code
   1.234 + */
   1.235 +U_CAPI void U_EXPORT2
   1.236 +ures_getVersionByKey(const UResourceBundle *resB,
   1.237 +                     const char *key,
   1.238 +                     UVersionInfo ver,
   1.239 +                     UErrorCode *status);
   1.240 +
   1.241 +
   1.242 +/**
   1.243 + * Internal function.
   1.244 + * Return the version number associated with this ResourceBundle as a string.
   1.245 + *
   1.246 + * @param resourceBundle The resource bundle for which the version is checked.
   1.247 + * @return  A version number string as specified in the resource bundle or its parent.
   1.248 + *          The caller does not own this string.
   1.249 + * @see ures_getVersion
   1.250 + */
   1.251 +U_CAPI const char* U_EXPORT2 
   1.252 +ures_getVersionNumberInternal(const UResourceBundle *resourceBundle);
   1.253 +
   1.254 +/**
   1.255 + * Return the name of the Locale associated with this ResourceBundle. This API allows
   1.256 + * you to query for the real locale of the resource. For example, if you requested 
   1.257 + * "en_US_CALIFORNIA" and only "en_US" bundle exists, "en_US" will be returned. 
   1.258 + * For subresources, the locale where this resource comes from will be returned.
   1.259 + * If fallback has occured, getLocale will reflect this.
   1.260 + *
   1.261 + * This internal version avoids deprecated-warnings in ICU code.
   1.262 + *
   1.263 + * @param resourceBundle resource bundle in question
   1.264 + * @param status just for catching illegal arguments
   1.265 + * @return  A Locale name
   1.266 + */
   1.267 +U_CAPI const char* U_EXPORT2 
   1.268 +ures_getLocaleInternal(const UResourceBundle* resourceBundle, 
   1.269 +               UErrorCode* status);
   1.270 +
   1.271 +#endif /*URESIMP_H*/

mercurial