ures.h 36 KB

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