home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / common / ures.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  6.1 KB  |  183 lines

  1. /*
  2. *******************************************************************************
  3. *                                                                             *
  4. * COPYRIGHT:                                                                  *
  5. *   (C) Copyright Taligent, Inc.,  1997                                       *
  6. *   (C) Copyright International Business Machines Corporation,  1997-1998     *
  7. *   Licensed Material - Program-Property of IBM - All Rights Reserved.        *
  8. *   US Government Users Restricted Rights - Use, duplication, or disclosure   *
  9. *   restricted by GSA ADP Schedule Contract with IBM Corp.                    *
  10. *                                                                             *
  11. *******************************************************************************
  12. *
  13. * File CRESBUND.CPP
  14. *
  15. * Modification History:
  16. *
  17. *   Date        Name        Description
  18. *   04/01/97    aliu        Creation.
  19. *   06/14/99    stephen     Removed functions taking a filename suffix.
  20. *   07/20/99    stephen     Changed for UResourceBundle typedef'd to void*
  21. *******************************************************************************
  22. */
  23.  
  24. #include "resbund.h"
  25. #include "ures.h"
  26. #include "locid.h"
  27. #include "uloc.h"
  28.  
  29. /**
  30.  * Functions to create and destroy resource bundles.
  31.  */
  32.  
  33. U_CAPI UResourceBundle* ures_open(    const char* myPath,
  34.                     const char* localeID,
  35.                     UErrorCode* status)
  36. {
  37.   UnicodeString uPath;
  38.   Locale myLocale;
  39.  
  40.  
  41.   if (myPath != 0) uPath = myPath;
  42.   else uPath = uloc_getDataDirectory();
  43.  
  44.   if (localeID == 0) localeID = uloc_getDefault();
  45.  
  46.  
  47.   return (UResourceBundle*) new ResourceBundle(uPath, myLocale.init(localeID), *status);
  48. }
  49.  
  50. U_CAPI UResourceBundle* ures_openW(    const wchar_t* myPath,
  51.                     const char* localeID,
  52.                     UErrorCode* status)
  53. {
  54.   Locale myLocale;
  55.   if (localeID == 0) localeID = uloc_getDefault();
  56.  
  57.   return (UResourceBundle*) new ResourceBundle(myPath, myLocale.init(localeID), *status);
  58. }
  59.  
  60.  
  61. /**
  62.  * Functions to retrieve data from resource bundles.
  63.  */
  64.  
  65. U_CAPI const UChar* ures_get(    const UResourceBundle*    resourceBundle,
  66.                 const char*              resourceTag,
  67.                 UErrorCode*               status)
  68. {
  69.   if (U_FAILURE(*status)) return NULL;
  70.   if (!resourceBundle || !resourceTag)
  71.     {
  72.       *status = U_ILLEGAL_ARGUMENT_ERROR;
  73.       return NULL;
  74.     }
  75.  
  76.   const UnicodeString* tmp =  ((ResourceBundle*)resourceBundle)->getString(resourceTag, *status);
  77.  
  78.   if (U_SUCCESS(*status)) return tmp->getUChars();
  79.   else return NULL;
  80. }
  81.  
  82. U_CAPI const UChar* ures_getArrayItem(const UResourceBundle*     resourceBundle,
  83.                     const char*               resourceTag,
  84.                     int32_t                   resourceIndex,
  85.                     UErrorCode*                status)
  86. {
  87.   if (U_FAILURE(*status)) return NULL;
  88.   if (!resourceBundle || !resourceTag || (resourceIndex < 0))
  89.     {
  90.       *status = U_ILLEGAL_ARGUMENT_ERROR;
  91.       return NULL;
  92.     }
  93.  
  94.   const UnicodeString* tmp =  ((ResourceBundle*)resourceBundle)->getArrayItem(resourceTag, resourceIndex, *status);
  95.  
  96.   if (U_SUCCESS(*status)) return tmp->getUChars();
  97.   else return NULL;
  98. }
  99.  
  100.  
  101.  
  102. U_CAPI const UChar* ures_get2dArrayItem(const UResourceBundle*   resourceBundle,
  103.                       const char*             resourceTag,
  104.                       int32_t                 rowIndex,
  105.                       int32_t                 columnIndex,
  106.                       UErrorCode*              status)
  107. {
  108.   if (U_FAILURE(*status)) return NULL;
  109.   if (!resourceBundle || !resourceTag || (rowIndex < 0) || (columnIndex < 0))
  110.     {
  111.       *status = U_ILLEGAL_ARGUMENT_ERROR;
  112.       return NULL;
  113.     }
  114.  
  115.   const UnicodeString* tmp = ((ResourceBundle*)resourceBundle)->get2dArrayItem(resourceTag,
  116.                                 rowIndex,
  117.                                 columnIndex,
  118.                                 *status);
  119.   if (U_SUCCESS(*status)) return tmp->getUChars();
  120.   else return NULL;
  121. }
  122.  
  123. U_CAPI const UChar* ures_getTaggedArrayItem(const UResourceBundle*   resourceBundle,
  124.                       const char*             resourceTag,
  125.                       const char*             itemTag,
  126.                       UErrorCode*              status)
  127. {
  128.   if (U_FAILURE(*status)) return NULL;
  129.   if (!resourceBundle || !resourceTag || !itemTag)
  130.     {
  131.       *status = U_ILLEGAL_ARGUMENT_ERROR;
  132.       return NULL;
  133.     }
  134.  
  135.   const UnicodeString* tmp =  ((ResourceBundle*)resourceBundle)->getTaggedArrayItem(resourceTag,
  136.                                itemTag,
  137.                                *status);
  138.   if (U_SUCCESS(*status)) return tmp->getUChars();
  139.   else return NULL;
  140. }
  141.  
  142.  
  143. U_CAPI const char* ures_getVersionNumber(const UResourceBundle*   resourceBundle)
  144. {
  145.   if (!resourceBundle) return NULL;
  146.   return ((ResourceBundle*)resourceBundle)->getVersionNumber();
  147. }
  148.  
  149. extern "C" int32_t T_ResourceBundle_countArrayItems(const ResourceBundle* rb,
  150.                              const char* resourceKey,
  151.                              UErrorCode* err);
  152.  
  153. U_CAPI int32_t ures_countArrayItems(const UResourceBundle* resourceBundle,
  154.                   const char* resourceKey,
  155.                   UErrorCode* err)
  156. {
  157.   return T_ResourceBundle_countArrayItems((ResourceBundle*)resourceBundle,
  158.                       resourceKey,
  159.                       err);
  160. }
  161.  
  162. U_CAPI void ures_close(    UResourceBundle*    resourceBundle)
  163. {
  164.     delete resourceBundle;
  165.     return;
  166. }
  167.  
  168. /**
  169.  * Returns a list of all available ULocales.  The return value is a pointer to
  170.  * an array of pointers to ULocale objects.  Both this array and the pointers
  171.  * it contains are owned by ICU and should not be deleted or written through
  172.  * by the caller.  The array is terminated by a null pointer.
  173.  */
  174. extern "C" void T_ResourceBundle_getTaggedArrayUChars(const ResourceBundle*   UResourceBundle,
  175.                             const UnicodeString&    resourceTag,
  176.                             UChar const**         itemTags,
  177.                             UChar const**         items,
  178.                             int32_t                    maxItems,
  179.                             int32_t*                numItems,
  180.                             UErrorCode*              err);
  181.  
  182. //eof
  183.