intl/icu/source/common/unicode/resbund.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 ******************************************************************************
michael@0 3 *
michael@0 4 * Copyright (C) 1996-2013, International Business Machines Corporation
michael@0 5 * and others. All Rights Reserved.
michael@0 6 *
michael@0 7 ******************************************************************************
michael@0 8 *
michael@0 9 * File resbund.h
michael@0 10 *
michael@0 11 * CREATED BY
michael@0 12 * Richard Gillam
michael@0 13 *
michael@0 14 * Modification History:
michael@0 15 *
michael@0 16 * Date Name Description
michael@0 17 * 2/5/97 aliu Added scanForLocaleInFile. Added
michael@0 18 * constructor which attempts to read resource bundle
michael@0 19 * from a specific file, without searching other files.
michael@0 20 * 2/11/97 aliu Added UErrorCode return values to constructors. Fixed
michael@0 21 * infinite loops in scanForFile and scanForLocale.
michael@0 22 * Modified getRawResourceData to not delete storage
michael@0 23 * in localeData and resourceData which it doesn't own.
michael@0 24 * Added Mac compatibility #ifdefs for tellp() and
michael@0 25 * ios::nocreate.
michael@0 26 * 2/18/97 helena Updated with 100% documentation coverage.
michael@0 27 * 3/13/97 aliu Rewrote to load in entire resource bundle and store
michael@0 28 * it as a Hashtable of ResourceBundleData objects.
michael@0 29 * Added state table to govern parsing of files.
michael@0 30 * Modified to load locale index out of new file
michael@0 31 * distinct from default.txt.
michael@0 32 * 3/25/97 aliu Modified to support 2-d arrays, needed for timezone
michael@0 33 * data. Added support for custom file suffixes. Again,
michael@0 34 * needed to support timezone data.
michael@0 35 * 4/7/97 aliu Cleaned up.
michael@0 36 * 03/02/99 stephen Removed dependency on FILE*.
michael@0 37 * 03/29/99 helena Merged Bertrand and Stephen's changes.
michael@0 38 * 06/11/99 stephen Removed parsing of .txt files.
michael@0 39 * Reworked to use new binary format.
michael@0 40 * Cleaned up.
michael@0 41 * 06/14/99 stephen Removed methods taking a filename suffix.
michael@0 42 * 11/09/99 weiv Added getLocale(), fRealLocale, removed fRealLocaleID
michael@0 43 ******************************************************************************
michael@0 44 */
michael@0 45
michael@0 46 #ifndef RESBUND_H
michael@0 47 #define RESBUND_H
michael@0 48
michael@0 49 #include "unicode/utypes.h"
michael@0 50 #include "unicode/uobject.h"
michael@0 51 #include "unicode/ures.h"
michael@0 52 #include "unicode/unistr.h"
michael@0 53 #include "unicode/locid.h"
michael@0 54
michael@0 55 /**
michael@0 56 * \file
michael@0 57 * \brief C++ API: Resource Bundle
michael@0 58 */
michael@0 59
michael@0 60 U_NAMESPACE_BEGIN
michael@0 61
michael@0 62 /**
michael@0 63 * A class representing a collection of resource information pertaining to a given
michael@0 64 * locale. A resource bundle provides a way of accessing locale- specfic information in
michael@0 65 * a data file. You create a resource bundle that manages the resources for a given
michael@0 66 * locale and then ask it for individual resources.
michael@0 67 * <P>
michael@0 68 * Resource bundles in ICU4C are currently defined using text files which conform to the following
michael@0 69 * <a href="http://source.icu-project.org/repos/icu/icuhtml/trunk/design/bnf_rb.txt">BNF definition</a>.
michael@0 70 * More on resource bundle concepts and syntax can be found in the
michael@0 71 * <a href="http://icu-project.org/userguide/ResourceManagement.html">Users Guide</a>.
michael@0 72 * <P>
michael@0 73 *
michael@0 74 * The ResourceBundle class is not suitable for subclassing.
michael@0 75 *
michael@0 76 * @stable ICU 2.0
michael@0 77 */
michael@0 78 class U_COMMON_API ResourceBundle : public UObject {
michael@0 79 public:
michael@0 80 /**
michael@0 81 * Constructor
michael@0 82 *
michael@0 83 * @param packageName The packageName and locale together point to an ICU udata object,
michael@0 84 * as defined by <code> udata_open( packageName, "res", locale, err) </code>
michael@0 85 * or equivalent. Typically, packageName will refer to a (.dat) file, or to
michael@0 86 * a package registered with udata_setAppData(). Using a full file or directory
michael@0 87 * pathname for packageName is deprecated.
michael@0 88 * @param locale This is the locale this resource bundle is for. To get resources
michael@0 89 * for the French locale, for example, you would create a
michael@0 90 * ResourceBundle passing Locale::FRENCH for the "locale" parameter,
michael@0 91 * and all subsequent calls to that resource bundle will return
michael@0 92 * resources that pertain to the French locale. If the caller doesn't
michael@0 93 * pass a locale parameter, the default locale for the system (as
michael@0 94 * returned by Locale::getDefault()) will be used.
michael@0 95 * @param err The Error Code.
michael@0 96 * The UErrorCode& err parameter is used to return status information to the user. To
michael@0 97 * check whether the construction succeeded or not, you should check the value of
michael@0 98 * U_SUCCESS(err). If you wish more detailed information, you can check for
michael@0 99 * informational error results which still indicate success. U_USING_FALLBACK_WARNING
michael@0 100 * indicates that a fall back locale was used. For example, 'de_CH' was requested,
michael@0 101 * but nothing was found there, so 'de' was used. U_USING_DEFAULT_WARNING indicates that
michael@0 102 * the default locale data was used; neither the requested locale nor any of its
michael@0 103 * fall back locales could be found.
michael@0 104 * @stable ICU 2.0
michael@0 105 */
michael@0 106 ResourceBundle(const UnicodeString& packageName,
michael@0 107 const Locale& locale,
michael@0 108 UErrorCode& err);
michael@0 109
michael@0 110 /**
michael@0 111 * Construct a resource bundle for the default bundle in the specified package.
michael@0 112 *
michael@0 113 * @param packageName The packageName and locale together point to an ICU udata object,
michael@0 114 * as defined by <code> udata_open( packageName, "res", locale, err) </code>
michael@0 115 * or equivalent. Typically, packageName will refer to a (.dat) file, or to
michael@0 116 * a package registered with udata_setAppData(). Using a full file or directory
michael@0 117 * pathname for packageName is deprecated.
michael@0 118 * @param err A UErrorCode value
michael@0 119 * @stable ICU 2.0
michael@0 120 */
michael@0 121 ResourceBundle(const UnicodeString& packageName,
michael@0 122 UErrorCode& err);
michael@0 123
michael@0 124 /**
michael@0 125 * Construct a resource bundle for the ICU default bundle.
michael@0 126 *
michael@0 127 * @param err A UErrorCode value
michael@0 128 * @stable ICU 2.0
michael@0 129 */
michael@0 130 ResourceBundle(UErrorCode &err);
michael@0 131
michael@0 132 /**
michael@0 133 * Standard constructor, onstructs a resource bundle for the locale-specific
michael@0 134 * bundle in the specified package.
michael@0 135 *
michael@0 136 * @param packageName The packageName and locale together point to an ICU udata object,
michael@0 137 * as defined by <code> udata_open( packageName, "res", locale, err) </code>
michael@0 138 * or equivalent. Typically, packageName will refer to a (.dat) file, or to
michael@0 139 * a package registered with udata_setAppData(). Using a full file or directory
michael@0 140 * pathname for packageName is deprecated.
michael@0 141 * NULL is used to refer to ICU data.
michael@0 142 * @param locale The locale for which to open a resource bundle.
michael@0 143 * @param err A UErrorCode value
michael@0 144 * @stable ICU 2.0
michael@0 145 */
michael@0 146 ResourceBundle(const char* packageName,
michael@0 147 const Locale& locale,
michael@0 148 UErrorCode& err);
michael@0 149
michael@0 150 /**
michael@0 151 * Copy constructor.
michael@0 152 *
michael@0 153 * @param original The resource bundle to copy.
michael@0 154 * @stable ICU 2.0
michael@0 155 */
michael@0 156 ResourceBundle(const ResourceBundle &original);
michael@0 157
michael@0 158 /**
michael@0 159 * Constructor from a C UResourceBundle. The resource bundle is
michael@0 160 * copied and not adopted. ures_close will still need to be used on the
michael@0 161 * original resource bundle.
michael@0 162 *
michael@0 163 * @param res A pointer to the C resource bundle.
michael@0 164 * @param status A UErrorCode value.
michael@0 165 * @stable ICU 2.0
michael@0 166 */
michael@0 167 ResourceBundle(UResourceBundle *res,
michael@0 168 UErrorCode &status);
michael@0 169
michael@0 170 /**
michael@0 171 * Assignment operator.
michael@0 172 *
michael@0 173 * @param other The resource bundle to copy.
michael@0 174 * @stable ICU 2.0
michael@0 175 */
michael@0 176 ResourceBundle&
michael@0 177 operator=(const ResourceBundle& other);
michael@0 178
michael@0 179 /** Destructor.
michael@0 180 * @stable ICU 2.0
michael@0 181 */
michael@0 182 virtual ~ResourceBundle();
michael@0 183
michael@0 184 /**
michael@0 185 * Clone this object.
michael@0 186 * Clones can be used concurrently in multiple threads.
michael@0 187 * If an error occurs, then NULL is returned.
michael@0 188 * The caller must delete the clone.
michael@0 189 *
michael@0 190 * @return a clone of this object
michael@0 191 *
michael@0 192 * @see getDynamicClassID
michael@0 193 * @stable ICU 2.8
michael@0 194 */
michael@0 195 ResourceBundle *clone() const;
michael@0 196
michael@0 197 /**
michael@0 198 * Returns the size of a resource. Size for scalar types is always 1, and for vector/table types is
michael@0 199 * the number of child resources.
michael@0 200 * @warning Integer array is treated as a scalar type. There are no
michael@0 201 * APIs to access individual members of an integer array. It
michael@0 202 * is always returned as a whole.
michael@0 203 *
michael@0 204 * @return number of resources in a given resource.
michael@0 205 * @stable ICU 2.0
michael@0 206 */
michael@0 207 int32_t
michael@0 208 getSize(void) const;
michael@0 209
michael@0 210 /**
michael@0 211 * returns a string from a string resource type
michael@0 212 *
michael@0 213 * @param status fills in the outgoing error code
michael@0 214 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
michael@0 215 * could be a warning
michael@0 216 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
michael@0 217 * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file.
michael@0 218 * @stable ICU 2.0
michael@0 219 */
michael@0 220 UnicodeString
michael@0 221 getString(UErrorCode& status) const;
michael@0 222
michael@0 223 /**
michael@0 224 * returns a binary data from a resource. Can be used at most primitive resource types (binaries,
michael@0 225 * strings, ints)
michael@0 226 *
michael@0 227 * @param len fills in the length of resulting byte chunk
michael@0 228 * @param status fills in the outgoing error code
michael@0 229 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
michael@0 230 * could be a warning
michael@0 231 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
michael@0 232 * @return a pointer to a chunk of unsigned bytes which live in a memory mapped/DLL file.
michael@0 233 * @stable ICU 2.0
michael@0 234 */
michael@0 235 const uint8_t*
michael@0 236 getBinary(int32_t& len, UErrorCode& status) const;
michael@0 237
michael@0 238
michael@0 239 /**
michael@0 240 * returns an integer vector from a resource.
michael@0 241 *
michael@0 242 * @param len fills in the length of resulting integer vector
michael@0 243 * @param status fills in the outgoing error code
michael@0 244 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
michael@0 245 * could be a warning
michael@0 246 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
michael@0 247 * @return a pointer to a vector of integers that lives in a memory mapped/DLL file.
michael@0 248 * @stable ICU 2.0
michael@0 249 */
michael@0 250 const int32_t*
michael@0 251 getIntVector(int32_t& len, UErrorCode& status) const;
michael@0 252
michael@0 253 /**
michael@0 254 * returns an unsigned integer from a resource.
michael@0 255 * This integer is originally 28 bits.
michael@0 256 *
michael@0 257 * @param status fills in the outgoing error code
michael@0 258 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
michael@0 259 * could be a warning
michael@0 260 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
michael@0 261 * @return an unsigned integer value
michael@0 262 * @stable ICU 2.0
michael@0 263 */
michael@0 264 uint32_t
michael@0 265 getUInt(UErrorCode& status) const;
michael@0 266
michael@0 267 /**
michael@0 268 * returns a signed integer from a resource.
michael@0 269 * This integer is originally 28 bit and the sign gets propagated.
michael@0 270 *
michael@0 271 * @param status fills in the outgoing error code
michael@0 272 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
michael@0 273 * could be a warning
michael@0 274 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
michael@0 275 * @return a signed integer value
michael@0 276 * @stable ICU 2.0
michael@0 277 */
michael@0 278 int32_t
michael@0 279 getInt(UErrorCode& status) const;
michael@0 280
michael@0 281 /**
michael@0 282 * Checks whether the resource has another element to iterate over.
michael@0 283 *
michael@0 284 * @return TRUE if there are more elements, FALSE if there is no more elements
michael@0 285 * @stable ICU 2.0
michael@0 286 */
michael@0 287 UBool
michael@0 288 hasNext(void) const;
michael@0 289
michael@0 290 /**
michael@0 291 * Resets the internal context of a resource so that iteration starts from the first element.
michael@0 292 *
michael@0 293 * @stable ICU 2.0
michael@0 294 */
michael@0 295 void
michael@0 296 resetIterator(void);
michael@0 297
michael@0 298 /**
michael@0 299 * Returns the key associated with this resource. Not all the resources have a key - only
michael@0 300 * those that are members of a table.
michael@0 301 *
michael@0 302 * @return a key associated to this resource, or NULL if it doesn't have a key
michael@0 303 * @stable ICU 2.0
michael@0 304 */
michael@0 305 const char*
michael@0 306 getKey(void) const;
michael@0 307
michael@0 308 /**
michael@0 309 * Gets the locale ID of the resource bundle as a string.
michael@0 310 * Same as getLocale().getName() .
michael@0 311 *
michael@0 312 * @return the locale ID of the resource bundle as a string
michael@0 313 * @stable ICU 2.0
michael@0 314 */
michael@0 315 const char*
michael@0 316 getName(void) const;
michael@0 317
michael@0 318
michael@0 319 /**
michael@0 320 * Returns the type of a resource. Available types are defined in enum UResType
michael@0 321 *
michael@0 322 * @return type of the given resource.
michael@0 323 * @stable ICU 2.0
michael@0 324 */
michael@0 325 UResType
michael@0 326 getType(void) const;
michael@0 327
michael@0 328 /**
michael@0 329 * Returns the next resource in a given resource or NULL if there are no more resources
michael@0 330 *
michael@0 331 * @param status fills in the outgoing error code
michael@0 332 * @return ResourceBundle object.
michael@0 333 * @stable ICU 2.0
michael@0 334 */
michael@0 335 ResourceBundle
michael@0 336 getNext(UErrorCode& status);
michael@0 337
michael@0 338 /**
michael@0 339 * Returns the next string in a resource or NULL if there are no more resources
michael@0 340 * to iterate over.
michael@0 341 *
michael@0 342 * @param status fills in the outgoing error code
michael@0 343 * @return an UnicodeString object.
michael@0 344 * @stable ICU 2.0
michael@0 345 */
michael@0 346 UnicodeString
michael@0 347 getNextString(UErrorCode& status);
michael@0 348
michael@0 349 /**
michael@0 350 * Returns the next string in a resource or NULL if there are no more resources
michael@0 351 * to iterate over.
michael@0 352 *
michael@0 353 * @param key fill in for key associated with this string
michael@0 354 * @param status fills in the outgoing error code
michael@0 355 * @return an UnicodeString object.
michael@0 356 * @stable ICU 2.0
michael@0 357 */
michael@0 358 UnicodeString
michael@0 359 getNextString(const char ** key,
michael@0 360 UErrorCode& status);
michael@0 361
michael@0 362 /**
michael@0 363 * Returns the resource in a resource at the specified index.
michael@0 364 *
michael@0 365 * @param index an index to the wanted resource.
michael@0 366 * @param status fills in the outgoing error code
michael@0 367 * @return ResourceBundle object. If there is an error, resource is invalid.
michael@0 368 * @stable ICU 2.0
michael@0 369 */
michael@0 370 ResourceBundle
michael@0 371 get(int32_t index,
michael@0 372 UErrorCode& status) const;
michael@0 373
michael@0 374 /**
michael@0 375 * Returns the string in a given resource at the specified index.
michael@0 376 *
michael@0 377 * @param index an index to the wanted string.
michael@0 378 * @param status fills in the outgoing error code
michael@0 379 * @return an UnicodeString object. If there is an error, string is bogus
michael@0 380 * @stable ICU 2.0
michael@0 381 */
michael@0 382 UnicodeString
michael@0 383 getStringEx(int32_t index,
michael@0 384 UErrorCode& status) const;
michael@0 385
michael@0 386 /**
michael@0 387 * Returns a resource in a resource that has a given key. This procedure works only with table
michael@0 388 * resources.
michael@0 389 *
michael@0 390 * @param key a key associated with the wanted resource
michael@0 391 * @param status fills in the outgoing error code.
michael@0 392 * @return ResourceBundle object. If there is an error, resource is invalid.
michael@0 393 * @stable ICU 2.0
michael@0 394 */
michael@0 395 ResourceBundle
michael@0 396 get(const char* key,
michael@0 397 UErrorCode& status) const;
michael@0 398
michael@0 399 /**
michael@0 400 * Returns a string in a resource that has a given key. This procedure works only with table
michael@0 401 * resources.
michael@0 402 *
michael@0 403 * @param key a key associated with the wanted string
michael@0 404 * @param status fills in the outgoing error code
michael@0 405 * @return an UnicodeString object. If there is an error, string is bogus
michael@0 406 * @stable ICU 2.0
michael@0 407 */
michael@0 408 UnicodeString
michael@0 409 getStringEx(const char* key,
michael@0 410 UErrorCode& status) const;
michael@0 411
michael@0 412 #ifndef U_HIDE_DEPRECATED_API
michael@0 413 /**
michael@0 414 * Return the version number associated with this ResourceBundle as a string. Please
michael@0 415 * use getVersion, as this method is going to be deprecated.
michael@0 416 *
michael@0 417 * @return A version number string as specified in the resource bundle or its parent.
michael@0 418 * The caller does not own this string.
michael@0 419 * @see getVersion
michael@0 420 * @deprecated ICU 2.8 Use getVersion instead.
michael@0 421 */
michael@0 422 const char*
michael@0 423 getVersionNumber(void) const;
michael@0 424 #endif /* U_HIDE_DEPRECATED_API */
michael@0 425
michael@0 426 /**
michael@0 427 * Return the version number associated with this ResourceBundle as a UVersionInfo array.
michael@0 428 *
michael@0 429 * @param versionInfo A UVersionInfo array that is filled with the version number
michael@0 430 * as specified in the resource bundle or its parent.
michael@0 431 * @stable ICU 2.0
michael@0 432 */
michael@0 433 void
michael@0 434 getVersion(UVersionInfo versionInfo) const;
michael@0 435
michael@0 436 #ifndef U_HIDE_DEPRECATED_API
michael@0 437 /**
michael@0 438 * Return the Locale associated with this ResourceBundle.
michael@0 439 *
michael@0 440 * @return a Locale object
michael@0 441 * @deprecated ICU 2.8 Use getLocale(ULocDataLocaleType type, UErrorCode &status) overload instead.
michael@0 442 */
michael@0 443 const Locale&
michael@0 444 getLocale(void) const;
michael@0 445 #endif /* U_HIDE_DEPRECATED_API */
michael@0 446
michael@0 447 /**
michael@0 448 * Return the Locale associated with this ResourceBundle.
michael@0 449 * @param type You can choose between requested, valid and actual
michael@0 450 * locale. For description see the definition of
michael@0 451 * ULocDataLocaleType in uloc.h
michael@0 452 * @param status just for catching illegal arguments
michael@0 453 *
michael@0 454 * @return a Locale object
michael@0 455 * @stable ICU 2.8
michael@0 456 */
michael@0 457 const Locale
michael@0 458 getLocale(ULocDataLocaleType type, UErrorCode &status) const;
michael@0 459 #ifndef U_HIDE_INTERNAL_API
michael@0 460 /**
michael@0 461 * This API implements multilevel fallback
michael@0 462 * @internal
michael@0 463 */
michael@0 464 ResourceBundle
michael@0 465 getWithFallback(const char* key, UErrorCode& status);
michael@0 466 #endif /* U_HIDE_INTERNAL_API */
michael@0 467 /**
michael@0 468 * ICU "poor man's RTTI", returns a UClassID for the actual class.
michael@0 469 *
michael@0 470 * @stable ICU 2.2
michael@0 471 */
michael@0 472 virtual UClassID getDynamicClassID() const;
michael@0 473
michael@0 474 /**
michael@0 475 * ICU "poor man's RTTI", returns a UClassID for this class.
michael@0 476 *
michael@0 477 * @stable ICU 2.2
michael@0 478 */
michael@0 479 static UClassID U_EXPORT2 getStaticClassID();
michael@0 480
michael@0 481 private:
michael@0 482 ResourceBundle(); // default constructor not implemented
michael@0 483
michael@0 484 UResourceBundle *fResource;
michael@0 485 void constructForLocale(const UnicodeString& path, const Locale& locale, UErrorCode& error);
michael@0 486 Locale *fLocale;
michael@0 487 };
michael@0 488
michael@0 489 U_NAMESPACE_END
michael@0 490 #endif

mercurial