ures.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. **********************************************************************
  5. * Copyright (C) 1997-2016, International Business Machines
  6. * Corporation and others. All Rights Reserved.
  7. **********************************************************************
  8. *
  9. * File URES.H (formerly CRESBUND.H)
  10. *
  11. * Modification History:
  12. *
  13. * Date Name Description
  14. * 04/01/97 aliu Creation.
  15. * 02/22/99 damiba overhaul.
  16. * 04/04/99 helena Fixed internal header inclusion.
  17. * 04/15/99 Madhu Updated Javadoc
  18. * 06/14/99 stephen Removed functions taking a filename suffix.
  19. * 07/20/99 stephen Language-independent typedef to void*
  20. * 11/09/99 weiv Added ures_getLocale()
  21. * 06/24/02 weiv Added support for resource sharing
  22. ******************************************************************************
  23. */
  24. #ifndef URES_H
  25. #define URES_H
  26. #include "unicode/char16ptr.h"
  27. #include "unicode/utypes.h"
  28. #include "unicode/uloc.h"
  29. #if U_SHOW_CPLUSPLUS_API
  30. #include "unicode/localpointer.h"
  31. #endif // U_SHOW_CPLUSPLUS_API
  32. /**
  33. * \file
  34. * \brief C API: Resource Bundle
  35. *
  36. * <h2>C API: Resource Bundle</h2>
  37. *
  38. * C API representing a collection of resource information pertaining to a given
  39. * locale. A resource bundle provides a way of accessing locale- specific information in
  40. * a data file. You create a resource bundle that manages the resources for a given
  41. * locale and then ask it for individual resources.
  42. * <P>
  43. * Resource bundles in ICU4C are currently defined using text files which conform to the following
  44. * <a href="https://github.com/unicode-org/icu-docs/blob/main/design/bnf_rb.txt">BNF definition</a>.
  45. * More on resource bundle concepts and syntax can be found in the
  46. * <a href="https://unicode-org.github.io/icu/userguide/locale/resources">Users Guide</a>.
  47. * <P>
  48. */
  49. /**
  50. * UResourceBundle is an opaque type for handles for resource bundles in C APIs.
  51. * @stable ICU 2.0
  52. */
  53. struct UResourceBundle;
  54. /**
  55. * @stable ICU 2.0
  56. */
  57. typedef struct UResourceBundle UResourceBundle;
  58. /**
  59. * Numeric constants for types of resource items.
  60. * @see ures_getType
  61. * @stable ICU 2.0
  62. */
  63. typedef enum {
  64. /** Resource type constant for "no resource". @stable ICU 2.6 */
  65. URES_NONE=-1,
  66. /** Resource type constant for 16-bit Unicode strings. @stable ICU 2.6 */
  67. URES_STRING=0,
  68. /** Resource type constant for binary data. @stable ICU 2.6 */
  69. URES_BINARY=1,
  70. /** Resource type constant for tables of key-value pairs. @stable ICU 2.6 */
  71. URES_TABLE=2,
  72. /**
  73. * Resource type constant for aliases;
  74. * internally stores a string which identifies the actual resource
  75. * storing the data (can be in a different resource bundle).
  76. * Resolved internally before delivering the actual resource through the API.
  77. * @stable ICU 2.6
  78. */
  79. URES_ALIAS=3,
  80. /**
  81. * Resource type constant for a single 28-bit integer, interpreted as
  82. * signed or unsigned by the ures_getInt() or ures_getUInt() function.
  83. * @see ures_getInt
  84. * @see ures_getUInt
  85. * @stable ICU 2.6
  86. */
  87. URES_INT=7,
  88. /** Resource type constant for arrays of resources. @stable ICU 2.6 */
  89. URES_ARRAY=8,
  90. /**
  91. * Resource type constant for vectors of 32-bit integers.
  92. * @see ures_getIntVector
  93. * @stable ICU 2.6
  94. */
  95. URES_INT_VECTOR = 14,
  96. #ifndef U_HIDE_DEPRECATED_API
  97. /** @deprecated ICU 2.6 Use the URES_ constant instead. */
  98. RES_NONE=URES_NONE,
  99. /** @deprecated ICU 2.6 Use the URES_ constant instead. */
  100. RES_STRING=URES_STRING,
  101. /** @deprecated ICU 2.6 Use the URES_ constant instead. */
  102. RES_BINARY=URES_BINARY,
  103. /** @deprecated ICU 2.6 Use the URES_ constant instead. */
  104. RES_TABLE=URES_TABLE,
  105. /** @deprecated ICU 2.6 Use the URES_ constant instead. */
  106. RES_ALIAS=URES_ALIAS,
  107. /** @deprecated ICU 2.6 Use the URES_ constant instead. */
  108. RES_INT=URES_INT,
  109. /** @deprecated ICU 2.6 Use the URES_ constant instead. */
  110. RES_ARRAY=URES_ARRAY,
  111. /** @deprecated ICU 2.6 Use the URES_ constant instead. */
  112. RES_INT_VECTOR=URES_INT_VECTOR,
  113. /** @deprecated ICU 2.6 Not used. */
  114. RES_RESERVED=15,
  115. /**
  116. * One more than the highest normal UResType value.
  117. * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
  118. */
  119. URES_LIMIT = 16
  120. #endif // U_HIDE_DEPRECATED_API
  121. } UResType;
  122. /*
  123. * Functions to create and destroy resource bundles.
  124. */
  125. /**
  126. * Opens a UResourceBundle, from which users can extract strings by using
  127. * their corresponding keys.
  128. * Note that the caller is responsible of calling <TT>ures_close</TT> on each successfully
  129. * opened resource bundle.
  130. * @param packageName The packageName and locale together point to an ICU udata object,
  131. * as defined by <code> udata_open( packageName, "res", locale, err) </code>
  132. * or equivalent. Typically, packageName will refer to a (.dat) file, or to
  133. * a package registered with udata_setAppData(). Using a full file or directory
  134. * pathname for packageName is deprecated. If NULL, ICU data will be used.
  135. * @param locale specifies the locale for which we want to open the resource
  136. * if NULL, the default locale will be used. If strlen(locale) == 0
  137. * root locale will be used.
  138. *
  139. * @param status fills in the outgoing error code.
  140. * The UErrorCode err parameter is used to return status information to the user. To
  141. * check whether the construction succeeded or not, you should check the value of
  142. * U_SUCCESS(err). If you wish more detailed information, you can check for
  143. * informational status results which still indicate success. U_USING_FALLBACK_WARNING
  144. * indicates that a fall back locale was used. For example, 'de_CH' was requested,
  145. * but nothing was found there, so 'de' was used. U_USING_DEFAULT_WARNING indicates that
  146. * the default locale data or root locale data was used; neither the requested locale
  147. * nor any of its fall back locales could be found. Please see the users guide for more
  148. * information on this topic.
  149. * @return a newly allocated resource bundle.
  150. * @see ures_close
  151. * @stable ICU 2.0
  152. */
  153. U_CAPI UResourceBundle* U_EXPORT2
  154. ures_open(const char* packageName,
  155. const char* locale,
  156. UErrorCode* status);
  157. /** This function does not care what kind of localeID is passed in. It simply opens a bundle with
  158. * that name. Fallback mechanism is disabled for the new bundle. If the requested bundle contains
  159. * an %%ALIAS directive, the results are undefined.
  160. * @param packageName The packageName and locale together point to an ICU udata object,
  161. * as defined by <code> udata_open( packageName, "res", locale, err) </code>
  162. * or equivalent. Typically, packageName will refer to a (.dat) file, or to
  163. * a package registered with udata_setAppData(). Using a full file or directory
  164. * pathname for packageName is deprecated. If NULL, ICU data will be used.
  165. * @param locale specifies the locale for which we want to open the resource
  166. * if NULL, the default locale will be used. If strlen(locale) == 0
  167. * root locale will be used.
  168. *
  169. * @param status fills in the outgoing error code. Either U_ZERO_ERROR or U_MISSING_RESOURCE_ERROR
  170. * @return a newly allocated resource bundle or NULL if it doesn't exist.
  171. * @see ures_close
  172. * @stable ICU 2.0
  173. */
  174. U_CAPI UResourceBundle* U_EXPORT2
  175. ures_openDirect(const char* packageName,
  176. const char* locale,
  177. UErrorCode* status);
  178. /**
  179. * Same as ures_open() but takes a const UChar *path.
  180. * This path will be converted to char * using the default converter,
  181. * then ures_open() is called.
  182. *
  183. * @param packageName The packageName and locale together point to an ICU udata object,
  184. * as defined by <code> udata_open( packageName, "res", locale, err) </code>
  185. * or equivalent. Typically, packageName will refer to a (.dat) file, or to
  186. * a package registered with udata_setAppData(). Using a full file or directory
  187. * pathname for packageName is deprecated. If NULL, ICU data will be used.
  188. * @param locale specifies the locale for which we want to open the resource
  189. * if NULL, the default locale will be used. If strlen(locale) == 0
  190. * root locale will be used.
  191. * @param status fills in the outgoing error code.
  192. * @return a newly allocated resource bundle.
  193. * @see ures_open
  194. * @stable ICU 2.0
  195. */
  196. U_CAPI UResourceBundle* U_EXPORT2
  197. ures_openU(const UChar* packageName,
  198. const char* locale,
  199. UErrorCode* status);
  200. #ifndef U_HIDE_DEPRECATED_API
  201. /**
  202. * Returns the number of strings/arrays in resource bundles.
  203. * Better to use ures_getSize, as this function will be deprecated.
  204. *
  205. *@param resourceBundle resource bundle containing the desired strings
  206. *@param resourceKey key tagging the resource
  207. *@param err fills in the outgoing error code
  208. * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
  209. * could be a non-failing error
  210. * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_FALLBACK_WARNING </TT>
  211. *@return: for <STRONG>Arrays</STRONG>: returns the number of resources in the array
  212. * <STRONG>Tables</STRONG>: returns the number of resources in the table
  213. * <STRONG>single string</STRONG>: returns 1
  214. *@see ures_getSize
  215. * @deprecated ICU 2.8 User ures_getSize instead
  216. */
  217. U_DEPRECATED int32_t U_EXPORT2
  218. ures_countArrayItems(const UResourceBundle* resourceBundle,
  219. const char* resourceKey,
  220. UErrorCode* err);
  221. #endif /* U_HIDE_DEPRECATED_API */
  222. /**
  223. * Close a resource bundle, all pointers returned from the various ures_getXXX calls
  224. * on this particular bundle should be considered invalid henceforth.
  225. *
  226. * @param resourceBundle a pointer to a resourceBundle struct. Can be NULL.
  227. * @see ures_open
  228. * @stable ICU 2.0
  229. */
  230. U_CAPI void U_EXPORT2
  231. ures_close(UResourceBundle* resourceBundle);
  232. #if U_SHOW_CPLUSPLUS_API
  233. U_NAMESPACE_BEGIN
  234. /**
  235. * \class LocalUResourceBundlePointer
  236. * "Smart pointer" class, closes a UResourceBundle via ures_close().
  237. * For most methods see the LocalPointerBase base class.
  238. *
  239. * @see LocalPointerBase
  240. * @see LocalPointer
  241. * @stable ICU 4.4
  242. */
  243. U_DEFINE_LOCAL_OPEN_POINTER(LocalUResourceBundlePointer, UResourceBundle, ures_close);
  244. U_NAMESPACE_END
  245. #endif
  246. #ifndef U_HIDE_DEPRECATED_API
  247. /**
  248. * Return the version number associated with this ResourceBundle as a string. Please
  249. * use ures_getVersion as this function is going to be deprecated.
  250. *
  251. * @param resourceBundle The resource bundle for which the version is checked.
  252. * @return A version number string as specified in the resource bundle or its parent.
  253. * The caller does not own this string.
  254. * @see ures_getVersion
  255. * @deprecated ICU 2.8 Use ures_getVersion instead.
  256. */
  257. U_DEPRECATED const char* U_EXPORT2
  258. ures_getVersionNumber(const UResourceBundle* resourceBundle);
  259. #endif /* U_HIDE_DEPRECATED_API */
  260. /**
  261. * Return the version number associated with this ResourceBundle as an
  262. * UVersionInfo array.
  263. *
  264. * @param resB The resource bundle for which the version is checked.
  265. * @param versionInfo A UVersionInfo array that is filled with the version number
  266. * as specified in the resource bundle or its parent.
  267. * @stable ICU 2.0
  268. */
  269. U_CAPI void U_EXPORT2
  270. ures_getVersion(const UResourceBundle* resB,
  271. UVersionInfo versionInfo);
  272. #ifndef U_HIDE_DEPRECATED_API
  273. /**
  274. * Return the name of the Locale associated with this ResourceBundle. This API allows
  275. * you to query for the real locale of the resource. For example, if you requested
  276. * "en_US_CALIFORNIA" and only "en_US" bundle exists, "en_US" will be returned.
  277. * For subresources, the locale where this resource comes from will be returned.
  278. * If fallback has occurred, getLocale will reflect this.
  279. *
  280. * @param resourceBundle resource bundle in question
  281. * @param status just for catching illegal arguments
  282. * @return A Locale name
  283. * @deprecated ICU 2.8 Use ures_getLocaleByType instead.
  284. */
  285. U_DEPRECATED const char* U_EXPORT2
  286. ures_getLocale(const UResourceBundle* resourceBundle,
  287. UErrorCode* status);
  288. #endif /* U_HIDE_DEPRECATED_API */
  289. /**
  290. * Return the name of the Locale associated with this ResourceBundle.
  291. * You can choose between requested, valid and real locale.
  292. *
  293. * @param resourceBundle resource bundle in question
  294. * @param type You can choose between requested, valid and actual
  295. * locale. For description see the definition of
  296. * ULocDataLocaleType in uloc.h
  297. * @param status just for catching illegal arguments
  298. * @return A Locale name
  299. * @stable ICU 2.8
  300. */
  301. U_CAPI const char* U_EXPORT2
  302. ures_getLocaleByType(const UResourceBundle* resourceBundle,
  303. ULocDataLocaleType type,
  304. UErrorCode* status);
  305. #ifndef U_HIDE_INTERNAL_API
  306. /**
  307. * Same as ures_open() but uses the fill-in parameter instead of allocating a new bundle.
  308. *
  309. * TODO need to revisit usefulness of this function
  310. * and usage model for fillIn parameters without knowing sizeof(UResourceBundle)
  311. * @param r The existing UResourceBundle to fill in. If NULL then status will be
  312. * set to U_ILLEGAL_ARGUMENT_ERROR.
  313. * @param packageName The packageName and locale together point to an ICU udata object,
  314. * as defined by <code> udata_open( packageName, "res", locale, err) </code>
  315. * or equivalent. Typically, packageName will refer to a (.dat) file, or to
  316. * a package registered with udata_setAppData(). Using a full file or directory
  317. * pathname for packageName is deprecated. If NULL, ICU data will be used.
  318. * @param localeID specifies the locale for which we want to open the resource
  319. * @param status The error code.
  320. * @internal
  321. */
  322. U_CAPI void U_EXPORT2
  323. ures_openFillIn(UResourceBundle *r,
  324. const char* packageName,
  325. const char* localeID,
  326. UErrorCode* status);
  327. #endif /* U_HIDE_INTERNAL_API */
  328. /**
  329. * Returns a string from a string resource type
  330. *
  331. * @param resourceBundle a string resource
  332. * @param len fills in the length of resulting string
  333. * @param status fills in the outgoing error code
  334. * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
  335. * Always check the value of status. Don't count on returning NULL.
  336. * could be a non-failing error
  337. * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
  338. * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file.
  339. * @see ures_getBinary
  340. * @see ures_getIntVector
  341. * @see ures_getInt
  342. * @see ures_getUInt
  343. * @stable ICU 2.0
  344. */
  345. U_CAPI const UChar* U_EXPORT2
  346. ures_getString(const UResourceBundle* resourceBundle,
  347. int32_t* len,
  348. UErrorCode* status);
  349. /**
  350. * Returns a UTF-8 string from a string resource.
  351. * The UTF-8 string may be returnable directly as a pointer, or
  352. * it may need to be copied, or transformed from UTF-16 using u_strToUTF8()
  353. * or equivalent.
  354. *
  355. * If forceCopy==true, then the string is always written to the dest buffer
  356. * and dest is returned.
  357. *
  358. * If forceCopy==false, then the string is returned as a pointer if possible,
  359. * without needing a dest buffer (it can be NULL). If the string needs to be
  360. * copied or transformed, then it may be placed into dest at an arbitrary offset.
  361. *
  362. * If the string is to be written to dest, then U_BUFFER_OVERFLOW_ERROR and
  363. * U_STRING_NOT_TERMINATED_WARNING are set if appropriate, as usual.
  364. *
  365. * If the string is transformed from UTF-16, then a conversion error may occur
  366. * if an unpaired surrogate is encountered. If the function is successful, then
  367. * the output UTF-8 string is always well-formed.
  368. *
  369. * @param resB Resource bundle.
  370. * @param dest Destination buffer. Can be NULL only if capacity=*length==0.
  371. * @param length Input: Capacity of destination buffer.
  372. * Output: Actual length of the UTF-8 string, not counting the
  373. * terminating NUL, even in case of U_BUFFER_OVERFLOW_ERROR.
  374. * Can be NULL, meaning capacity=0 and the string length is not
  375. * returned to the caller.
  376. * @param forceCopy If true, then the output string will always be written to
  377. * dest, with U_BUFFER_OVERFLOW_ERROR and
  378. * U_STRING_NOT_TERMINATED_WARNING set if appropriate.
  379. * If false, then the dest buffer may or may not contain a
  380. * copy of the string. dest may or may not be modified.
  381. * If a copy needs to be written, then the UErrorCode parameter
  382. * indicates overflow etc. as usual.
  383. * @param status Pointer to a standard ICU error code. Its input value must
  384. * pass the U_SUCCESS() test, or else the function returns
  385. * immediately. Check for U_FAILURE() on output or use with
  386. * function chaining. (See User Guide for details.)
  387. * @return The pointer to the UTF-8 string. It may be dest, or at some offset
  388. * from dest (only if !forceCopy), or in unrelated memory.
  389. * Always NUL-terminated unless the string was written to dest and
  390. * length==capacity (in which case U_STRING_NOT_TERMINATED_WARNING is set).
  391. *
  392. * @see ures_getString
  393. * @see u_strToUTF8
  394. * @stable ICU 3.6
  395. */
  396. U_CAPI const char * U_EXPORT2
  397. ures_getUTF8String(const UResourceBundle *resB,
  398. char *dest, int32_t *length,
  399. UBool forceCopy,
  400. UErrorCode *status);
  401. /**
  402. * Returns a binary data from a binary resource.
  403. *
  404. * @param resourceBundle a string resource
  405. * @param len fills in the length of resulting byte chunk
  406. * @param status fills in the outgoing error code
  407. * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
  408. * Always check the value of status. Don't count on returning NULL.
  409. * could be a non-failing error
  410. * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
  411. * @return a pointer to a chunk of unsigned bytes which live in a memory mapped/DLL file.
  412. * @see ures_getString
  413. * @see ures_getIntVector
  414. * @see ures_getInt
  415. * @see ures_getUInt
  416. * @stable ICU 2.0
  417. */
  418. U_CAPI const uint8_t* U_EXPORT2
  419. ures_getBinary(const UResourceBundle* resourceBundle,
  420. int32_t* len,
  421. UErrorCode* status);
  422. /**
  423. * Returns a 32 bit integer array from a resource.
  424. *
  425. * @param resourceBundle an int vector resource
  426. * @param len fills in the length of resulting byte chunk
  427. * @param status fills in the outgoing error code
  428. * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
  429. * Always check the value of status. Don't count on returning NULL.
  430. * could be a non-failing error
  431. * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
  432. * @return a pointer to a chunk of integers which live in a memory mapped/DLL file.
  433. * @see ures_getBinary
  434. * @see ures_getString
  435. * @see ures_getInt
  436. * @see ures_getUInt
  437. * @stable ICU 2.0
  438. */
  439. U_CAPI const int32_t* U_EXPORT2
  440. ures_getIntVector(const UResourceBundle* resourceBundle,
  441. int32_t* len,
  442. UErrorCode* status);
  443. /**
  444. * Returns an unsigned integer from a resource.
  445. * This integer is originally 28 bits.
  446. *
  447. * @param resourceBundle a string resource
  448. * @param status fills in the outgoing error code
  449. * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
  450. * could be a non-failing error
  451. * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
  452. * @return an integer value
  453. * @see ures_getInt
  454. * @see ures_getIntVector
  455. * @see ures_getBinary
  456. * @see ures_getString
  457. * @stable ICU 2.0
  458. */
  459. U_CAPI uint32_t U_EXPORT2
  460. ures_getUInt(const UResourceBundle* resourceBundle,
  461. UErrorCode *status);
  462. /**
  463. * Returns a signed integer from a resource.
  464. * This integer is originally 28 bit and the sign gets propagated.
  465. *
  466. * @param resourceBundle a string resource
  467. * @param status fills in the outgoing error code
  468. * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
  469. * could be a non-failing error
  470. * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
  471. * @return an integer value
  472. * @see ures_getUInt
  473. * @see ures_getIntVector
  474. * @see ures_getBinary
  475. * @see ures_getString
  476. * @stable ICU 2.0
  477. */
  478. U_CAPI int32_t U_EXPORT2
  479. ures_getInt(const UResourceBundle* resourceBundle,
  480. UErrorCode *status);
  481. /**
  482. * Returns the size of a resource. Size for scalar types is always 1,
  483. * and for vector/table types is the number of child resources.
  484. * @warning Integer array is treated as a scalar type. There are no
  485. * APIs to access individual members of an integer array. It
  486. * is always returned as a whole.
  487. * @param resourceBundle a resource
  488. * @return number of resources in a given resource.
  489. * @stable ICU 2.0
  490. */
  491. U_CAPI int32_t U_EXPORT2
  492. ures_getSize(const UResourceBundle *resourceBundle);
  493. /**
  494. * Returns the type of a resource. Available types are defined in enum UResType
  495. *
  496. * @param resourceBundle a resource
  497. * @return type of the given resource.
  498. * @see UResType
  499. * @stable ICU 2.0
  500. */
  501. U_CAPI UResType U_EXPORT2
  502. ures_getType(const UResourceBundle *resourceBundle);
  503. /**
  504. * Returns the key associated with a given resource. Not all the resources have a key - only
  505. * those that are members of a table.
  506. *
  507. * @param resourceBundle a resource
  508. * @return a key associated to this resource, or NULL if it doesn't have a key
  509. * @stable ICU 2.0
  510. */
  511. U_CAPI const char * U_EXPORT2
  512. ures_getKey(const UResourceBundle *resourceBundle);
  513. /* ITERATION API
  514. This API provides means for iterating through a resource
  515. */
  516. /**
  517. * Resets the internal context of a resource so that iteration starts from the first element.
  518. *
  519. * @param resourceBundle a resource
  520. * @stable ICU 2.0
  521. */
  522. U_CAPI void U_EXPORT2
  523. ures_resetIterator(UResourceBundle *resourceBundle);
  524. /**
  525. * Checks whether the given resource has another element to iterate over.
  526. *
  527. * @param resourceBundle a resource
  528. * @return true if there are more elements, false if there is no more elements
  529. * @stable ICU 2.0
  530. */
  531. U_CAPI UBool U_EXPORT2
  532. ures_hasNext(const UResourceBundle *resourceBundle);
  533. /**
  534. * Returns the next resource in a given resource or NULL if there are no more resources
  535. * to iterate over. Features a fill-in parameter.
  536. *
  537. * @param resourceBundle a resource
  538. * @param fillIn if NULL a new UResourceBundle struct is allocated and must be closed by the caller.
  539. * Alternatively, you can supply a struct to be filled by this function.
  540. * @param status fills in the outgoing error code. You may still get a non NULL result even if an
  541. * error occurred. Check status instead.
  542. * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must close it
  543. * @stable ICU 2.0
  544. */
  545. U_CAPI UResourceBundle* U_EXPORT2
  546. ures_getNextResource(UResourceBundle *resourceBundle,
  547. UResourceBundle *fillIn,
  548. UErrorCode *status);
  549. /**
  550. * Returns the next string in a given resource or NULL if there are no more resources
  551. * to iterate over.
  552. *
  553. * @param resourceBundle a resource
  554. * @param len fill in length of the string
  555. * @param key fill in for key associated with this string. NULL if no key
  556. * @param status fills in the outgoing error code. If an error occurred, we may return NULL, but don't
  557. * count on it. Check status instead!
  558. * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file.
  559. * @stable ICU 2.0
  560. */
  561. U_CAPI const UChar* U_EXPORT2
  562. ures_getNextString(UResourceBundle *resourceBundle,
  563. int32_t* len,
  564. const char ** key,
  565. UErrorCode *status);
  566. /**
  567. * Returns the resource in a given resource at the specified index. Features a fill-in parameter.
  568. *
  569. * @param resourceBundle the resource bundle from which to get a sub-resource
  570. * @param indexR an index to the wanted resource.
  571. * @param fillIn if NULL a new UResourceBundle struct is allocated and must be closed by the caller.
  572. * Alternatively, you can supply a struct to be filled by this function.
  573. * @param status fills in the outgoing error code. Don't count on NULL being returned if an error has
  574. * occurred. Check status instead.
  575. * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must close it
  576. * @stable ICU 2.0
  577. */
  578. U_CAPI UResourceBundle* U_EXPORT2
  579. ures_getByIndex(const UResourceBundle *resourceBundle,
  580. int32_t indexR,
  581. UResourceBundle *fillIn,
  582. UErrorCode *status);
  583. /**
  584. * Returns the string in a given resource at the specified index.
  585. *
  586. * @param resourceBundle a resource
  587. * @param indexS an index to the wanted string.
  588. * @param len fill in length of the string
  589. * @param status fills in the outgoing error code. If an error occurred, we may return NULL, but don't
  590. * count on it. Check status instead!
  591. * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file.
  592. * @stable ICU 2.0
  593. */
  594. U_CAPI const UChar* U_EXPORT2
  595. ures_getStringByIndex(const UResourceBundle *resourceBundle,
  596. int32_t indexS,
  597. int32_t* len,
  598. UErrorCode *status);
  599. /**
  600. * Returns a UTF-8 string from a resource at the specified index.
  601. * The UTF-8 string may be returnable directly as a pointer, or
  602. * it may need to be copied, or transformed from UTF-16 using u_strToUTF8()
  603. * or equivalent.
  604. *
  605. * If forceCopy==true, then the string is always written to the dest buffer
  606. * and dest is returned.
  607. *
  608. * If forceCopy==false, then the string is returned as a pointer if possible,
  609. * without needing a dest buffer (it can be NULL). If the string needs to be
  610. * copied or transformed, then it may be placed into dest at an arbitrary offset.
  611. *
  612. * If the string is to be written to dest, then U_BUFFER_OVERFLOW_ERROR and
  613. * U_STRING_NOT_TERMINATED_WARNING are set if appropriate, as usual.
  614. *
  615. * If the string is transformed from UTF-16, then a conversion error may occur
  616. * if an unpaired surrogate is encountered. If the function is successful, then
  617. * the output UTF-8 string is always well-formed.
  618. *
  619. * @param resB Resource bundle.
  620. * @param stringIndex An index to the wanted string.
  621. * @param dest Destination buffer. Can be NULL only if capacity=*length==0.
  622. * @param pLength Input: Capacity of destination buffer.
  623. * Output: Actual length of the UTF-8 string, not counting the
  624. * terminating NUL, even in case of U_BUFFER_OVERFLOW_ERROR.
  625. * Can be NULL, meaning capacity=0 and the string length is not
  626. * returned to the caller.
  627. * @param forceCopy If true, then the output string will always be written to
  628. * dest, with U_BUFFER_OVERFLOW_ERROR and
  629. * U_STRING_NOT_TERMINATED_WARNING set if appropriate.
  630. * If false, then the dest buffer may or may not contain a
  631. * copy of the string. dest may or may not be modified.
  632. * If a copy needs to be written, then the UErrorCode parameter
  633. * indicates overflow etc. as usual.
  634. * @param status Pointer to a standard ICU error code. Its input value must
  635. * pass the U_SUCCESS() test, or else the function returns
  636. * immediately. Check for U_FAILURE() on output or use with
  637. * function chaining. (See User Guide for details.)
  638. * @return The pointer to the UTF-8 string. It may be dest, or at some offset
  639. * from dest (only if !forceCopy), or in unrelated memory.
  640. * Always NUL-terminated unless the string was written to dest and
  641. * length==capacity (in which case U_STRING_NOT_TERMINATED_WARNING is set).
  642. *
  643. * @see ures_getStringByIndex
  644. * @see u_strToUTF8
  645. * @stable ICU 3.6
  646. */
  647. U_CAPI const char * U_EXPORT2
  648. ures_getUTF8StringByIndex(const UResourceBundle *resB,
  649. int32_t stringIndex,
  650. char *dest, int32_t *pLength,
  651. UBool forceCopy,
  652. UErrorCode *status);
  653. /**
  654. * Returns a resource in a given resource that has a given key. This procedure works only with table
  655. * resources. Features a fill-in parameter.
  656. *
  657. * @param resourceBundle a resource
  658. * @param key a key associated with the wanted resource
  659. * @param fillIn if NULL a new UResourceBundle struct is allocated and must be closed by the caller.
  660. * Alternatively, you can supply a struct to be filled by this function.
  661. * @param status fills in the outgoing error code.
  662. * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must close it
  663. * @stable ICU 2.0
  664. */
  665. U_CAPI UResourceBundle* U_EXPORT2
  666. ures_getByKey(const UResourceBundle *resourceBundle,
  667. const char* key,
  668. UResourceBundle *fillIn,
  669. UErrorCode *status);
  670. /**
  671. * Returns a string in a given resource that has a given key. This procedure works only with table
  672. * resources.
  673. *
  674. * @param resB a resource
  675. * @param key a key associated with the wanted string
  676. * @param len fill in length of the string
  677. * @param status fills in the outgoing error code. If an error occurred, we may return NULL, but don't
  678. * count on it. Check status instead!
  679. * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file.
  680. * @stable ICU 2.0
  681. */
  682. U_CAPI const UChar* U_EXPORT2
  683. ures_getStringByKey(const UResourceBundle *resB,
  684. const char* key,
  685. int32_t* len,
  686. UErrorCode *status);
  687. /**
  688. * Returns a UTF-8 string from a resource and a key.
  689. * This function works only with table resources.
  690. *
  691. * The UTF-8 string may be returnable directly as a pointer, or
  692. * it may need to be copied, or transformed from UTF-16 using u_strToUTF8()
  693. * or equivalent.
  694. *
  695. * If forceCopy==true, then the string is always written to the dest buffer
  696. * and dest is returned.
  697. *
  698. * If forceCopy==false, then the string is returned as a pointer if possible,
  699. * without needing a dest buffer (it can be NULL). If the string needs to be
  700. * copied or transformed, then it may be placed into dest at an arbitrary offset.
  701. *
  702. * If the string is to be written to dest, then U_BUFFER_OVERFLOW_ERROR and
  703. * U_STRING_NOT_TERMINATED_WARNING are set if appropriate, as usual.
  704. *
  705. * If the string is transformed from UTF-16, then a conversion error may occur
  706. * if an unpaired surrogate is encountered. If the function is successful, then
  707. * the output UTF-8 string is always well-formed.
  708. *
  709. * @param resB Resource bundle.
  710. * @param key A key associated with the wanted resource
  711. * @param dest Destination buffer. Can be NULL only if capacity=*length==0.
  712. * @param pLength Input: Capacity of destination buffer.
  713. * Output: Actual length of the UTF-8 string, not counting the
  714. * terminating NUL, even in case of U_BUFFER_OVERFLOW_ERROR.
  715. * Can be NULL, meaning capacity=0 and the string length is not
  716. * returned to the caller.
  717. * @param forceCopy If true, then the output string will always be written to
  718. * dest, with U_BUFFER_OVERFLOW_ERROR and
  719. * U_STRING_NOT_TERMINATED_WARNING set if appropriate.
  720. * If false, then the dest buffer may or may not contain a
  721. * copy of the string. dest may or may not be modified.
  722. * If a copy needs to be written, then the UErrorCode parameter
  723. * indicates overflow etc. as usual.
  724. * @param status Pointer to a standard ICU error code. Its input value must
  725. * pass the U_SUCCESS() test, or else the function returns
  726. * immediately. Check for U_FAILURE() on output or use with
  727. * function chaining. (See User Guide for details.)
  728. * @return The pointer to the UTF-8 string. It may be dest, or at some offset
  729. * from dest (only if !forceCopy), or in unrelated memory.
  730. * Always NUL-terminated unless the string was written to dest and
  731. * length==capacity (in which case U_STRING_NOT_TERMINATED_WARNING is set).
  732. *
  733. * @see ures_getStringByKey
  734. * @see u_strToUTF8
  735. * @stable ICU 3.6
  736. */
  737. U_CAPI const char * U_EXPORT2
  738. ures_getUTF8StringByKey(const UResourceBundle *resB,
  739. const char *key,
  740. char *dest, int32_t *pLength,
  741. UBool forceCopy,
  742. UErrorCode *status);
  743. #if U_SHOW_CPLUSPLUS_API
  744. #include "unicode/unistr.h"
  745. U_NAMESPACE_BEGIN
  746. /**
  747. * Returns the string value from a string resource bundle.
  748. *
  749. * @param resB a resource, should have type URES_STRING
  750. * @param status: fills in the outgoing error code
  751. * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found
  752. * could be a non-failing error
  753. * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
  754. * @return The string value, or a bogus string if there is a failure UErrorCode.
  755. * @stable ICU 2.0
  756. */
  757. inline UnicodeString
  758. ures_getUnicodeString(const UResourceBundle *resB, UErrorCode* status) {
  759. UnicodeString result;
  760. int32_t len = 0;
  761. const char16_t *r = ConstChar16Ptr(ures_getString(resB, &len, status));
  762. if(U_SUCCESS(*status)) {
  763. result.setTo(true, r, len);
  764. } else {
  765. result.setToBogus();
  766. }
  767. return result;
  768. }
  769. /**
  770. * Returns the next string in a resource, or an empty string if there are no more resources
  771. * to iterate over.
  772. * Use ures_getNextString() instead to distinguish between
  773. * the end of the iteration and a real empty string value.
  774. *
  775. * @param resB a resource
  776. * @param key fill in for key associated with this string
  777. * @param status fills in the outgoing error code
  778. * @return The string value, or a bogus string if there is a failure UErrorCode.
  779. * @stable ICU 2.0
  780. */
  781. inline UnicodeString
  782. ures_getNextUnicodeString(UResourceBundle *resB, const char ** key, UErrorCode* status) {
  783. UnicodeString result;
  784. int32_t len = 0;
  785. const char16_t* r = ConstChar16Ptr(ures_getNextString(resB, &len, key, status));
  786. if(U_SUCCESS(*status)) {
  787. result.setTo(true, r, len);
  788. } else {
  789. result.setToBogus();
  790. }
  791. return result;
  792. }
  793. /**
  794. * Returns the string in a given resource array or table at the specified index.
  795. *
  796. * @param resB a resource
  797. * @param indexS an index to the wanted string.
  798. * @param status fills in the outgoing error code
  799. * @return The string value, or a bogus string if there is a failure UErrorCode.
  800. * @stable ICU 2.0
  801. */
  802. inline UnicodeString
  803. ures_getUnicodeStringByIndex(const UResourceBundle *resB, int32_t indexS, UErrorCode* status) {
  804. UnicodeString result;
  805. int32_t len = 0;
  806. const char16_t* r = ConstChar16Ptr(ures_getStringByIndex(resB, indexS, &len, status));
  807. if(U_SUCCESS(*status)) {
  808. result.setTo(true, r, len);
  809. } else {
  810. result.setToBogus();
  811. }
  812. return result;
  813. }
  814. /**
  815. * Returns a string in a resource that has a given key.
  816. * This procedure works only with table resources.
  817. *
  818. * @param resB a resource
  819. * @param key a key associated with the wanted string
  820. * @param status fills in the outgoing error code
  821. * @return The string value, or a bogus string if there is a failure UErrorCode.
  822. * @stable ICU 2.0
  823. */
  824. inline UnicodeString
  825. ures_getUnicodeStringByKey(const UResourceBundle *resB, const char* key, UErrorCode* status) {
  826. UnicodeString result;
  827. int32_t len = 0;
  828. const char16_t* r = ConstChar16Ptr(ures_getStringByKey(resB, key, &len, status));
  829. if(U_SUCCESS(*status)) {
  830. result.setTo(true, r, len);
  831. } else {
  832. result.setToBogus();
  833. }
  834. return result;
  835. }
  836. U_NAMESPACE_END
  837. #endif
  838. /**
  839. * Create a string enumerator, owned by the caller, of all locales located within
  840. * the specified resource tree.
  841. * @param packageName name of the tree, such as (NULL) or U_ICUDATA_ALIAS or or "ICUDATA-coll"
  842. * This call is similar to uloc_getAvailable().
  843. * @param status error code
  844. * @stable ICU 3.2
  845. */
  846. U_CAPI UEnumeration* U_EXPORT2
  847. ures_openAvailableLocales(const char *packageName, UErrorCode *status);
  848. #endif /*_URES*/
  849. /*eof*/