Path: blob/jdk8u272-b10-aarch32-20201026/jdk/src/share/native/common/unicode/resbund.h
48773 views
// © 2016 and later: Unicode, Inc. and others.1// License & terms of use: http://www.unicode.org/copyright.html2/*3******************************************************************************4*5* Copyright (C) 1996-2013, International Business Machines Corporation6* and others. All Rights Reserved.7*8******************************************************************************9*10* File resbund.h11*12* CREATED BY13* Richard Gillam14*15* Modification History:16*17* Date Name Description18* 2/5/97 aliu Added scanForLocaleInFile. Added19* constructor which attempts to read resource bundle20* from a specific file, without searching other files.21* 2/11/97 aliu Added UErrorCode return values to constructors. Fixed22* infinite loops in scanForFile and scanForLocale.23* Modified getRawResourceData to not delete storage24* in localeData and resourceData which it doesn't own.25* Added Mac compatibility #ifdefs for tellp() and26* ios::nocreate.27* 2/18/97 helena Updated with 100% documentation coverage.28* 3/13/97 aliu Rewrote to load in entire resource bundle and store29* it as a Hashtable of ResourceBundleData objects.30* Added state table to govern parsing of files.31* Modified to load locale index out of new file32* distinct from default.txt.33* 3/25/97 aliu Modified to support 2-d arrays, needed for timezone34* data. Added support for custom file suffixes. Again,35* needed to support timezone data.36* 4/7/97 aliu Cleaned up.37* 03/02/99 stephen Removed dependency on FILE*.38* 03/29/99 helena Merged Bertrand and Stephen's changes.39* 06/11/99 stephen Removed parsing of .txt files.40* Reworked to use new binary format.41* Cleaned up.42* 06/14/99 stephen Removed methods taking a filename suffix.43* 11/09/99 weiv Added getLocale(), fRealLocale, removed fRealLocaleID44******************************************************************************45*/4647#ifndef RESBUND_H48#define RESBUND_H4950#include "unicode/utypes.h"51#include "unicode/uobject.h"52#include "unicode/ures.h"53#include "unicode/unistr.h"54#include "unicode/locid.h"5556/**57* \file58* \brief C++ API: Resource Bundle59*/6061U_NAMESPACE_BEGIN6263/**64* A class representing a collection of resource information pertaining to a given65* locale. A resource bundle provides a way of accessing locale- specfic information in66* a data file. You create a resource bundle that manages the resources for a given67* locale and then ask it for individual resources.68* <P>69* Resource bundles in ICU4C are currently defined using text files which conform to the following70* <a href="http://source.icu-project.org/repos/icu/icuhtml/trunk/design/bnf_rb.txt">BNF definition</a>.71* More on resource bundle concepts and syntax can be found in the72* <a href="http://icu-project.org/userguide/ResourceManagement.html">Users Guide</a>.73* <P>74*75* The ResourceBundle class is not suitable for subclassing.76*77* @stable ICU 2.078*/79class U_COMMON_API ResourceBundle : public UObject {80public:81/**82* Constructor83*84* @param packageName The packageName and locale together point to an ICU udata object,85* as defined by <code> udata_open( packageName, "res", locale, err) </code>86* or equivalent. Typically, packageName will refer to a (.dat) file, or to87* a package registered with udata_setAppData(). Using a full file or directory88* pathname for packageName is deprecated.89* @param locale This is the locale this resource bundle is for. To get resources90* for the French locale, for example, you would create a91* ResourceBundle passing Locale::FRENCH for the "locale" parameter,92* and all subsequent calls to that resource bundle will return93* resources that pertain to the French locale. If the caller doesn't94* pass a locale parameter, the default locale for the system (as95* returned by Locale::getDefault()) will be used.96* @param err The Error Code.97* The UErrorCode& err parameter is used to return status information to the user. To98* check whether the construction succeeded or not, you should check the value of99* U_SUCCESS(err). If you wish more detailed information, you can check for100* informational error results which still indicate success. U_USING_FALLBACK_WARNING101* indicates that a fall back locale was used. For example, 'de_CH' was requested,102* but nothing was found there, so 'de' was used. U_USING_DEFAULT_WARNING indicates that103* the default locale data was used; neither the requested locale nor any of its104* fall back locales could be found.105* @stable ICU 2.0106*/107ResourceBundle(const UnicodeString& packageName,108const Locale& locale,109UErrorCode& err);110111/**112* Construct a resource bundle for the default bundle in the specified package.113*114* @param packageName The packageName and locale together point to an ICU udata object,115* as defined by <code> udata_open( packageName, "res", locale, err) </code>116* or equivalent. Typically, packageName will refer to a (.dat) file, or to117* a package registered with udata_setAppData(). Using a full file or directory118* pathname for packageName is deprecated.119* @param err A UErrorCode value120* @stable ICU 2.0121*/122ResourceBundle(const UnicodeString& packageName,123UErrorCode& err);124125/**126* Construct a resource bundle for the ICU default bundle.127*128* @param err A UErrorCode value129* @stable ICU 2.0130*/131ResourceBundle(UErrorCode &err);132133/**134* Standard constructor, constructs a resource bundle for the locale-specific135* bundle in the specified package.136*137* @param packageName The packageName and locale together point to an ICU udata object,138* as defined by <code> udata_open( packageName, "res", locale, err) </code>139* or equivalent. Typically, packageName will refer to a (.dat) file, or to140* a package registered with udata_setAppData(). Using a full file or directory141* pathname for packageName is deprecated.142* NULL is used to refer to ICU data.143* @param locale The locale for which to open a resource bundle.144* @param err A UErrorCode value145* @stable ICU 2.0146*/147ResourceBundle(const char* packageName,148const Locale& locale,149UErrorCode& err);150151/**152* Copy constructor.153*154* @param original The resource bundle to copy.155* @stable ICU 2.0156*/157ResourceBundle(const ResourceBundle &original);158159/**160* Constructor from a C UResourceBundle. The resource bundle is161* copied and not adopted. ures_close will still need to be used on the162* original resource bundle.163*164* @param res A pointer to the C resource bundle.165* @param status A UErrorCode value.166* @stable ICU 2.0167*/168ResourceBundle(UResourceBundle *res,169UErrorCode &status);170171/**172* Assignment operator.173*174* @param other The resource bundle to copy.175* @stable ICU 2.0176*/177ResourceBundle&178operator=(const ResourceBundle& other);179180/** Destructor.181* @stable ICU 2.0182*/183virtual ~ResourceBundle();184185/**186* Clone this object.187* Clones can be used concurrently in multiple threads.188* If an error occurs, then NULL is returned.189* The caller must delete the clone.190*191* @return a clone of this object192*193* @see getDynamicClassID194* @stable ICU 2.8195*/196ResourceBundle *clone() const;197198/**199* Returns the size of a resource. Size for scalar types is always 1, and for vector/table types is200* the number of child resources.201* @warning Integer array is treated as a scalar type. There are no202* APIs to access individual members of an integer array. It203* is always returned as a whole.204*205* @return number of resources in a given resource.206* @stable ICU 2.0207*/208int32_t209getSize(void) const;210211/**212* returns a string from a string resource type213*214* @param status fills in the outgoing error code215* could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found216* could be a warning217* e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>218* @return a pointer to a zero-terminated char16_t array which lives in a memory mapped/DLL file.219* @stable ICU 2.0220*/221UnicodeString222getString(UErrorCode& status) const;223224/**225* returns a binary data from a resource. Can be used at most primitive resource types (binaries,226* strings, ints)227*228* @param len fills in the length of resulting byte chunk229* @param status fills in the outgoing error code230* could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found231* could be a warning232* e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>233* @return a pointer to a chunk of unsigned bytes which live in a memory mapped/DLL file.234* @stable ICU 2.0235*/236const uint8_t*237getBinary(int32_t& len, UErrorCode& status) const;238239240/**241* returns an integer vector from a resource.242*243* @param len fills in the length of resulting integer vector244* @param status fills in the outgoing error code245* could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found246* could be a warning247* e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>248* @return a pointer to a vector of integers that lives in a memory mapped/DLL file.249* @stable ICU 2.0250*/251const int32_t*252getIntVector(int32_t& len, UErrorCode& status) const;253254/**255* returns an unsigned integer from a resource.256* This integer is originally 28 bits.257*258* @param status fills in the outgoing error code259* could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found260* could be a warning261* e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>262* @return an unsigned integer value263* @stable ICU 2.0264*/265uint32_t266getUInt(UErrorCode& status) const;267268/**269* returns a signed integer from a resource.270* This integer is originally 28 bit and the sign gets propagated.271*272* @param status fills in the outgoing error code273* could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found274* could be a warning275* e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>276* @return a signed integer value277* @stable ICU 2.0278*/279int32_t280getInt(UErrorCode& status) const;281282/**283* Checks whether the resource has another element to iterate over.284*285* @return TRUE if there are more elements, FALSE if there is no more elements286* @stable ICU 2.0287*/288UBool289hasNext(void) const;290291/**292* Resets the internal context of a resource so that iteration starts from the first element.293*294* @stable ICU 2.0295*/296void297resetIterator(void);298299/**300* Returns the key associated with this resource. Not all the resources have a key - only301* those that are members of a table.302*303* @return a key associated to this resource, or NULL if it doesn't have a key304* @stable ICU 2.0305*/306const char*307getKey(void) const;308309/**310* Gets the locale ID of the resource bundle as a string.311* Same as getLocale().getName() .312*313* @return the locale ID of the resource bundle as a string314* @stable ICU 2.0315*/316const char*317getName(void) const;318319320/**321* Returns the type of a resource. Available types are defined in enum UResType322*323* @return type of the given resource.324* @stable ICU 2.0325*/326UResType327getType(void) const;328329/**330* Returns the next resource in a given resource or NULL if there are no more resources331*332* @param status fills in the outgoing error code333* @return ResourceBundle object.334* @stable ICU 2.0335*/336ResourceBundle337getNext(UErrorCode& status);338339/**340* Returns the next string in a resource or NULL if there are no more resources341* to iterate over.342*343* @param status fills in the outgoing error code344* @return an UnicodeString object.345* @stable ICU 2.0346*/347UnicodeString348getNextString(UErrorCode& status);349350/**351* Returns the next string in a resource or NULL if there are no more resources352* to iterate over.353*354* @param key fill in for key associated with this string355* @param status fills in the outgoing error code356* @return an UnicodeString object.357* @stable ICU 2.0358*/359UnicodeString360getNextString(const char ** key,361UErrorCode& status);362363/**364* Returns the resource in a resource at the specified index.365*366* @param index an index to the wanted resource.367* @param status fills in the outgoing error code368* @return ResourceBundle object. If there is an error, resource is invalid.369* @stable ICU 2.0370*/371ResourceBundle372get(int32_t index,373UErrorCode& status) const;374375/**376* Returns the string in a given resource at the specified index.377*378* @param index an index to the wanted string.379* @param status fills in the outgoing error code380* @return an UnicodeString object. If there is an error, string is bogus381* @stable ICU 2.0382*/383UnicodeString384getStringEx(int32_t index,385UErrorCode& status) const;386387/**388* Returns a resource in a resource that has a given key. This procedure works only with table389* resources.390*391* @param key a key associated with the wanted resource392* @param status fills in the outgoing error code.393* @return ResourceBundle object. If there is an error, resource is invalid.394* @stable ICU 2.0395*/396ResourceBundle397get(const char* key,398UErrorCode& status) const;399400/**401* Returns a string in a resource that has a given key. This procedure works only with table402* resources.403*404* @param key a key associated with the wanted string405* @param status fills in the outgoing error code406* @return an UnicodeString object. If there is an error, string is bogus407* @stable ICU 2.0408*/409UnicodeString410getStringEx(const char* key,411UErrorCode& status) const;412413#ifndef U_HIDE_DEPRECATED_API414/**415* Return the version number associated with this ResourceBundle as a string. Please416* use getVersion, as this method is going to be deprecated.417*418* @return A version number string as specified in the resource bundle or its parent.419* The caller does not own this string.420* @see getVersion421* @deprecated ICU 2.8 Use getVersion instead.422*/423const char*424getVersionNumber(void) const;425#endif /* U_HIDE_DEPRECATED_API */426427/**428* Return the version number associated with this ResourceBundle as a UVersionInfo array.429*430* @param versionInfo A UVersionInfo array that is filled with the version number431* as specified in the resource bundle or its parent.432* @stable ICU 2.0433*/434void435getVersion(UVersionInfo versionInfo) const;436437#ifndef U_HIDE_DEPRECATED_API438/**439* Return the Locale associated with this ResourceBundle.440*441* @return a Locale object442* @deprecated ICU 2.8 Use getLocale(ULocDataLocaleType type, UErrorCode &status) overload instead.443*/444const Locale&445getLocale(void) const;446#endif /* U_HIDE_DEPRECATED_API */447448/**449* Return the Locale associated with this ResourceBundle.450* @param type You can choose between requested, valid and actual451* locale. For description see the definition of452* ULocDataLocaleType in uloc.h453* @param status just for catching illegal arguments454*455* @return a Locale object456* @stable ICU 2.8457*/458const Locale459getLocale(ULocDataLocaleType type, UErrorCode &status) const;460#ifndef U_HIDE_INTERNAL_API461/**462* This API implements multilevel fallback463* @internal464*/465ResourceBundle466getWithFallback(const char* key, UErrorCode& status);467#endif /* U_HIDE_INTERNAL_API */468/**469* ICU "poor man's RTTI", returns a UClassID for the actual class.470*471* @stable ICU 2.2472*/473virtual UClassID getDynamicClassID() const;474475/**476* ICU "poor man's RTTI", returns a UClassID for this class.477*478* @stable ICU 2.2479*/480static UClassID U_EXPORT2 getStaticClassID();481482private:483ResourceBundle(); // default constructor not implemented484485UResourceBundle *fResource;486void constructForLocale(const UnicodeString& path, const Locale& locale, UErrorCode& error);487Locale *fLocale;488};489490U_NAMESPACE_END491#endif492493494