2003-11-07 02:39:42 +00:00
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* *
|
2007-06-14 01:30:51 +00:00
|
|
|
* Copyright (C) 2003-2007, International Business Machines *
|
2003-11-07 02:39:42 +00:00
|
|
|
* Corporation and others. All Rights Reserved. *
|
|
|
|
* *
|
|
|
|
******************************************************************************
|
|
|
|
* file name: ulocdata.c
|
|
|
|
* encoding: US-ASCII
|
|
|
|
* tab size: 8 (not used)
|
|
|
|
* indentation:4
|
|
|
|
*
|
|
|
|
* created on: 2003Oct21
|
2005-06-30 16:56:46 +00:00
|
|
|
* created by: Ram Viswanadha,John Emmons
|
2003-11-07 02:39:42 +00:00
|
|
|
*/
|
|
|
|
|
2005-06-24 20:09:52 +00:00
|
|
|
#include "cmemory.h"
|
|
|
|
#include "unicode/ustring.h"
|
2003-11-07 02:39:42 +00:00
|
|
|
#include "unicode/ulocdata.h"
|
|
|
|
|
|
|
|
#define MEASUREMENT_SYSTEM "MeasurementSystem"
|
|
|
|
#define PAPER_SIZE "PaperSize"
|
|
|
|
|
2005-12-01 17:51:20 +00:00
|
|
|
/** A locale data object.
|
|
|
|
* For usage in C programs.
|
|
|
|
* @draft ICU 3.4
|
|
|
|
*/
|
2005-12-02 00:05:15 +00:00
|
|
|
struct ULocaleData {
|
2005-12-01 17:51:20 +00:00
|
|
|
/**
|
|
|
|
* Controls the "No Substitute" behavior of this locale data object
|
|
|
|
*/
|
|
|
|
UBool noSubstitute;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pointer to the resource bundle associated with this locale data object
|
|
|
|
*/
|
|
|
|
UResourceBundle *bundle;
|
2005-12-02 00:05:15 +00:00
|
|
|
};
|
2005-12-01 17:51:20 +00:00
|
|
|
|
2005-06-24 15:48:23 +00:00
|
|
|
U_CAPI ULocaleData* U_EXPORT2
|
|
|
|
ulocdata_open(const char *localeID, UErrorCode *status)
|
|
|
|
{
|
|
|
|
ULocaleData *uld;
|
|
|
|
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
uld = (ULocaleData *)uprv_malloc(sizeof(ULocaleData));
|
|
|
|
if (uld == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uld->noSubstitute = FALSE;
|
|
|
|
uld->bundle = ures_open(NULL, localeID, status);
|
|
|
|
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
uprv_free(uld);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return uld;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
ulocdata_close(ULocaleData *uld)
|
|
|
|
{
|
|
|
|
if ( uld != NULL ) {
|
|
|
|
ures_close(uld->bundle);
|
|
|
|
uprv_free(uld);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-30 16:56:46 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
ulocdata_setNoSubstitute(ULocaleData *uld, UBool setting)
|
|
|
|
{
|
|
|
|
uld->noSubstitute = setting;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI UBool U_EXPORT2
|
|
|
|
ulocdata_getNoSubstitute(ULocaleData *uld)
|
|
|
|
{
|
|
|
|
return uld->noSubstitute;
|
|
|
|
}
|
|
|
|
|
2005-06-24 15:48:23 +00:00
|
|
|
U_CAPI USet* U_EXPORT2
|
|
|
|
ulocdata_getExemplarSet(ULocaleData *uld, USet *fillIn,
|
|
|
|
uint32_t options, ULocaleDataExemplarSetType extype, UErrorCode *status){
|
2003-11-07 02:39:42 +00:00
|
|
|
|
2007-06-14 01:30:51 +00:00
|
|
|
static const char* const exemplarSetTypes[] = { "ExemplarCharacters", "AuxExemplarCharacters" };
|
2003-11-07 02:39:42 +00:00
|
|
|
const UChar *exemplarChars = NULL;
|
|
|
|
int32_t len = 0;
|
2004-10-19 05:19:36 +00:00
|
|
|
UErrorCode localStatus = U_ZERO_ERROR;
|
2003-11-07 02:39:42 +00:00
|
|
|
|
2005-06-24 15:48:23 +00:00
|
|
|
if (U_FAILURE(*status))
|
2004-10-18 23:58:03 +00:00
|
|
|
return NULL;
|
2003-11-07 02:39:42 +00:00
|
|
|
|
2005-06-24 15:48:23 +00:00
|
|
|
exemplarChars = ures_getStringByKey(uld->bundle, exemplarSetTypes[extype], &len, &localStatus);
|
2005-06-30 16:56:46 +00:00
|
|
|
if ( (localStatus == U_USING_DEFAULT_WARNING) && uld->noSubstitute ) {
|
|
|
|
localStatus = U_MISSING_RESOURCE_ERROR;
|
|
|
|
}
|
|
|
|
|
2005-09-14 19:09:13 +00:00
|
|
|
if (localStatus != U_ZERO_ERROR) {
|
2004-10-18 23:58:03 +00:00
|
|
|
*status = localStatus;
|
|
|
|
}
|
2003-11-07 02:39:42 +00:00
|
|
|
|
2005-06-30 16:56:46 +00:00
|
|
|
if (U_FAILURE(*status))
|
|
|
|
return NULL;
|
|
|
|
|
2005-06-24 15:48:23 +00:00
|
|
|
if(fillIn != NULL)
|
2003-11-07 02:39:42 +00:00
|
|
|
uset_applyPattern(fillIn, exemplarChars, len,
|
2004-05-17 21:42:43 +00:00
|
|
|
USET_IGNORE_SPACE | options, status);
|
2005-06-24 15:48:23 +00:00
|
|
|
else
|
2004-05-17 21:42:43 +00:00
|
|
|
fillIn = uset_openPatternOptions(exemplarChars, len,
|
|
|
|
USET_IGNORE_SPACE | options, status);
|
2003-11-07 02:39:42 +00:00
|
|
|
|
|
|
|
return fillIn;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-06-24 15:48:23 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
ulocdata_getDelimiter(ULocaleData *uld, ULocaleDataDelimiterType type,
|
|
|
|
UChar *result, int32_t resultLength, UErrorCode *status){
|
|
|
|
|
2007-06-14 01:30:51 +00:00
|
|
|
static const char* const delimiterKeys[] = {
|
|
|
|
"quotationStart",
|
|
|
|
"quotationEnd",
|
|
|
|
"alternateQuotationStart",
|
|
|
|
"alternateQuotationEnd"
|
|
|
|
};
|
2005-06-30 16:56:46 +00:00
|
|
|
|
|
|
|
UResourceBundle *delimiterBundle;
|
2005-06-24 15:48:23 +00:00
|
|
|
int32_t len = 0;
|
|
|
|
const UChar *delimiter = NULL;
|
|
|
|
UErrorCode localStatus = U_ZERO_ERROR;
|
|
|
|
|
|
|
|
if (U_FAILURE(*status))
|
2005-06-24 22:19:45 +00:00
|
|
|
return 0;
|
2005-06-24 15:48:23 +00:00
|
|
|
|
2005-06-30 16:56:46 +00:00
|
|
|
delimiterBundle = ures_getByKey(uld->bundle, "delimiters", NULL, &localStatus);
|
|
|
|
|
|
|
|
if ( (localStatus == U_USING_DEFAULT_WARNING) && uld->noSubstitute ) {
|
|
|
|
localStatus = U_MISSING_RESOURCE_ERROR;
|
|
|
|
}
|
|
|
|
|
2005-09-14 19:09:13 +00:00
|
|
|
if (localStatus != U_ZERO_ERROR) {
|
2005-06-30 16:56:46 +00:00
|
|
|
*status = localStatus;
|
|
|
|
}
|
|
|
|
|
2005-07-14 23:25:48 +00:00
|
|
|
if (U_FAILURE(*status)){
|
|
|
|
ures_close(delimiterBundle);
|
2005-06-30 16:56:46 +00:00
|
|
|
return 0;
|
2005-07-14 23:25:48 +00:00
|
|
|
}
|
2005-06-30 16:56:46 +00:00
|
|
|
|
|
|
|
delimiter = ures_getStringByKey(delimiterBundle, delimiterKeys[type], &len, &localStatus);
|
2005-07-18 06:05:28 +00:00
|
|
|
ures_close(delimiterBundle);
|
2005-06-30 16:56:46 +00:00
|
|
|
|
|
|
|
if ( (localStatus == U_USING_DEFAULT_WARNING) && uld->noSubstitute ) {
|
|
|
|
localStatus = U_MISSING_RESOURCE_ERROR;
|
|
|
|
}
|
|
|
|
|
2005-09-14 19:09:13 +00:00
|
|
|
if (localStatus != U_ZERO_ERROR) {
|
2005-06-24 15:48:23 +00:00
|
|
|
*status = localStatus;
|
|
|
|
}
|
|
|
|
|
2005-07-14 23:25:48 +00:00
|
|
|
if (U_FAILURE(*status)){
|
2005-06-30 16:56:46 +00:00
|
|
|
return 0;
|
2005-07-14 23:25:48 +00:00
|
|
|
}
|
|
|
|
|
2005-06-24 15:48:23 +00:00
|
|
|
u_strncpy(result,delimiter,resultLength);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2003-11-07 02:39:42 +00:00
|
|
|
U_CAPI UMeasurementSystem U_EXPORT2
|
|
|
|
ulocdata_getMeasurementSystem(const char *localeID, UErrorCode *status){
|
|
|
|
|
|
|
|
UResourceBundle* bundle=NULL;
|
|
|
|
UResourceBundle* measurement=NULL;
|
|
|
|
UMeasurementSystem system = UMS_LIMIT;
|
|
|
|
|
|
|
|
if(status == NULL || U_FAILURE(*status)){
|
|
|
|
return system;
|
|
|
|
}
|
|
|
|
|
|
|
|
bundle = ures_open(NULL, localeID, status);
|
|
|
|
|
|
|
|
measurement = ures_getByKey(bundle, MEASUREMENT_SYSTEM, NULL, status);
|
|
|
|
|
|
|
|
system = (UMeasurementSystem) ures_getInt(measurement, status);
|
|
|
|
|
|
|
|
ures_close(bundle);
|
|
|
|
ures_close(measurement);
|
|
|
|
|
|
|
|
return system;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
ulocdata_getPaperSize(const char* localeID, int32_t *height, int32_t *width, UErrorCode *status){
|
|
|
|
UResourceBundle* bundle=NULL;
|
|
|
|
UResourceBundle* paperSizeBundle = NULL;
|
|
|
|
const int32_t* paperSize=NULL;
|
|
|
|
int32_t len = 0;
|
|
|
|
|
|
|
|
if(status == NULL || U_FAILURE(*status)){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bundle = ures_open(NULL, localeID, status);
|
|
|
|
paperSizeBundle = ures_getByKey(bundle, PAPER_SIZE, NULL, status);
|
|
|
|
paperSize = ures_getIntVector(paperSizeBundle, &len, status);
|
|
|
|
|
|
|
|
if(U_SUCCESS(*status)){
|
|
|
|
if(len < 2){
|
|
|
|
*status = U_INTERNAL_PROGRAM_ERROR;
|
|
|
|
}else{
|
|
|
|
*height = paperSize[0];
|
|
|
|
*width = paperSize[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ures_close(bundle);
|
2003-11-18 23:27:49 +00:00
|
|
|
ures_close(paperSizeBundle);
|
2003-11-07 02:39:42 +00:00
|
|
|
|
|
|
|
}
|