home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icuapps / locexp / util / ures_additions.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-22  |  2.1 KB  |  88 lines

  1. #include "ures_additions.h"
  2. #include "resbund.h"
  3. #include "ustring.h"
  4. #include "decimfmt.h"
  5.  
  6. U_CAPI void ures_count2dArrayItems(const UResourceBundle *resourceBundle,
  7.                  const char * resourceTag,
  8.                  int32_t *rowCount,
  9.                  int32_t *columnCount,
  10.                  UErrorCode* status)
  11.  
  12. {
  13.   if ( U_FAILURE(*status)) return;
  14.   if (!resourceBundle || !resourceTag || (rowCount == 0) || (columnCount == 0) )
  15.     {
  16.       *status = U_ILLEGAL_ARGUMENT_ERROR;
  17.       return;
  18.     }
  19.   
  20.   /* ignore result */
  21.   ((ResourceBundle*)resourceBundle)-> get2dArray(resourceTag,
  22.                   *rowCount,
  23.                   *columnCount,
  24.                   *status);
  25. }
  26.  
  27. U_CAPI const char* ures_getTaggedArrayTag(const UResourceBundle *resourceBundle,
  28.                                const char *resourceTag, 
  29.                                int32_t index,
  30.                                UErrorCode* status)
  31. {
  32.   UnicodeString *itemTags;
  33.   UnicodeString *items;
  34.   int32_t numItems;
  35.  
  36.   if (U_FAILURE(*status)) return NULL;
  37.   if (!resourceBundle || !resourceTag || (index < 0) )
  38.     {
  39.       *status = U_ILLEGAL_ARGUMENT_ERROR;
  40.       return NULL;
  41.     }
  42.  
  43.    ((ResourceBundle*)resourceBundle)
  44.     ->getTaggedArray(resourceTag,
  45.              itemTags,
  46.              items,
  47.              numItems,
  48.              *status);
  49.   if (U_SUCCESS(*status))
  50.     {
  51.       delete [] items; 
  52.  
  53.       if(index >= numItems)
  54.     {
  55.       *status = U_INDEX_OUTOFBOUNDS_ERROR;
  56.       delete [] itemTags;
  57.       return NULL;
  58.     }
  59.       else
  60.     {
  61.       char *str = (char*)malloc(itemTags[index].size() + 3);
  62.       u_austrcpy(str,itemTags[index].getUChars()); /* should be extract? */
  63.       delete [] itemTags;
  64.       return str; /* LEAK */
  65.     }
  66.     }
  67.   else return NULL;
  68.   
  69. }
  70.  
  71.  
  72. /* ripped off from udat_applyPattern */
  73. U_CAPI void
  74. unum_applyPattern(            UNumberFormat     *format,
  75.                   bool_t          localized,
  76.                   const   UChar           *pattern,
  77.                   int32_t         patternLength)
  78. {
  79.   int32_t len = (patternLength == -1 ? u_strlen(pattern) : patternLength);
  80.   const UnicodeString pat((UChar*)pattern, len, len);
  81.   UErrorCode status = U_ZERO_ERROR;
  82.   
  83.   if(localized)
  84.     ((DecimalFormat*)format)->applyLocalizedPattern(pat, status);
  85.   else
  86.     ((DecimalFormat*)format)->applyPattern(pat, status);
  87. }
  88.