1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
2000-01-13 23:54:23 +00:00
|
|
|
*
|
2004-05-19 20:59:59 +00:00
|
|
|
* Copyright (C) 1998-2004, International Business Machines
|
2000-01-13 23:54:23 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
1999-08-16 21:50:52 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*
|
|
|
|
* File locbund.c
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 11/18/98 stephen Creation.
|
1999-12-10 19:16:17 +00:00
|
|
|
* 12/10/1999 bobbyr@optiosoftware.com Fix for memory leak + string allocation bugs
|
1999-08-16 21:50:52 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
2000-08-28 22:48:46 +00:00
|
|
|
#include <stdlib.h>
|
2002-10-01 01:26:49 +00:00
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "locbund.h"
|
1999-12-28 23:39:02 +00:00
|
|
|
|
2002-02-28 01:42:40 +00:00
|
|
|
#include "cmemory.h"
|
1999-12-28 23:39:02 +00:00
|
|
|
#include "unicode/ustring.h"
|
|
|
|
#include "unicode/uloc.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
ULocaleBundle*
|
2003-08-06 16:18:38 +00:00
|
|
|
u_locbund_init(ULocaleBundle *result, const char *loc)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-08-06 16:18:38 +00:00
|
|
|
int32_t len;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2003-08-06 16:18:38 +00:00
|
|
|
if(result == 0)
|
|
|
|
return 0;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2003-08-06 16:18:38 +00:00
|
|
|
if (loc == NULL) {
|
|
|
|
loc = uloc_getDefault();
|
|
|
|
}
|
|
|
|
|
|
|
|
uprv_memset(result, 0, sizeof(ULocaleBundle));
|
|
|
|
|
|
|
|
len = (int32_t)strlen(loc);
|
|
|
|
result->fLocale = (char*) uprv_malloc(len + 1);
|
|
|
|
if(result->fLocale == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(result->fLocale, loc);
|
|
|
|
|
|
|
|
return result;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2003-08-06 16:18:38 +00:00
|
|
|
/*ULocaleBundle*
|
|
|
|
u_locbund_new(const char *loc)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-08-06 16:18:38 +00:00
|
|
|
ULocaleBundle *result = (ULocaleBundle*) uprv_malloc(sizeof(ULocaleBundle));
|
|
|
|
return u_locbund_init(result, loc);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2003-08-06 16:18:38 +00:00
|
|
|
ULocaleBundle*
|
|
|
|
u_locbund_clone(const ULocaleBundle *bundle)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-08-06 16:18:38 +00:00
|
|
|
ULocaleBundle *result = (ULocaleBundle*)uprv_malloc(sizeof(ULocaleBundle));
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
int32_t styleIdx;
|
|
|
|
|
|
|
|
if(result == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
result->fLocale = (char*) uprv_malloc(strlen(bundle->fLocale) + 1);
|
|
|
|
if(result->fLocale == 0) {
|
|
|
|
uprv_free(result);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(result->fLocale, bundle->fLocale );
|
|
|
|
|
|
|
|
for (styleIdx = 0; styleIdx < ULOCALEBUNDLE_NUMBERFORMAT_COUNT; styleIdx++) {
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
if (result->fNumberFormat[styleIdx]) {
|
|
|
|
result->fNumberFormat[styleIdx] = unum_clone(bundle->fNumberFormat[styleIdx], &status);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
result->fNumberFormat[styleIdx] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result->fNumberFormat[styleIdx] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result->fDateFormat = (bundle->fDateFormat == 0 ? 0 :
|
|
|
|
udat_clone(bundle->fDateFormat, &status));
|
|
|
|
result->fTimeFormat = (bundle->fTimeFormat == 0 ? 0 :
|
|
|
|
udat_clone(bundle->fTimeFormat, &status));
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}*/
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2003-08-06 16:18:38 +00:00
|
|
|
void
|
|
|
|
u_locbund_close(ULocaleBundle *bundle)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-08-06 16:18:38 +00:00
|
|
|
int32_t styleIdx;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2003-08-06 16:18:38 +00:00
|
|
|
uprv_free(bundle->fLocale);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2003-08-06 16:18:38 +00:00
|
|
|
for (styleIdx = 0; styleIdx < ULOCALEBUNDLE_NUMBERFORMAT_COUNT; styleIdx++) {
|
|
|
|
if (bundle->fNumberFormat[styleIdx]) {
|
|
|
|
unum_close(bundle->fNumberFormat[styleIdx]);
|
|
|
|
}
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2003-08-06 16:18:38 +00:00
|
|
|
uprv_memset(bundle, 0, sizeof(ULocaleBundle));
|
|
|
|
/* uprv_free(bundle);*/
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UNumberFormat*
|
2003-08-06 16:18:38 +00:00
|
|
|
u_locbund_getNumberFormat(ULocaleBundle *bundle, UNumberFormatStyle style)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2004-05-20 18:21:41 +00:00
|
|
|
UNumberFormat *formatAlias = NULL;
|
2003-08-06 16:18:38 +00:00
|
|
|
if (style >= UNUM_IGNORE) {
|
2004-05-20 18:21:41 +00:00
|
|
|
formatAlias = bundle->fNumberFormat[style-1];
|
|
|
|
if (formatAlias == NULL) {
|
2003-08-06 16:18:38 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2004-05-20 18:21:41 +00:00
|
|
|
formatAlias = unum_open(style, NULL, 0, bundle->fLocale, NULL, &status);
|
2003-08-06 16:18:38 +00:00
|
|
|
if (U_FAILURE(status)) {
|
2004-05-20 18:21:41 +00:00
|
|
|
unum_close(formatAlias);
|
|
|
|
formatAlias = NULL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bundle->fNumberFormat[style-1] = formatAlias;
|
2003-08-06 16:18:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-05-20 18:21:41 +00:00
|
|
|
return formatAlias;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2002-10-01 01:26:49 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|