~ubuntu-branches/ubuntu/gutsy/icu/gutsy-updates

« back to all changes in this revision

Viewing changes to source/extra/ustdio/locbund.c

  • Committer: Package Import Robot
  • Author(s): Jay Berkenbilt
  • Date: 2005-11-19 11:29:31 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20051119112931-vcizkrp10tli4enw
Tags: 3.4-3
Explicitly build with g++ 3.4.  The current ICU fails its test suite
with 4.0 but not with 3.4.  Future versions should work properly with
4.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
*******************************************************************************
3
 
*
4
 
*   Copyright (C) 1998-1999, International Business Machines
5
 
*   Corporation and others.  All Rights Reserved.
6
 
*
7
 
*******************************************************************************
8
 
*
9
 
* File locbund.c
10
 
*
11
 
* Modification History:
12
 
*
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
 
*******************************************************************************
17
 
*/
18
 
 
19
 
#include <stdlib.h>
20
 
#include "locbund.h"
21
 
 
22
 
#include "cmemory.h"
23
 
#include "unicode/ustring.h"
24
 
#include "unicode/uloc.h"
25
 
 
26
 
ULocaleBundle*        
27
 
u_locbund_new(const char *loc)
28
 
{
29
 
  ULocaleBundle *result = (ULocaleBundle*) uprv_malloc(sizeof(ULocaleBundle));
30
 
  int32_t len;
31
 
 
32
 
  if(result == 0)
33
 
    return 0;
34
 
 
35
 
  len = (loc == 0 ? strlen(uloc_getDefault()) : strlen(loc));
36
 
  result->fLocale = (char*) uprv_malloc(len + 1);
37
 
  if(result->fLocale == 0) {
38
 
    uprv_free(result);
39
 
    return 0;
40
 
  }
41
 
  
42
 
  strcpy(result->fLocale, (loc == 0 ? uloc_getDefault() : loc) );
43
 
  
44
 
  result->fNumberFormat     = 0;
45
 
  result->fPercentFormat     = 0;
46
 
  result->fCurrencyFormat     = 0;
47
 
  result->fScientificFormat     = 0;
48
 
  result->fSpelloutFormat     = 0;
49
 
  result->fDateFormat         = 0;
50
 
  result->fTimeFormat         = 0;
51
 
 
52
 
  return result;
53
 
}
54
 
 
55
 
ULocaleBundle*
56
 
u_locbund_clone(const ULocaleBundle *bundle)
57
 
{
58
 
  ULocaleBundle *result = (ULocaleBundle*)uprv_malloc(sizeof(ULocaleBundle));
59
 
  UErrorCode status = U_ZERO_ERROR;
60
 
 
61
 
  if(result == 0)
62
 
    return 0;
63
 
  
64
 
  result->fLocale = (char*) uprv_malloc(strlen(bundle->fLocale) + 1);
65
 
  if(result->fLocale == 0) {
66
 
    uprv_free(result);
67
 
    return 0;
68
 
  }
69
 
  
70
 
  strcpy(result->fLocale, bundle->fLocale );
71
 
  
72
 
  result->fNumberFormat     = (bundle->fNumberFormat == 0 ? 0 :
73
 
                   unum_clone(bundle->fNumberFormat, &status));
74
 
  result->fPercentFormat     = (bundle->fPercentFormat == 0 ? 0 :
75
 
                   unum_clone(bundle->fPercentFormat, 
76
 
                          &status));
77
 
  result->fCurrencyFormat     = (bundle->fCurrencyFormat == 0 ? 0 :
78
 
                   unum_clone(bundle->fCurrencyFormat, 
79
 
                          &status));
80
 
  result->fScientificFormat     = (bundle->fScientificFormat == 0 ? 0 :
81
 
                   unum_clone(bundle->fScientificFormat, 
82
 
                          &status));
83
 
  result->fSpelloutFormat     = (bundle->fSpelloutFormat == 0 ? 0 :
84
 
                   unum_clone(bundle->fSpelloutFormat, 
85
 
                          &status));
86
 
  result->fDateFormat         = (bundle->fDateFormat == 0 ? 0 :
87
 
                   udat_clone(bundle->fDateFormat, &status));
88
 
  result->fTimeFormat         = (bundle->fTimeFormat == 0 ? 0 :
89
 
                   udat_clone(bundle->fTimeFormat, &status));
90
 
 
91
 
  return result;
92
 
}
93
 
 
94
 
void
95
 
u_locbund_delete(ULocaleBundle *bundle)
96
 
