2 *******************************************************************************
4 * Copyright (C) 1998-2004, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
11 * Modification History:
13 * Date Name Description
14 * 11/18/98 stephen Creation.
15 * 12/10/1999 bobbyr@optiosoftware.com Fix for memory leak + string allocation bugs
16 *******************************************************************************
21 #include "unicode/utypes.h"
23 #if !UCONFIG_NO_FORMATTING
28 #include "unicode/ustring.h"
29 #include "unicode/uloc.h"
32 u_locbund_init(ULocaleBundle
*result
, const char *loc
)
40 loc
= uloc_getDefault();
43 uprv_memset(result
, 0, sizeof(ULocaleBundle
));
45 len
= (int32_t)strlen(loc
);
46 result
->fLocale
= (char*) uprv_malloc(len
+ 1);
47 if(result
->fLocale
== 0) {
51 strcpy(result
->fLocale
, loc
);
57 u_locbund_new(const char *loc)
59 ULocaleBundle *result = (ULocaleBundle*) uprv_malloc(sizeof(ULocaleBundle));
60 return u_locbund_init(result, loc);
64 u_locbund_clone(const ULocaleBundle *bundle)
66 ULocaleBundle *result = (ULocaleBundle*)uprv_malloc(sizeof(ULocaleBundle));
67 UErrorCode status = U_ZERO_ERROR;
73 result->fLocale = (char*) uprv_malloc(strlen(bundle->fLocale) + 1);
74 if(result->fLocale == 0) {
79 strcpy(result->fLocale, bundle->fLocale );
81 for (styleIdx = 0; styleIdx < ULOCALEBUNDLE_NUMBERFORMAT_COUNT; styleIdx++) {
82 status = U_ZERO_ERROR;
83 if (result->fNumberFormat[styleIdx]) {
84 result->fNumberFormat[styleIdx] = unum_clone(bundle->fNumberFormat[styleIdx], &status);
85 if (U_FAILURE(status)) {
86 result->fNumberFormat[styleIdx] = NULL;
90 result->fNumberFormat[styleIdx] = NULL;
93 result->fDateFormat = (bundle->fDateFormat == 0 ? 0 :
94 udat_clone(bundle->fDateFormat, &status));
95 result->fTimeFormat = (bundle->fTimeFormat == 0 ? 0 :
96 udat_clone(bundle->fTimeFormat, &status));
102 u_locbund_close(ULocaleBundle
*bundle
)
106 uprv_free(bundle
->fLocale
);
108 for (styleIdx
= 0; styleIdx
< ULOCALEBUNDLE_NUMBERFORMAT_COUNT
; styleIdx
++) {
109 if (bundle
->fNumberFormat
[styleIdx
]) {
110 unum_close(bundle
->fNumberFormat
[styleIdx
]);
114 uprv_memset(bundle
, 0, sizeof(ULocaleBundle
));
115 /* uprv_free(bundle);*/
119 u_locbund_getNumberFormat(ULocaleBundle
*bundle
, UNumberFormatStyle style
)
121 UNumberFormat
*formatAlias
= NULL
;
122 if (style
>= UNUM_IGNORE
) {
123 formatAlias
= bundle
->fNumberFormat
[style
-1];
124 if (formatAlias
== NULL
) {
125 UErrorCode status
= U_ZERO_ERROR
;
126 formatAlias
= unum_open(style
, NULL
, 0, bundle
->fLocale
, NULL
, &status
);
127 if (U_FAILURE(status
)) {
128 unum_close(formatAlias
);
132 bundle
->fNumberFormat
[style
-1] = formatAlias
;
139 #endif /* #if !UCONFIG_NO_FORMATTING */