ICU-80 ResourceBundle keys (tags) are now const char*

X-SVN-Rev: 271
This commit is contained in:
Markus Scherer 1999-12-01 21:27:44 +00:00
parent 396d65de3a
commit ec97389ca8
12 changed files with 97 additions and 94 deletions

View file

@ -355,15 +355,14 @@ UnicodeConverterCPP::getDisplayName(const Locale& displayLocale,
{
UErrorCode err = U_ZERO_ERROR;
ResourceBundle rb("", displayLocale, err);
char tablename[UCNV_MAX_CONVERTER_NAME_LENGTH];
UChar name[UCNV_MAX_CONVERTER_NAME_LENGTH];
int32_t length = ucnv_getDisplayName(myUnicodeConverter, displayLocale.getName(), name, sizeof(name), &err);
if (U_SUCCESS(err))
{
rb.getString(UnicodeString(tablename), displayName, err);
displayName.replace(0, 0x7fffffff, name, length);
}
if (U_FAILURE(err))
else
{
/*Error While creating the resource bundle use the internal name instead*/
displayName.remove();

View file

@ -194,7 +194,7 @@ const char* ResourceBundle::kIndexTag = "InstalledLocales";
// character long.
const char* ResourceBundle::kDefaultMinorVersion = "0";
const char* ResourceBundle::kVersionSeparator = ".";
const UnicodeString ResourceBundle::kVersionTag("Version");
const char* ResourceBundle::kVersionTag = "Version";
ResourceBundleCache* ResourceBundle::fgUserCache = new ResourceBundleCache();
VisitedFileCache* ResourceBundle::fgUserVisitedFiles = new VisitedFileCache();
@ -581,7 +581,7 @@ ResourceBundle::parseIfUnparsed(const PathInfo& path,
* locales.
*/
const ResourceBundleData*
ResourceBundle::getDataForTag(const UnicodeString& tag,
ResourceBundle::getDataForTag(const char *tag,
UErrorCode& err) const
{
err = U_ZERO_ERROR; /* just to make sure there's no fallback/etc left over */
@ -606,7 +606,7 @@ ResourceBundle::getDataForTag(const UnicodeString& tag,
if(fData[i] != 0) {
const ResourceBundleData* s =
(const ResourceBundleData*)uhash_get(fData[i],
tag.hashCode() & 0x7FFFFFFF);
UnicodeString(tag, "").hashCode() & 0x7FFFFFFF);
if(s != 0) {
err = fDataStatus[i]; /* restore the error from the original lookup. */
return s;
@ -623,7 +623,7 @@ ResourceBundle::getDataForTag(const UnicodeString& tag,
}
void
ResourceBundle::getString( const UnicodeString& resourceTag,
ResourceBundle::getString( const char *resourceTag,
UnicodeString& theString,
UErrorCode& err) const
{
@ -636,7 +636,7 @@ ResourceBundle::getString( const UnicodeString& resourceTag,
}
const UnicodeString*
ResourceBundle::getString( const UnicodeString& resourceTag,
ResourceBundle::getString( const char *resourceTag,
UErrorCode& err) const
{
if(U_FAILURE(err))
@ -653,7 +653,7 @@ ResourceBundle::getString( const UnicodeString& resourceTag,
}
const UnicodeString*
ResourceBundle::getStringArray( const UnicodeString& resourceTag,
ResourceBundle::getStringArray( const char *resourceTag,
int32_t& count,
UErrorCode& err) const
{
@ -671,7 +671,7 @@ ResourceBundle::getStringArray( const UnicodeString& resourceTag,
}
void
ResourceBundle::getArrayItem( const UnicodeString& resourceTag,
ResourceBundle::getArrayItem( const char *resourceTag,
int32_t index,
UnicodeString& theArrayItem,
UErrorCode& err) const
@ -685,7 +685,7 @@ ResourceBundle::getArrayItem( const UnicodeString& resourceTag,
}
const UnicodeString*
ResourceBundle::getArrayItem( const UnicodeString& resourceTag,
ResourceBundle::getArrayItem( const char *resourceTag,
int32_t index,
UErrorCode& err) const
{
@ -708,7 +708,7 @@ ResourceBundle::getArrayItem( const UnicodeString& resourceTag,
}
const UnicodeString**
ResourceBundle::get2dArray(const UnicodeString& resourceTag,
ResourceBundle::get2dArray(const char *resourceTag,
int32_t& rowCount,
int32_t& columnCount,
UErrorCode& err) const
@ -730,7 +730,7 @@ ResourceBundle::get2dArray(const UnicodeString& resourceTag,
}
void
ResourceBundle::get2dArrayItem(const UnicodeString& resourceTag,
ResourceBundle::get2dArrayItem(const char *resourceTag,
int32_t rowIndex,
int32_t columnIndex,
UnicodeString& theArrayItem,
@ -747,7 +747,7 @@ ResourceBundle::get2dArrayItem(const UnicodeString& resourceTag,
}
const UnicodeString*
ResourceBundle::get2dArrayItem(const UnicodeString& resourceTag,
ResourceBundle::get2dArrayItem(const char *resourceTag,
int32_t rowIndex,
int32_t columnIndex,
UErrorCode& err) const
@ -773,7 +773,7 @@ ResourceBundle::get2dArrayItem(const UnicodeString& resourceTag,
}
void
ResourceBundle::getTaggedArrayItem( const UnicodeString& resourceTag,
ResourceBundle::getTaggedArrayItem( const char *resourceTag,
const UnicodeString& itemTag,
UnicodeString& theArrayItem,
UErrorCode& err) const
@ -788,7 +788,7 @@ ResourceBundle::getTaggedArrayItem( const UnicodeString& resourceTag,
}
const UnicodeString*
ResourceBundle::getTaggedArrayItem( const UnicodeString& resourceTag,
ResourceBundle::getTaggedArrayItem( const char *resourceTag,
const UnicodeString& itemTag,
UErrorCode& err) const
{
@ -809,7 +809,7 @@ ResourceBundle::getTaggedArrayItem( const UnicodeString& resourceTag,
extern "C" void
T_ResourceBundle_getTaggedArrayUChars(const ResourceBundle* bundle,
const UnicodeString& resourceTag,
const char *resourceTag,
UChar const** itemTags,
UChar const** items,
int32_t maxItems,
@ -829,7 +829,7 @@ T_ResourceBundle_getTaggedArrayUChars(const ResourceBundle* bundle,
void
getTaggedArrayUCharsImplementation( const ResourceBundle* bundle,
const UnicodeString& resourceTag,
const char *resourceTag,
UChar const** itemTags,
UChar const** items,
int32_t maxItems,
@ -867,7 +867,7 @@ getTaggedArrayUCharsImplementation( const ResourceBundle* bundle,
}
void
ResourceBundle::getTaggedArray( const UnicodeString& resourceTag,
ResourceBundle::getTaggedArray( const char *resourceTag,
UnicodeString*& itemTags,
UnicodeString*& items,
int32_t& numItems,

View file

@ -196,7 +196,7 @@ public:
* @param err Set to U_MISSING_RESOURCE_ERROR if a resource with the
* specified tag couldn't be found.
*/
void getString( const UnicodeString& resourceTag,
void getString( const char *resourceTag,
UnicodeString& theString,
UErrorCode& err) const;
@ -211,7 +211,7 @@ public:
* @return A pointer to the string from the resource bundle, or NULL if there was
* an error.
*/
const UnicodeString* getString( const UnicodeString& resourceTag,
const UnicodeString* getString( const char *resourceTag,
UErrorCode& err) const;
/**
@ -232,7 +232,7 @@ public:
* UnicodeStrings. The caller does not own the storage and
* must not delete it.
*/
const UnicodeString* getStringArray( const UnicodeString& resourceTag,
const UnicodeString* getStringArray( const char *resourceTag,
int32_t& numArrayItems,
UErrorCode& err) const;
@ -250,7 +250,7 @@ public:
* @param err Set to U_MISSING_RESOURCE_ERROR if a resource with the
* specified tag couldn't be found, or if the index was out of range.
*/
void getArrayItem( const UnicodeString& resourceTag,
void getArrayItem( const char *resourceTag,
int32_t index,
UnicodeString& theArrayItem,
UErrorCode& err) const;
@ -268,7 +268,7 @@ public:
* specified tag couldn't be found, or if the index was out of range.
* @return A pointer to the text of the array item, or NULL is there was an error.
*/
const UnicodeString* getArrayItem( const UnicodeString& resourceTag,
const UnicodeString* getArrayItem( const char *resourceTag,
int32_t index,
UErrorCode& err) const;
@ -289,7 +289,7 @@ public:
* @return The resource requested, as a UnicodeStrings**. The caller
* does not own the storage and must not delete it.
*/
const UnicodeString** get2dArray(const UnicodeString& resourceTag,
const UnicodeString** get2dArray(const char *resourceTag,
int32_t& rowCount,
int32_t& columnCount,
UErrorCode& err) const;
@ -311,7 +311,7 @@ public:
* specified tag couldn't be found, if the resource data was in
* the wrong format, or if either index is out of bounds.
*/
void get2dArrayItem(const UnicodeString& resourceTag,
void get2dArrayItem(const char *resourceTag,
int32_t rowIndex,
int32_t columnIndex,
UnicodeString& theArrayItem,
@ -333,7 +333,7 @@ public:
* the wrong format, or if either index is out of bounds.
* @return A pointer to the text of the array item, or NULL is there was an error.
*/
const UnicodeString* get2dArrayItem( const UnicodeString& resourceTag,
const UnicodeString* get2dArrayItem( const char *resourceTag,
int32_t rowIndex,
int32_t columnIndex,
UErrorCode& err) const;
@ -353,7 +353,7 @@ public:
* specified resource tag couldn't be found, or if an item
* with the specified item tag couldn't be found in the resource.
*/
void getTaggedArrayItem( const UnicodeString& resourceTag,
void getTaggedArrayItem( const char *resourceTag,
const UnicodeString& itemTag,
UnicodeString& theArrayItem,
UErrorCode& err) const;
@ -372,7 +372,7 @@ public:
* with the specified item tag coldn't be found in the resource.
* @return A pointer to the text of the array item, or NULL is there was an error.
*/
const UnicodeString* getTaggedArrayItem( const UnicodeString& resourceTag,
const UnicodeString* getTaggedArrayItem( const char *resourceTag,
const UnicodeString& itemTag,
UErrorCode& err) const;
@ -398,7 +398,7 @@ public:
* @param err Set to U_MISSING_RESOURCE_ERROR if a resource with the
* specified tag couldn't be found.
*/
void getTaggedArray( const UnicodeString& resourceTag,
void getTaggedArray( const char *resourceTag,
UnicodeString*& itemTags,
UnicodeString*& items,
int32_t& numItems,
@ -466,7 +466,7 @@ private:
int32_t* numInstalledLocales);
friend void getTaggedArrayUCharsImplementation(
const ResourceBundle* bundle,
const UnicodeString& resourceTag,
const char *resourceTag,
UChar const** itemTags,
UChar const** items,
int32_t maxItems,
@ -554,7 +554,7 @@ private:
const UHashtable* getHashtableForLocale(const UnicodeString& desiredLocale,
UErrorCode& error);
const ResourceBundleData* getDataForTag(const UnicodeString& tag,
const ResourceBundleData* getDataForTag(const char *tag,
UErrorCode& err) const;
void constructForLocale(const PathInfo& path,
@ -609,7 +609,7 @@ private:
static const char* kDefaultMinorVersion;
static const char* kVersionSeparator;
static const UnicodeString kVersionTag;
static const char* kVersionTag;
static ResourceBundleCache* fgUserCache;
static VisitedFileCache* fgUserVisitedFiles;

View file

@ -32,8 +32,8 @@ const int32_t DecimalFormatSymbols::fgCurrencyElementsLength = 3;
* These are the tags we expect to see in normal resource bundle files associated
* with a locale.
*/
const UnicodeString DecimalFormatSymbols::fgNumberElements("NumberElements");
const UnicodeString DecimalFormatSymbols::fgCurrencyElements("CurrencyElements");
const char *DecimalFormatSymbols::fgNumberElements="NumberElements";
const char *DecimalFormatSymbols::fgCurrencyElements="CurrencyElements";
// Because the C-compiler doesn't parse \u escape sequences, we encode the
// \u last resort strings as UChar arrays.

View file

@ -250,8 +250,8 @@ private:
* The resource tags we use to retrieve decimal format data from
* locale resource bundles.
*/
static const UnicodeString fgNumberElements;
static const UnicodeString fgCurrencyElements;
static const char *fgNumberElements;
static const char *fgCurrencyElements;
static const int32_t fgNumberElementsLength;
static const int32_t fgCurrencyElementsLength;
static const UnicodeString fgLastResortNumberElements[];

View file

@ -92,7 +92,7 @@ const int32_t DecimalFormat::kDoubleFractionDigits = 340;
* These are the tags we expect to see in normal resource bundle files associated
* with a locale.
*/
const UnicodeString DecimalFormat::fgNumberPatterns("NumberPatterns");
const char *DecimalFormat::fgNumberPatterns="NumberPatterns";
//------------------------------------------------------------------------------
// Constructs a DecimalFormat instance in the default locale.

View file

@ -783,7 +783,7 @@ public:
* The resource tags we use to retrieve decimal format data from
* locale resource bundles.
*/
static const UnicodeString fgNumberPatterns;
static const char *fgNumberPatterns;
public:

View file

@ -58,20 +58,20 @@ const UnicodeString SimpleDateFormat::fgDefaultPattern("yyMMdd hh:mm a");
* These are the tags we expect to see in normal resource bundle files associated
* with a locale.
*/
const UnicodeString SimpleDateFormat::fgErasTag("Eras");
const UnicodeString SimpleDateFormat::fgMonthNamesTag("MonthNames");
const UnicodeString SimpleDateFormat::fgMonthAbbreviationsTag("MonthAbbreviations");
const UnicodeString SimpleDateFormat::fgDayNamesTag("DayNames");
const UnicodeString SimpleDateFormat::fgDayAbbreviationsTag("DayAbbreviations");
const UnicodeString SimpleDateFormat::fgAmPmMarkersTag("AmPmMarkers");
const UnicodeString SimpleDateFormat::fgDateTimePatternsTag("DateTimePatterns");
const char *SimpleDateFormat::fgErasTag="Eras";
const char *SimpleDateFormat::fgMonthNamesTag="MonthNames";
const char *SimpleDateFormat::fgMonthAbbreviationsTag="MonthAbbreviations";
const char *SimpleDateFormat::fgDayNamesTag="DayNames";
const char *SimpleDateFormat::fgDayAbbreviationsTag="DayAbbreviations";
const char *SimpleDateFormat::fgAmPmMarkersTag="AmPmMarkers";
const char *SimpleDateFormat::fgDateTimePatternsTag="DateTimePatterns";
/**
* These are the tags we expect to see in time zone data resource bundle files
* associated with a locale.
*/
const UnicodeString SimpleDateFormat::fgZoneStringsTag("zoneStrings");
const UnicodeString SimpleDateFormat::fgLocalPatternCharsTag("localPatternChars");
const char *SimpleDateFormat::fgZoneStringsTag="zoneStrings";
const char *SimpleDateFormat::fgLocalPatternCharsTag="localPatternChars";
char SimpleDateFormat::fgClassID = 0; // Value is irrelevant

View file

@ -428,16 +428,16 @@ public:
/**
* Resource bundle file suffix and tag names used by this class.
*/
static const UnicodeString fgErasTag; // resource bundle tag for era names
static const UnicodeString fgMonthNamesTag; // resource bundle tag for month names
static const UnicodeString fgMonthAbbreviationsTag; // resource bundle tag for month abbreviations
static const UnicodeString fgDayNamesTag; // resource bundle tag for day names
static const UnicodeString fgDayAbbreviationsTag; // resource bundle tag for day abbreviations
static const UnicodeString fgAmPmMarkersTag; // resource bundle tag for AM/PM strings
static const UnicodeString fgDateTimePatternsTag; // resource bundle tag for default date and time patterns
static const char *fgErasTag; // resource bundle tag for era names
static const char *fgMonthNamesTag; // resource bundle tag for month names
static const char *fgMonthAbbreviationsTag; // resource bundle tag for month abbreviations
static const char *fgDayNamesTag; // resource bundle tag for day names
static const char *fgDayAbbreviationsTag; // resource bundle tag for day abbreviations
static const char *fgAmPmMarkersTag; // resource bundle tag for AM/PM strings
static const char *fgDateTimePatternsTag; // resource bundle tag for default date and time patterns
static const UnicodeString fgZoneStringsTag; // resource bundle tag for time zone names
static const UnicodeString fgLocalPatternCharsTag; // resource bundle tag for localized pattern characters
static const char *fgZoneStringsTag; // resource bundle tag for time zone names
static const char *fgLocalPatternCharsTag; // resource bundle tag for localized pattern characters
static const UnicodeString fgDefaultPattern; // date/time pattern of last resort

View file

@ -392,8 +392,11 @@ UnicodeString& Transliterator::getDisplayName(const Locale& inLocale,
ResourceBundle bundle(Locale::getDataDirectory(), inLocale, status);
// Suspend checking status until later...
UnicodeString key(RB_DISPLAY_NAME_PREFIX);
key.append(ID);
// build the char* key
char key[100];
icu_strcpy(key, RB_DISPLAY_NAME_PREFIX);
int32_t length=icu_strlen(RB_DISPLAY_NAME_PREFIX);
key[ID.extract(0, sizeof(key)-length-1, key+length, "")]=0;
// Try to retrieve a UnicodeString* from the bundle. The result,
// if any, should NOT be deleted.

View file

@ -1406,8 +1406,7 @@ void NumberFormatRegressionTest::Test4122840()
// will return the localized symbol, not \00a4
//
int32_t resCount = 0;
const UnicodeString *numPatterns = rb->getStringArray(UnicodeString("NumberPatterns"),
resCount, status);
const UnicodeString *numPatterns = rb->getStringArray("NumberPatterns", resCount, status);
failure(status, "rb->getStringArray");
UnicodeString pattern = numPatterns[1];

View file

@ -11,22 +11,24 @@
*****************************************************************************************
*/
#include "restest.h"
#include "resbund.h"
#include "unistr.h"
#include <time.h>
#include <string.h>
#include <limits.h>
#define RESTEST_HEAP_CHECK 0
#include "utypes.h"
#if defined(_WIN32) && !defined(__WINDOWS__)
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#endif
#include "cstring.h"
#include "unistr.h"
#include "resbund.h"
#include "restest.h"
//***************************************************************************************
const UnicodeString kERROR = "ERROR";
@ -341,7 +343,7 @@ ResourceBundleTest::testTag(const char* frag,
// Now try to load the desired items
UnicodeString tag;
char tag[100];
UnicodeString action;
int32_t i,j,row,col, actual_bundle;
@ -359,28 +361,28 @@ ResourceBundleTest::testTag(const char* frag,
ResourceBundle theBundle( directory, *param[i].locale, status);
CONFIRM_UErrorCode(status,param[i].expected_constructor_status);
if(i == 5)
actual_bundle = 0; /* ne -> default */
else if(i == 3)
actual_bundle = 1; /* te_NE -> te */
else if(i == 4)
actual_bundle = 2; /* te_IN_NE -> te_IN */
else
actual_bundle = i;
if(i == 5)
actual_bundle = 0; /* ne -> default */
else if(i == 3)
actual_bundle = 1; /* te_NE -> te */
else if(i == 4)
actual_bundle = 2; /* te_IN_NE -> te_IN */
else
actual_bundle = i;
UErrorCode expected_resource_status = U_MISSING_RESOURCE_ERROR;
for (j=e_te_IN; j>=e_Default; --j)
{
if (is_in[j] && param[i].inherits[j])
{
if(j == actual_bundle) /* it's in the same bundle OR it's a nonexistent=default bundle (5) */
expected_resource_status = U_ZERO_ERROR;
else if(j == 0)
expected_resource_status = U_USING_DEFAULT_ERROR;
else
expected_resource_status = U_USING_FALLBACK_ERROR;
{
if(j == actual_bundle) /* it's in the same bundle OR it's a nonexistent=default bundle (5) */
expected_resource_status = U_ZERO_ERROR;
else if(j == 0)
expected_resource_status = U_USING_DEFAULT_ERROR;
else
expected_resource_status = U_USING_FALLBACK_ERROR;
break;
}
}
@ -405,8 +407,8 @@ ResourceBundleTest::testTag(const char* frag,
action += tag;
action += ")";
tag = "string_";
tag += frag;
icu_strcpy(tag, "string_");
icu_strcat(tag, frag);
UnicodeString string(kERROR);
status = U_ZERO_ERROR;
@ -427,8 +429,8 @@ ResourceBundleTest::testTag(const char* frag,
action += tag;
action += ")";
tag = "array_";
tag += frag;
icu_strcpy(tag, "array_");
icu_strcat(tag, frag);
int32_t count = kERROR_COUNT;
status = U_ZERO_ERROR;
@ -493,8 +495,8 @@ ResourceBundleTest::testTag(const char* frag,
action += tag;
action += ")";
tag = "array_2d_";
tag += frag;
icu_strcpy(tag, "array_2d_");
icu_strcat(tag, frag);
int32_t row_count = kERROR_COUNT, column_count = kERROR_COUNT;
status = U_ZERO_ERROR;
@ -543,7 +545,7 @@ ResourceBundleTest::testTag(const char* frag,
string = kERROR;
theBundle.get2dArrayItem(tag, row, col, string, status);
expected_status = (row >= 0 && row < row_count && col >= 0 && col < column_count) ?
expected_resource_status: U_MISSING_RESOURCE_ERROR;
expected_resource_status: U_MISSING_RESOURCE_ERROR;
CONFIRM_UErrorCode(status,expected_status);
if (U_SUCCESS(status))
@ -563,8 +565,8 @@ ResourceBundleTest::testTag(const char* frag,
//--------------------------------------------------------------------------
// taggedArrayItem
tag = "tagged_array_";
tag += frag;
icu_strcpy(tag, "tagged_array_");
icu_strcat(tag, frag);
action = param[i].name;
action += ".getTaggedArray(";