{
97
 
  uprv_free(bundle->fLocale);
98
 
 
99
 
  if(bundle->fNumberFormat != 0)
100
 
    unum_close(bundle->fNumberFormat);
101
 
  if(bundle->fPercentFormat != 0)
102
 
    unum_close(bundle->fPercentFormat);
103
 
  if(bundle->fCurrencyFormat != 0)
104
 
    unum_close(bundle->fCurrencyFormat);
105
 
  if(bundle->fScientificFormat != 0)
106
 
    unum_close(bundle->fScientificFormat);
107
 
  if(bundle->fSpelloutFormat != 0)
108
 
    unum_close(bundle->fSpelloutFormat);
109
 
  if(bundle->fDateFormat != 0)
110
 
    udat_close(bundle->fDateFormat);
111
 
  if(bundle->fTimeFormat != 0)
112
 
    udat_close(bundle->fTimeFormat);
113
 
 
114
 
  uprv_free(bundle);
115
 
}
116
 
 
117
 
UNumberFormat*        
118
 
u_locbund_getNumberFormat(ULocaleBundle *bundle)
119
 
{
120
 
  UErrorCode status = U_ZERO_ERROR;
121
 
  
122
 
  if(bundle->fNumberFormat == 0) {
123
 
    bundle->fNumberFormat = unum_open(UNUM_DEFAULT, NULL,0,bundle->fLocale,NULL, &status);
124
 
    if(U_FAILURE(status))
125
 
      return 0;
126
 
  }
127
 
  
128
 
  return bundle->fNumberFormat;
129
 
}
130
 
 
131
 
UNumberFormat*    
132
 
u_locbund_getPercentFormat(ULocaleBundle *bundle)
133
 
{
134
 
  UErrorCode status = U_ZERO_ERROR;
135
 
  
136
 
  if(bundle->fPercentFormat == 0) {
137
 
    bundle->fPercentFormat = unum_open(UNUM_PERCENT,NULL,0, bundle->fLocale,NULL, &status);
138
 
    if(U_FAILURE(status))
139
 
      return 0;
140
 
  }
141
 
  
142
 
  return bundle->fPercentFormat;
143
 
}
144
 
 
145
 
UNumberFormat*    
146
 
u_locbund_getCurrencyFormat(ULocaleBundle *bundle)
147
 
{
148
 
  UErrorCode status = U_ZERO_ERROR;
149
 
  
150
 
  if(bundle->fCurrencyFormat == 0) {
151
 
    bundle->fCurrencyFormat = unum_open(UNUM_CURRENCY,NULL,0, bundle->fLocale, NULL,&status);
152
 
    if(U_FAILURE(status))
153
 
      return 0;
154
 
  }
155
 
  
156
 
  return bundle->fCurrencyFormat;
157
 
}
158
 
 
159
 
#define PAT_SIZE 512
160
 
 
161
 
UNumberFormat*    
162
 
u_locbund_getScientificFormat(ULocaleBundle *bundle)
163
 
{
164
 
  UErrorCode status = U_ZERO_ERROR;
165
 
/*  UChar pattern [PAT_SIZE];*/
166
 
 
167
 
  if(bundle->fScientificFormat == 0) {
168
 
    /* create the pattern for the locale */
169
 
/*    u_uastrcpy(pattern, "0.000000E000");*/
170
 
    
171
 
    bundle->fScientificFormat = unum_open(UNUM_SCIENTIFIC, NULL, 0,
172
 
                         bundle->fLocale, NULL,&status);
173
 
    
174
 
    if(U_FAILURE(status))
175
 
      return 0;
176
 
  }
177
 
  
178
 
  return bundle->fScientificFormat;
179
 
}
180
 
 
181
 
UNumberFormat*
182
 
u_locbund_getSpelloutFormat(ULocaleBundle *bundle)
183
 
{
184
 
  UErrorCode status = U_ZERO_ERROR;
185
 
  
186
 
  if(bundle->fSpelloutFormat == 0) {
187
 
    bundle->fSpelloutFormat = unum_open(UNUM_SPELLOUT,NULL,0 ,bundle->fLocale, NULL,
188
 
                    &status);
189
 
  }
190
 
  
191
 
  return bundle->fSpelloutFormat;
192
 
}
193
 
 
194
 
UDateFormat*
195
 
u_locbund_getDateFormat(ULocaleBundle *bundle)
196
 
{
197
 
  UErrorCode status = U_ZERO_ERROR;
198
 
  
199
 
  if(bundle->fDateFormat == 0) {
200
 
    bundle->fDateFormat = udat_open(UDAT_NONE, UDAT_DEFAULT, 
201
 
                    bundle->fLocale, 0, 0,NULL,0, &status);
202
 
  }
203
 
  
204
 
  return bundle->fDateFormat;
205
 
}
206
 
 
207
 
UDateFormat*
208
 
u_locbund_getTimeFormat(ULocaleBundle *bundle)
209
 
{
210
 
  UErrorCode status = U_ZERO_ERROR;
211
 
  
212
 
  if(bundle->fTimeFormat == 0) {
213
 
    bundle->fTimeFormat = udat_open(UDAT_DEFAULT, UDAT_NONE, 
214
 
                    bundle->fLocale, 0, 0,NULL,0, &status);
215
 
  }
216
 
 
217
 
  return bundle->fTimeFormat;
218
 
}