ures.h 37 KB

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