|
||||
Warning, file /include/unicode/ures.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 // © 2016 and later: Unicode, Inc. and others. 0002 // License & terms of use: http://www.unicode.org/copyright.html 0003 /* 0004 ********************************************************************** 0005 * Copyright (C) 1997-2016, International Business Machines 0006 * Corporation and others. All Rights Reserved. 0007 ********************************************************************** 0008 * 0009 * File URES.H (formerly CRESBUND.H) 0010 * 0011 * Modification History: 0012 * 0013 * Date Name Description 0014 * 04/01/97 aliu Creation. 0015 * 02/22/99 damiba overhaul. 0016 * 04/04/99 helena Fixed internal header inclusion. 0017 * 04/15/99 Madhu Updated Javadoc 0018 * 06/14/99 stephen Removed functions taking a filename suffix. 0019 * 07/20/99 stephen Language-independent typedef to void* 0020 * 11/09/99 weiv Added ures_getLocale() 0021 * 06/24/02 weiv Added support for resource sharing 0022 ****************************************************************************** 0023 */ 0024 0025 #ifndef URES_H 0026 #define URES_H 0027 0028 #include "unicode/char16ptr.h" 0029 #include "unicode/utypes.h" 0030 #include "unicode/uloc.h" 0031 0032 #if U_SHOW_CPLUSPLUS_API 0033 #include "unicode/localpointer.h" 0034 #endif // U_SHOW_CPLUSPLUS_API 0035 0036 /** 0037 * \file 0038 * \brief C API: Resource Bundle 0039 * 0040 * <h2>C API: Resource Bundle</h2> 0041 * 0042 * C API representing a collection of resource information pertaining to a given 0043 * locale. A resource bundle provides a way of accessing locale- specific information in 0044 * a data file. You create a resource bundle that manages the resources for a given 0045 * locale and then ask it for individual resources. 0046 * <P> 0047 * Resource bundles in ICU4C are currently defined using text files which conform to the following 0048 * <a href="https://github.com/unicode-org/icu-docs/blob/main/design/bnf_rb.txt">BNF definition</a>. 0049 * More on resource bundle concepts and syntax can be found in the 0050 * <a href="https://unicode-org.github.io/icu/userguide/locale/resources">Users Guide</a>. 0051 * <P> 0052 */ 0053 0054 /** 0055 * UResourceBundle is an opaque type for handles for resource bundles in C APIs. 0056 * @stable ICU 2.0 0057 */ 0058 struct UResourceBundle; 0059 0060 /** 0061 * @stable ICU 2.0 0062 */ 0063 typedef struct UResourceBundle UResourceBundle; 0064 0065 /** 0066 * Numeric constants for types of resource items. 0067 * @see ures_getType 0068 * @stable ICU 2.0 0069 */ 0070 typedef enum { 0071 /** Resource type constant for "no resource". @stable ICU 2.6 */ 0072 URES_NONE=-1, 0073 0074 /** Resource type constant for 16-bit Unicode strings. @stable ICU 2.6 */ 0075 URES_STRING=0, 0076 0077 /** Resource type constant for binary data. @stable ICU 2.6 */ 0078 URES_BINARY=1, 0079 0080 /** Resource type constant for tables of key-value pairs. @stable ICU 2.6 */ 0081 URES_TABLE=2, 0082 0083 /** 0084 * Resource type constant for aliases; 0085 * internally stores a string which identifies the actual resource 0086 * storing the data (can be in a different resource bundle). 0087 * Resolved internally before delivering the actual resource through the API. 0088 * @stable ICU 2.6 0089 */ 0090 URES_ALIAS=3, 0091 0092 /** 0093 * Resource type constant for a single 28-bit integer, interpreted as 0094 * signed or unsigned by the ures_getInt() or ures_getUInt() function. 0095 * @see ures_getInt 0096 * @see ures_getUInt 0097 * @stable ICU 2.6 0098 */ 0099 URES_INT=7, 0100 0101 /** Resource type constant for arrays of resources. @stable ICU 2.6 */ 0102 URES_ARRAY=8, 0103 0104 /** 0105 * Resource type constant for vectors of 32-bit integers. 0106 * @see ures_getIntVector 0107 * @stable ICU 2.6 0108 */ 0109 URES_INT_VECTOR = 14, 0110 #ifndef U_HIDE_DEPRECATED_API 0111 /** @deprecated ICU 2.6 Use the URES_ constant instead. */ 0112 RES_NONE=URES_NONE, 0113 /** @deprecated ICU 2.6 Use the URES_ constant instead. */ 0114 RES_STRING=URES_STRING, 0115 /** @deprecated ICU 2.6 Use the URES_ constant instead. */ 0116 RES_BINARY=URES_BINARY, 0117 /** @deprecated ICU 2.6 Use the URES_ constant instead. */ 0118 RES_TABLE=URES_TABLE, 0119 /** @deprecated ICU 2.6 Use the URES_ constant instead. */ 0120 RES_ALIAS=URES_ALIAS, 0121 /** @deprecated ICU 2.6 Use the URES_ constant instead. */ 0122 RES_INT=URES_INT, 0123 /** @deprecated ICU 2.6 Use the URES_ constant instead. */ 0124 RES_ARRAY=URES_ARRAY, 0125 /** @deprecated ICU 2.6 Use the URES_ constant instead. */ 0126 RES_INT_VECTOR=URES_INT_VECTOR, 0127 /** @deprecated ICU 2.6 Not used. */ 0128 RES_RESERVED=15, 0129 0130 /** 0131 * One more than the highest normal UResType value. 0132 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. 0133 */ 0134 URES_LIMIT = 16 0135 #endif // U_HIDE_DEPRECATED_API 0136 } UResType; 0137 0138 /* 0139 * Functions to create and destroy resource bundles. 0140 */ 0141 0142 /** 0143 * Opens a UResourceBundle, from which users can extract strings by using 0144 * their corresponding keys. 0145 * Note that the caller is responsible of calling <TT>ures_close</TT> on each successfully 0146 * opened resource bundle. 0147 * @param packageName The packageName and locale together point to an ICU udata object, 0148 * as defined by <code> udata_open( packageName, "res", locale, err) </code> 0149 * or equivalent. Typically, packageName will refer to a (.dat) file, or to 0150 * a package registered with udata_setAppData(). Using a full file or directory 0151 * pathname for packageName is deprecated. If NULL, ICU data will be used. 0152 * @param locale specifies the locale for which we want to open the resource 0153 * if NULL, the default locale will be used. If strlen(locale) == 0 0154 * root locale will be used. 0155 * 0156 * @param status fills in the outgoing error code. 0157 * The UErrorCode err parameter is used to return status information to the user. To 0158 * check whether the construction succeeded or not, you should check the value of 0159 * U_SUCCESS(err). If you wish more detailed information, you can check for 0160 * informational status results which still indicate success. U_USING_FALLBACK_WARNING 0161 * indicates that a fall back locale was used. For example, 'de_CH' was requested, 0162 * but nothing was found there, so 'de' was used. U_USING_DEFAULT_WARNING indicates that 0163 * the default locale data or root locale data was used; neither the requested locale 0164 * nor any of its fall back locales could be found. Please see the users guide for more 0165 * information on this topic. 0166 * @return a newly allocated resource bundle. 0167 * @see ures_close 0168 * @stable ICU 2.0 0169 */ 0170 U_CAPI UResourceBundle* U_EXPORT2 0171 ures_open(const char* packageName, 0172 const char* locale, 0173 UErrorCode* status); 0174 0175 0176 /** This function does not care what kind of localeID is passed in. It simply opens a bundle with 0177 * that name. Fallback mechanism is disabled for the new bundle. If the requested bundle contains 0178 * an %%ALIAS directive, the results are undefined. 0179 * @param packageName The packageName and locale together point to an ICU udata object, 0180 * as defined by <code> udata_open( packageName, "res", locale, err) </code> 0181 * or equivalent. Typically, packageName will refer to a (.dat) file, or to 0182 * a package registered with udata_setAppData(). Using a full file or directory 0183 * pathname for packageName is deprecated. If NULL, ICU data will be used. 0184 * @param locale specifies the locale for which we want to open the resource 0185 * if NULL, the default locale will be used. If strlen(locale) == 0 0186 * root locale will be used. 0187 * 0188 * @param status fills in the outgoing error code. Either U_ZERO_ERROR or U_MISSING_RESOURCE_ERROR 0189 * @return a newly allocated resource bundle or NULL if it doesn't exist. 0190 * @see ures_close 0191 * @stable ICU 2.0 0192 */ 0193 U_CAPI UResourceBundle* U_EXPORT2 0194 ures_openDirect(const char* packageName, 0195 const char* locale, 0196 UErrorCode* status); 0197 0198 /** 0199 * Same as ures_open() but takes a const UChar *path. 0200 * This path will be converted to char * using the default converter, 0201 * then ures_open() is called. 0202 * 0203 * @param packageName The packageName and locale together point to an ICU udata object, 0204 * as defined by <code> udata_open( packageName, "res", locale, err) </code> 0205 * or equivalent. Typically, packageName will refer to a (.dat) file, or to 0206 * a package registered with udata_setAppData(). Using a full file or directory 0207 * pathname for packageName is deprecated. If NULL, ICU data will be used. 0208 * @param locale specifies the locale for which we want to open the resource 0209 * if NULL, the default locale will be used. If strlen(locale) == 0 0210 * root locale will be used. 0211 * @param status fills in the outgoing error code. 0212 * @return a newly allocated resource bundle. 0213 * @see ures_open 0214 * @stable ICU 2.0 0215 */ 0216 U_CAPI UResourceBundle* U_EXPORT2 0217 ures_openU(const UChar* packageName, 0218 const char* locale, 0219 UErrorCode* status); 0220 0221 #ifndef U_HIDE_DEPRECATED_API 0222 /** 0223 * Returns the number of strings/arrays in resource bundles. 0224 * Better to use ures_getSize, as this function will be deprecated. 0225 * 0226 *@param resourceBundle resource bundle containing the desired strings 0227 *@param resourceKey key tagging the resource 0228 *@param err fills in the outgoing error code 0229 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found 0230 * could be a non-failing error 0231 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_FALLBACK_WARNING </TT> 0232 *@return: for <STRONG>Arrays</STRONG>: returns the number of resources in the array 0233 * <STRONG>Tables</STRONG>: returns the number of resources in the table 0234 * <STRONG>single string</STRONG>: returns 1 0235 *@see ures_getSize 0236 * @deprecated ICU 2.8 User ures_getSize instead 0237 */ 0238 U_DEPRECATED int32_t U_EXPORT2 0239 ures_countArrayItems(const UResourceBundle* resourceBundle, 0240 const char* resourceKey, 0241 UErrorCode* err); 0242 #endif /* U_HIDE_DEPRECATED_API */ 0243 0244 /** 0245 * Close a resource bundle, all pointers returned from the various ures_getXXX calls 0246 * on this particular bundle should be considered invalid henceforth. 0247 * 0248 * @param resourceBundle a pointer to a resourceBundle struct. Can be NULL. 0249 * @see ures_open 0250 * @stable ICU 2.0 0251 */ 0252 U_CAPI void U_EXPORT2 0253 ures_close(UResourceBundle* resourceBundle); 0254 0255 #if U_SHOW_CPLUSPLUS_API 0256 0257 U_NAMESPACE_BEGIN 0258 0259 /** 0260 * \class LocalUResourceBundlePointer 0261 * "Smart pointer" class, closes a UResourceBundle via ures_close(). 0262 * For most methods see the LocalPointerBase base class. 0263 * 0264 * @see LocalPointerBase 0265 * @see LocalPointer 0266 * @stable ICU 4.4 0267 */ 0268 U_DEFINE_LOCAL_OPEN_POINTER(LocalUResourceBundlePointer, UResourceBundle, ures_close); 0269 0270 U_NAMESPACE_END 0271 0272 #endif 0273 0274 #ifndef U_HIDE_DEPRECATED_API 0275 /** 0276 * Return the version number associated with this ResourceBundle as a string. Please 0277 * use ures_getVersion as this function is going to be deprecated. 0278 * 0279 * @param resourceBundle The resource bundle for which the version is checked. 0280 * @return A version number string as specified in the resource bundle or its parent. 0281 * The caller does not own this string. 0282 * @see ures_getVersion 0283 * @deprecated ICU 2.8 Use ures_getVersion instead. 0284 */ 0285 U_DEPRECATED const char* U_EXPORT2 0286 ures_getVersionNumber(const UResourceBundle* resourceBundle); 0287 #endif /* U_HIDE_DEPRECATED_API */ 0288 0289 /** 0290 * Return the version number associated with this ResourceBundle as an 0291 * UVersionInfo array. 0292 * 0293 * @param resB The resource bundle for which the version is checked. 0294 * @param versionInfo A UVersionInfo array that is filled with the version number 0295 * as specified in the resource bundle or its parent. 0296 * @stable ICU 2.0 0297 */ 0298 U_CAPI void U_EXPORT2 0299 ures_getVersion(const UResourceBundle* resB, 0300 UVersionInfo versionInfo); 0301 0302 #ifndef U_HIDE_DEPRECATED_API 0303 /** 0304 * Return the name of the Locale associated with this ResourceBundle. This API allows 0305 * you to query for the real locale of the resource. For example, if you requested 0306 * "en_US_CALIFORNIA" and only "en_US" bundle exists, "en_US" will be returned. 0307 * For subresources, the locale where this resource comes from will be returned. 0308 * If fallback has occurred, getLocale will reflect this. 0309 * 0310 * @param resourceBundle resource bundle in question 0311 * @param status just for catching illegal arguments 0312 * @return A Locale name 0313 * @deprecated ICU 2.8 Use ures_getLocaleByType instead. 0314 */ 0315 U_DEPRECATED const char* U_EXPORT2 0316 ures_getLocale(const UResourceBundle* resourceBundle, 0317 UErrorCode* status); 0318 #endif /* U_HIDE_DEPRECATED_API */ 0319 0320 /** 0321 * Return the name of the Locale associated with this ResourceBundle. 0322 * You can choose between requested, valid and real locale. 0323 * 0324 * @param resourceBundle resource bundle in question 0325 * @param type You can choose between requested, valid and actual 0326 * locale. For description see the definition of 0327 * ULocDataLocaleType in uloc.h 0328 * @param status just for catching illegal arguments 0329 * @return A Locale name 0330 * @stable ICU 2.8 0331 */ 0332 U_CAPI const char* U_EXPORT2 0333 ures_getLocaleByType(const UResourceBundle* resourceBundle, 0334 ULocDataLocaleType type, 0335 UErrorCode* status); 0336 0337 0338 #ifndef U_HIDE_INTERNAL_API 0339 /** 0340 * Same as ures_open() but uses the fill-in parameter instead of allocating a new bundle. 0341 * 0342 * TODO need to revisit usefulness of this function 0343 * and usage model for fillIn parameters without knowing sizeof(UResourceBundle) 0344 * @param r The existing UResourceBundle to fill in. If NULL then status will be 0345 * set to U_ILLEGAL_ARGUMENT_ERROR. 0346 * @param packageName The packageName and locale together point to an ICU udata object, 0347 * as defined by <code> udata_open( packageName, "res", locale, err) </code> 0348 * or equivalent. Typically, packageName will refer to a (.dat) file, or to 0349 * a package registered with udata_setAppData(). Using a full file or directory 0350 * pathname for packageName is deprecated. If NULL, ICU data will be used. 0351 * @param localeID specifies the locale for which we want to open the resource 0352 * @param status The error code. 0353 * @internal 0354 */ 0355 U_CAPI void U_EXPORT2 0356 ures_openFillIn(UResourceBundle *r, 0357 const char* packageName, 0358 const char* localeID, 0359 UErrorCode* status); 0360 #endif /* U_HIDE_INTERNAL_API */ 0361 0362 /** 0363 * Returns a string from a string resource type 0364 * 0365 * @param resourceBundle a string resource 0366 * @param len fills in the length of resulting string 0367 * @param status fills in the outgoing error code 0368 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found 0369 * Always check the value of status. Don't count on returning NULL. 0370 * could be a non-failing error 0371 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT> 0372 * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file. 0373 * @see ures_getBinary 0374 * @see ures_getIntVector 0375 * @see ures_getInt 0376 * @see ures_getUInt 0377 * @stable ICU 2.0 0378 */ 0379 U_CAPI const UChar* U_EXPORT2 0380 ures_getString(const UResourceBundle* resourceBundle, 0381 int32_t* len, 0382 UErrorCode* status); 0383 0384 /** 0385 * Returns a UTF-8 string from a string resource. 0386 * The UTF-8 string may be returnable directly as a pointer, or 0387 * it may need to be copied, or transformed from UTF-16 using u_strToUTF8() 0388 * or equivalent. 0389 * 0390 * If forceCopy==true, then the string is always written to the dest buffer 0391 * and dest is returned. 0392 * 0393 * If forceCopy==false, then the string is returned as a pointer if possible, 0394 * without needing a dest buffer (it can be NULL). If the string needs to be 0395 * copied or transformed, then it may be placed into dest at an arbitrary offset. 0396 * 0397 * If the string is to be written to dest, then U_BUFFER_OVERFLOW_ERROR and 0398 * U_STRING_NOT_TERMINATED_WARNING are set if appropriate, as usual. 0399 * 0400 * If the string is transformed from UTF-16, then a conversion error may occur 0401 * if an unpaired surrogate is encountered. If the function is successful, then 0402 * the output UTF-8 string is always well-formed. 0403 * 0404 * @param resB Resource bundle. 0405 * @param dest Destination buffer. Can be NULL only if capacity=*length==0. 0406 * @param length Input: Capacity of destination buffer. 0407 * Output: Actual length of the UTF-8 string, not counting the 0408 * terminating NUL, even in case of U_BUFFER_OVERFLOW_ERROR. 0409 * Can be NULL, meaning capacity=0 and the string length is not 0410 * returned to the caller. 0411 * @param forceCopy If true, then the output string will always be written to 0412 * dest, with U_BUFFER_OVERFLOW_ERROR and 0413 * U_STRING_NOT_TERMINATED_WARNING set if appropriate. 0414 * If false, then the dest buffer may or may not contain a 0415 * copy of the string. dest may or may not be modified. 0416 * If a copy needs to be written, then the UErrorCode parameter 0417 * indicates overflow etc. as usual. 0418 * @param status Pointer to a standard ICU error code. Its input value must 0419 * pass the U_SUCCESS() test, or else the function returns 0420 * immediately. Check for U_FAILURE() on output or use with 0421 * function chaining. (See User Guide for details.) 0422 * @return The pointer to the UTF-8 string. It may be dest, or at some offset 0423 * from dest (only if !forceCopy), or in unrelated memory. 0424 * Always NUL-terminated unless the string was written to dest and 0425 * length==capacity (in which case U_STRING_NOT_TERMINATED_WARNING is set). 0426 * 0427 * @see ures_getString 0428 * @see u_strToUTF8 0429 * @stable ICU 3.6 0430 */ 0431 U_CAPI const char * U_EXPORT2 0432 ures_getUTF8String(const UResourceBundle *resB, 0433 char *dest, int32_t *length, 0434 UBool forceCopy, 0435 UErrorCode *status); 0436 0437 /** 0438 * Returns a binary data from a binary resource. 0439 * 0440 * @param resourceBundle a string resource 0441 * @param len fills in the length of resulting byte chunk 0442 * @param status fills in the outgoing error code 0443 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found 0444 * Always check the value of status. Don't count on returning NULL. 0445 * could be a non-failing error 0446 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT> 0447 * @return a pointer to a chunk of unsigned bytes which live in a memory mapped/DLL file. 0448 * @see ures_getString 0449 * @see ures_getIntVector 0450 * @see ures_getInt 0451 * @see ures_getUInt 0452 * @stable ICU 2.0 0453 */ 0454 U_CAPI const uint8_t* U_EXPORT2 0455 ures_getBinary(const UResourceBundle* resourceBundle, 0456 int32_t* len, 0457 UErrorCode* status); 0458 0459 /** 0460 * Returns a 32 bit integer array from a resource. 0461 * 0462 * @param resourceBundle an int vector resource 0463 * @param len fills in the length of resulting byte chunk 0464 * @param status fills in the outgoing error code 0465 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found 0466 * Always check the value of status. Don't count on returning NULL. 0467 * could be a non-failing error 0468 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT> 0469 * @return a pointer to a chunk of integers which live in a memory mapped/DLL file. 0470 * @see ures_getBinary 0471 * @see ures_getString 0472 * @see ures_getInt 0473 * @see ures_getUInt 0474 * @stable ICU 2.0 0475 */ 0476 U_CAPI const int32_t* U_EXPORT2 0477 ures_getIntVector(const UResourceBundle* resourceBundle, 0478 int32_t* len, 0479 UErrorCode* status); 0480 0481 /** 0482 * Returns an unsigned integer from a resource. 0483 * This integer is originally 28 bits. 0484 * 0485 * @param resourceBundle a string resource 0486 * @param status fills in the outgoing error code 0487 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found 0488 * could be a non-failing error 0489 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT> 0490 * @return an integer value 0491 * @see ures_getInt 0492 * @see ures_getIntVector 0493 * @see ures_getBinary 0494 * @see ures_getString 0495 * @stable ICU 2.0 0496 */ 0497 U_CAPI uint32_t U_EXPORT2 0498 ures_getUInt(const UResourceBundle* resourceBundle, 0499 UErrorCode *status); 0500 0501 /** 0502 * Returns a signed integer from a resource. 0503 * This integer is originally 28 bit and the sign gets propagated. 0504 * 0505 * @param resourceBundle a string resource 0506 * @param status fills in the outgoing error code 0507 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found 0508 * could be a non-failing error 0509 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT> 0510 * @return an integer value 0511 * @see ures_getUInt 0512 * @see ures_getIntVector 0513 * @see ures_getBinary 0514 * @see ures_getString 0515 * @stable ICU 2.0 0516 */ 0517 U_CAPI int32_t U_EXPORT2 0518 ures_getInt(const UResourceBundle* resourceBundle, 0519 UErrorCode *status); 0520 0521 /** 0522 * Returns the size of a resource. Size for scalar types is always 1, 0523 * and for vector/table types is the number of child resources. 0524 * @warning Integer array is treated as a scalar type. There are no 0525 * APIs to access individual members of an integer array. It 0526 * is always returned as a whole. 0527 * @param resourceBundle a resource 0528 * @return number of resources in a given resource. 0529 * @stable ICU 2.0 0530 */ 0531 U_CAPI int32_t U_EXPORT2 0532 ures_getSize(const UResourceBundle *resourceBundle); 0533 0534 /** 0535 * Returns the type of a resource. Available types are defined in enum UResType 0536 * 0537 * @param resourceBundle a resource 0538 * @return type of the given resource. 0539 * @see UResType 0540 * @stable ICU 2.0 0541 */ 0542 U_CAPI UResType U_EXPORT2 0543 ures_getType(const UResourceBundle *resourceBundle); 0544 0545 /** 0546 * Returns the key associated with a given resource. Not all the resources have a key - only 0547 * those that are members of a table. 0548 * 0549 * @param resourceBundle a resource 0550 * @return a key associated to this resource, or NULL if it doesn't have a key 0551 * @stable ICU 2.0 0552 */ 0553 U_CAPI const char * U_EXPORT2 0554 ures_getKey(const UResourceBundle *resourceBundle); 0555 0556 /* ITERATION API 0557 This API provides means for iterating through a resource 0558 */ 0559 0560 /** 0561 * Resets the internal context of a resource so that iteration starts from the first element. 0562 * 0563 * @param resourceBundle a resource 0564 * @stable ICU 2.0 0565 */ 0566 U_CAPI void U_EXPORT2 0567 ures_resetIterator(UResourceBundle *resourceBundle); 0568 0569 /** 0570 * Checks whether the given resource has another element to iterate over. 0571 * 0572 * @param resourceBundle a resource 0573 * @return true if there are more elements, false if there is no more elements 0574 * @stable ICU 2.0 0575 */ 0576 U_CAPI UBool U_EXPORT2 0577 ures_hasNext(const UResourceBundle *resourceBundle); 0578 0579 /** 0580 * Returns the next resource in a given resource or NULL if there are no more resources 0581 * to iterate over. Features a fill-in parameter. 0582 * 0583 * @param resourceBundle a resource 0584 * @param fillIn if NULL a new UResourceBundle struct is allocated and must be closed by the caller. 0585 * Alternatively, you can supply a struct to be filled by this function. 0586 * @param status fills in the outgoing error code. You may still get a non NULL result even if an 0587 * error occurred. Check status instead. 0588 * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must close it 0589 * @stable ICU 2.0 0590 */ 0591 U_CAPI UResourceBundle* U_EXPORT2 0592 ures_getNextResource(UResourceBundle *resourceBundle, 0593 UResourceBundle *fillIn, 0594 UErrorCode *status); 0595 0596 /** 0597 * Returns the next string in a given resource or NULL if there are no more resources 0598 * to iterate over. 0599 * 0600 * @param resourceBundle a resource 0601 * @param len fill in length of the string 0602 * @param key fill in for key associated with this string. NULL if no key 0603 * @param status fills in the outgoing error code. If an error occurred, we may return NULL, but don't 0604 * count on it. Check status instead! 0605 * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file. 0606 * @stable ICU 2.0 0607 */ 0608 U_CAPI const UChar* U_EXPORT2 0609 ures_getNextString(UResourceBundle *resourceBundle, 0610 int32_t* len, 0611 const char ** key, 0612 UErrorCode *status); 0613 0614 /** 0615 * Returns the resource in a given resource at the specified index. Features a fill-in parameter. 0616 * 0617 * @param resourceBundle the resource bundle from which to get a sub-resource 0618 * @param indexR an index to the wanted resource. 0619 * @param fillIn if NULL a new UResourceBundle struct is allocated and must be closed by the caller. 0620 * Alternatively, you can supply a struct to be filled by this function. 0621 * @param status fills in the outgoing error code. Don't count on NULL being returned if an error has 0622 * occurred. Check status instead. 0623 * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must close it 0624 * @stable ICU 2.0 0625 */ 0626 U_CAPI UResourceBundle* U_EXPORT2 0627 ures_getByIndex(const UResourceBundle *resourceBundle, 0628 int32_t indexR, 0629 UResourceBundle *fillIn, 0630 UErrorCode *status); 0631 0632 /** 0633 * Returns the string in a given resource at the specified index. 0634 * 0635 * @param resourceBundle a resource 0636 * @param indexS an index to the wanted string. 0637 * @param len fill in length of the string 0638 * @param status fills in the outgoing error code. If an error occurred, we may return NULL, but don't 0639 * count on it. Check status instead! 0640 * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file. 0641 * @stable ICU 2.0 0642 */ 0643 U_CAPI const UChar* U_EXPORT2 0644 ures_getStringByIndex(const UResourceBundle *resourceBundle, 0645 int32_t indexS, 0646 int32_t* len, 0647 UErrorCode *status); 0648 0649 /** 0650 * Returns a UTF-8 string from a resource at the specified index. 0651 * The UTF-8 string may be returnable directly as a pointer, or 0652 * it may need to be copied, or transformed from UTF-16 using u_strToUTF8() 0653 * or equivalent. 0654 * 0655 * If forceCopy==true, then the string is always written to the dest buffer 0656 * and dest is returned. 0657 * 0658 * If forceCopy==false, then the string is returned as a pointer if possible, 0659 * without needing a dest buffer (it can be NULL). If the string needs to be 0660 * copied or transformed, then it may be placed into dest at an arbitrary offset. 0661 * 0662 * If the string is to be written to dest, then U_BUFFER_OVERFLOW_ERROR and 0663 * U_STRING_NOT_TERMINATED_WARNING are set if appropriate, as usual. 0664 * 0665 * If the string is transformed from UTF-16, then a conversion error may occur 0666 * if an unpaired surrogate is encountered. If the function is successful, then 0667 * the output UTF-8 string is always well-formed. 0668 * 0669 * @param resB Resource bundle. 0670 * @param stringIndex An index to the wanted string. 0671 * @param dest Destination buffer. Can be NULL only if capacity=*length==0. 0672 * @param pLength Input: Capacity of destination buffer. 0673 * Output: Actual length of the UTF-8 string, not counting the 0674 * terminating NUL, even in case of U_BUFFER_OVERFLOW_ERROR. 0675 * Can be NULL, meaning capacity=0 and the string length is not 0676 * returned to the caller. 0677 * @param forceCopy If true, then the output string will always be written to 0678 * dest, with U_BUFFER_OVERFLOW_ERROR and 0679 * U_STRING_NOT_TERMINATED_WARNING set if appropriate. 0680 * If false, then the dest buffer may or may not contain a 0681 * copy of the string. dest may or may not be modified. 0682 * If a copy needs to be written, then the UErrorCode parameter 0683 * indicates overflow etc. as usual. 0684 * @param status Pointer to a standard ICU error code. Its input value must 0685 * pass the U_SUCCESS() test, or else the function returns 0686 * immediately. Check for U_FAILURE() on output or use with 0687 * function chaining. (See User Guide for details.) 0688 * @return The pointer to the UTF-8 string. It may be dest, or at some offset 0689 * from dest (only if !forceCopy), or in unrelated memory. 0690 * Always NUL-terminated unless the string was written to dest and 0691 * length==capacity (in which case U_STRING_NOT_TERMINATED_WARNING is set). 0692 * 0693 * @see ures_getStringByIndex 0694 * @see u_strToUTF8 0695 * @stable ICU 3.6 0696 */ 0697 U_CAPI const char * U_EXPORT2 0698 ures_getUTF8StringByIndex(const UResourceBundle *resB, 0699 int32_t stringIndex, 0700 char *dest, int32_t *pLength, 0701 UBool forceCopy, 0702 UErrorCode *status); 0703 0704 /** 0705 * Returns a resource in a given resource that has a given key. This procedure works only with table 0706 * resources. Features a fill-in parameter. 0707 * 0708 * @param resourceBundle a resource 0709 * @param key a key associated with the wanted resource 0710 * @param fillIn if NULL a new UResourceBundle struct is allocated and must be closed by the caller. 0711 * Alternatively, you can supply a struct to be filled by this function. 0712 * @param status fills in the outgoing error code. 0713 * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must close it 0714 * @stable ICU 2.0 0715 */ 0716 U_CAPI UResourceBundle* U_EXPORT2 0717 ures_getByKey(const UResourceBundle *resourceBundle, 0718 const char* key, 0719 UResourceBundle *fillIn, 0720 UErrorCode *status); 0721 0722 /** 0723 * Returns a string in a given resource that has a given key. This procedure works only with table 0724 * resources. 0725 * 0726 * @param resB a resource 0727 * @param key a key associated with the wanted string 0728 * @param len fill in length of the string 0729 * @param status fills in the outgoing error code. If an error occurred, we may return NULL, but don't 0730 * count on it. Check status instead! 0731 * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file. 0732 * @stable ICU 2.0 0733 */ 0734 U_CAPI const UChar* U_EXPORT2 0735 ures_getStringByKey(const UResourceBundle *resB, 0736 const char* key, 0737 int32_t* len, 0738 UErrorCode *status); 0739 0740 /** 0741 * Returns a UTF-8 string from a resource and a key. 0742 * This function works only with table resources. 0743 * 0744 * The UTF-8 string may be returnable directly as a pointer, or 0745 * it may need to be copied, or transformed from UTF-16 using u_strToUTF8() 0746 * or equivalent. 0747 * 0748 * If forceCopy==true, then the string is always written to the dest buffer 0749 * and dest is returned. 0750 * 0751 * If forceCopy==false, then the string is returned as a pointer if possible, 0752 * without needing a dest buffer (it can be NULL). If the string needs to be 0753 * copied or transformed, then it may be placed into dest at an arbitrary offset. 0754 * 0755 * If the string is to be written to dest, then U_BUFFER_OVERFLOW_ERROR and 0756 * U_STRING_NOT_TERMINATED_WARNING are set if appropriate, as usual. 0757 * 0758 * If the string is transformed from UTF-16, then a conversion error may occur 0759 * if an unpaired surrogate is encountered. If the function is successful, then 0760 * the output UTF-8 string is always well-formed. 0761 * 0762 * @param resB Resource bundle. 0763 * @param key A key associated with the wanted resource 0764 * @param dest Destination buffer. Can be NULL only if capacity=*length==0. 0765 * @param pLength Input: Capacity of destination buffer. 0766 * Output: Actual length of the UTF-8 string, not counting the 0767 * terminating NUL, even in case of U_BUFFER_OVERFLOW_ERROR. 0768 * Can be NULL, meaning capacity=0 and the string length is not 0769 * returned to the caller. 0770 * @param forceCopy If true, then the output string will always be written to 0771 * dest, with U_BUFFER_OVERFLOW_ERROR and 0772 * U_STRING_NOT_TERMINATED_WARNING set if appropriate. 0773 * If false, then the dest buffer may or may not contain a 0774 * copy of the string. dest may or may not be modified. 0775 * If a copy needs to be written, then the UErrorCode parameter 0776 * indicates overflow etc. as usual. 0777 * @param status Pointer to a standard ICU error code. Its input value must 0778 * pass the U_SUCCESS() test, or else the function returns 0779 * immediately. Check for U_FAILURE() on output or use with 0780 * function chaining. (See User Guide for details.) 0781 * @return The pointer to the UTF-8 string. It may be dest, or at some offset 0782 * from dest (only if !forceCopy), or in unrelated memory. 0783 * Always NUL-terminated unless the string was written to dest and 0784 * length==capacity (in which case U_STRING_NOT_TERMINATED_WARNING is set). 0785 * 0786 * @see ures_getStringByKey 0787 * @see u_strToUTF8 0788 * @stable ICU 3.6 0789 */ 0790 U_CAPI const char * U_EXPORT2 0791 ures_getUTF8StringByKey(const UResourceBundle *resB, 0792 const char *key, 0793 char *dest, int32_t *pLength, 0794 UBool forceCopy, 0795 UErrorCode *status); 0796 0797 #if U_SHOW_CPLUSPLUS_API 0798 #include "unicode/unistr.h" 0799 0800 U_NAMESPACE_BEGIN 0801 /** 0802 * Returns the string value from a string resource bundle. 0803 * 0804 * @param resB a resource, should have type URES_STRING 0805 * @param status: fills in the outgoing error code 0806 * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found 0807 * could be a non-failing error 0808 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT> 0809 * @return The string value, or a bogus string if there is a failure UErrorCode. 0810 * @stable ICU 2.0 0811 */ 0812 inline UnicodeString 0813 ures_getUnicodeString(const UResourceBundle *resB, UErrorCode* status) { 0814 UnicodeString result; 0815 int32_t len = 0; 0816 const char16_t *r = ConstChar16Ptr(ures_getString(resB, &len, status)); 0817 if(U_SUCCESS(*status)) { 0818 result.setTo(true, r, len); 0819 } else { 0820 result.setToBogus(); 0821 } 0822 return result; 0823 } 0824 0825 /** 0826 * Returns the next string in a resource, or an empty string if there are no more resources 0827 * to iterate over. 0828 * Use ures_getNextString() instead to distinguish between 0829 * the end of the iteration and a real empty string value. 0830 * 0831 * @param resB a resource 0832 * @param key fill in for key associated with this string 0833 * @param status fills in the outgoing error code 0834 * @return The string value, or a bogus string if there is a failure UErrorCode. 0835 * @stable ICU 2.0 0836 */ 0837 inline UnicodeString 0838 ures_getNextUnicodeString(UResourceBundle *resB, const char ** key, UErrorCode* status) { 0839 UnicodeString result; 0840 int32_t len = 0; 0841 const char16_t* r = ConstChar16Ptr(ures_getNextString(resB, &len, key, status)); 0842 if(U_SUCCESS(*status)) { 0843 result.setTo(true, r, len); 0844 } else { 0845 result.setToBogus(); 0846 } 0847 return result; 0848 } 0849 0850 /** 0851 * Returns the string in a given resource array or table at the specified index. 0852 * 0853 * @param resB a resource 0854 * @param indexS an index to the wanted string. 0855 * @param status fills in the outgoing error code 0856 * @return The string value, or a bogus string if there is a failure UErrorCode. 0857 * @stable ICU 2.0 0858 */ 0859 inline UnicodeString 0860 ures_getUnicodeStringByIndex(const UResourceBundle *resB, int32_t indexS, UErrorCode* status) { 0861 UnicodeString result; 0862 int32_t len = 0; 0863 const char16_t* r = ConstChar16Ptr(ures_getStringByIndex(resB, indexS, &len, status)); 0864 if(U_SUCCESS(*status)) { 0865 result.setTo(true, r, len); 0866 } else { 0867 result.setToBogus(); 0868 } 0869 return result; 0870 } 0871 0872 /** 0873 * Returns a string in a resource that has a given key. 0874 * This procedure works only with table resources. 0875 * 0876 * @param resB a resource 0877 * @param key a key associated with the wanted string 0878 * @param status fills in the outgoing error code 0879 * @return The string value, or a bogus string if there is a failure UErrorCode. 0880 * @stable ICU 2.0 0881 */ 0882 inline UnicodeString 0883 ures_getUnicodeStringByKey(const UResourceBundle *resB, const char* key, UErrorCode* status) { 0884 UnicodeString result; 0885 int32_t len = 0; 0886 const char16_t* r = ConstChar16Ptr(ures_getStringByKey(resB, key, &len, status)); 0887 if(U_SUCCESS(*status)) { 0888 result.setTo(true, r, len); 0889 } else { 0890 result.setToBogus(); 0891 } 0892 return result; 0893 } 0894 0895 U_NAMESPACE_END 0896 0897 #endif 0898 0899 /** 0900 * Create a string enumerator, owned by the caller, of all locales located within 0901 * the specified resource tree. 0902 * @param packageName name of the tree, such as (NULL) or U_ICUDATA_ALIAS or or "ICUDATA-coll" 0903 * This call is similar to uloc_getAvailable(). 0904 * @param status error code 0905 * @stable ICU 3.2 0906 */ 0907 U_CAPI UEnumeration* U_EXPORT2 0908 ures_openAvailableLocales(const char *packageName, UErrorCode *status); 0909 0910 0911 #endif /*_URES*/ 0912 /*eof*/
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |