1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
1999-11-22 20:25:35 +00:00
|
|
|
* Copyright (C) 1997-1999, International Business Machines Corporation and *
|
|
|
|
* others. All Rights Reserved. *
|
1999-08-16 21:50:52 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*
|
|
|
|
* File CRESBUND.CPP
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 04/01/97 aliu Creation.
|
|
|
|
* 06/14/99 stephen Removed functions taking a filename suffix.
|
|
|
|
* 07/20/99 stephen Changed for UResourceBundle typedef'd to void*
|
1999-11-11 21:25:17 +00:00
|
|
|
* 11/09/99 weiv Added ures_getLocale()
|
1999-08-16 21:50:52 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
1999-12-28 23:39:02 +00:00
|
|
|
#include "unicode/resbund.h"
|
|
|
|
#include "unicode/ures.h"
|
|
|
|
#include "unicode/locid.h"
|
|
|
|
#include "unicode/uloc.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Functions to create and destroy resource bundles.
|
|
|
|
*/
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI UResourceBundle* ures_open( const char* myPath,
|
1999-08-16 21:50:52 +00:00
|
|
|
const char* localeID,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
|
|
|
UnicodeString uPath;
|
|
|
|
Locale myLocale;
|
|
|
|
|
|
|
|
|
|
|
|
if (myPath != 0) uPath = myPath;
|
1999-12-14 19:14:27 +00:00
|
|
|
else uPath = u_getDataDirectory();
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
if (localeID == 0) localeID = uloc_getDefault();
|
|
|
|
|
|
|
|
|
|
|
|
return (UResourceBundle*) new ResourceBundle(uPath, myLocale.init(localeID), *status);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI UResourceBundle* ures_openW( const wchar_t* myPath,
|
1999-08-16 21:50:52 +00:00
|
|
|
const char* localeID,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
|
|
|
Locale myLocale;
|
|
|
|
if (localeID == 0) localeID = uloc_getDefault();
|
|
|
|
|
|
|
|
return (UResourceBundle*) new ResourceBundle(myPath, myLocale.init(localeID), *status);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Functions to retrieve data from resource bundles.
|
|
|
|
*/
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI const UChar* ures_get( const UResourceBundle* resourceBundle,
|
1999-08-16 21:50:52 +00:00
|
|
|
const char* resourceTag,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
1999-11-11 21:25:17 +00:00
|
|
|
if (status==NULL || U_FAILURE(*status)) return NULL;
|
1999-08-16 21:50:52 +00:00
|
|
|
if (!resourceBundle || !resourceTag)
|
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const UnicodeString* tmp = ((ResourceBundle*)resourceBundle)->getString(resourceTag, *status);
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_SUCCESS(*status)) return tmp->getUChars();
|
1999-08-16 21:50:52 +00:00
|
|
|
else return NULL;
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI const UChar* ures_getArrayItem(const UResourceBundle* resourceBundle,
|
1999-08-16 21:50:52 +00:00
|
|
|
const char* resourceTag,
|
|
|
|
int32_t resourceIndex,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
1999-11-11 21:25:17 +00:00
|
|
|
if (status==NULL || U_FAILURE(*status)) return NULL;
|
1999-08-16 21:50:52 +00:00
|
|
|
if (!resourceBundle || !resourceTag || (resourceIndex < 0))
|
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const UnicodeString* tmp = ((ResourceBundle*)resourceBundle)->getArrayItem(resourceTag, resourceIndex, *status);
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_SUCCESS(*status)) return tmp->getUChars();
|
1999-08-16 21:50:52 +00:00
|
|
|
else return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI const UChar* ures_get2dArrayItem(const UResourceBundle* resourceBundle,
|
1999-08-16 21:50:52 +00:00
|
|
|
const char* resourceTag,
|
|
|
|
int32_t rowIndex,
|
|
|
|
int32_t columnIndex,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
1999-11-11 21:25:17 +00:00
|
|
|
if (status==NULL || U_FAILURE(*status)) return NULL;
|
1999-08-16 21:50:52 +00:00
|
|
|
if (!resourceBundle || !resourceTag || (rowIndex < 0) || (columnIndex < 0))
|
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const UnicodeString* tmp = ((ResourceBundle*)resourceBundle)->get2dArrayItem(resourceTag,
|
|
|
|
rowIndex,
|
|
|
|
columnIndex,
|
|
|
|
*status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_SUCCESS(*status)) return tmp->getUChars();
|
1999-08-16 21:50:52 +00:00
|
|
|
else return NULL;
|
|
|
|
}
|
|
|
|
|
1999-11-11 21:25:17 +00:00
|
|
|
U_CAPI const char* ures_getLocale(const UResourceBundle* resourceBundle, UErrorCode* status)
|
|
|
|
{
|
|
|
|
if (status==NULL || U_FAILURE(*status)) return NULL;
|
|
|
|
if (!resourceBundle)
|
|
|
|
{
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return ((ResourceBundle*)resourceBundle)->getLocale().getName();
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI const UChar* ures_getTaggedArrayItem(const UResourceBundle* resourceBundle,
|
1999-08-16 21:50:52 +00:00
|
|
|
const char* resourceTag,
|
|
|
|
const char* itemTag,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
1999-11-11 21:25:17 +00:00
|
|
|
if (status==NULL || U_FAILURE(*status)) return NULL;
|
1999-08-16 21:50:52 +00:00
|
|
|
if (!resourceBundle || !resourceTag || !itemTag)
|
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const UnicodeString* tmp = ((ResourceBundle*)resourceBundle)->getTaggedArrayItem(resourceTag,
|
|
|
|
itemTag,
|
|
|
|
*status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_SUCCESS(*status)) return tmp->getUChars();
|
1999-08-16 21:50:52 +00:00
|
|
|
else return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI const char* ures_getVersionNumber(const UResourceBundle* resourceBundle)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
if (!resourceBundle) return NULL;
|
|
|
|
return ((ResourceBundle*)resourceBundle)->getVersionNumber();
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" int32_t T_ResourceBundle_countArrayItems(const ResourceBundle* rb,
|
|
|
|
const char* resourceKey,
|
|
|
|
UErrorCode* err);
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI int32_t ures_countArrayItems(const UResourceBundle* resourceBundle,
|
1999-08-16 21:50:52 +00:00
|
|
|
const char* resourceKey,
|
|
|
|
UErrorCode* err)
|
|
|
|
{
|
|
|
|
return T_ResourceBundle_countArrayItems((ResourceBundle*)resourceBundle,
|
|
|
|
resourceKey,
|
|
|
|
err);
|
|
|
|
}
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
U_CAPI void ures_close( UResourceBundle* resourceBundle)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
delete resourceBundle;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a list of all available ULocales. The return value is a pointer to
|
|
|
|
* an array of pointers to ULocale objects. Both this array and the pointers
|
|
|
|
* it contains are owned by ICU and should not be deleted or written through
|
|
|
|
* by the caller. The array is terminated by a null pointer.
|
|
|
|
*/
|
1999-12-29 22:33:47 +00:00
|
|
|
extern "C" void T_ResourceBundle_getTaggedArrayUChars(const ResourceBundle* resourceBundle,
|
1999-08-16 21:50:52 +00:00
|
|
|
const UnicodeString& resourceTag,
|
|
|
|
UChar const** itemTags,
|
|
|
|
UChar const** items,
|
|
|
|
int32_t maxItems,
|
|
|
|
int32_t* numItems,
|
|
|
|
UErrorCode* err);
|
|
|
|
|
|
|
|
//eof
|