Fix prevent issue
[platform/framework/native/appfw.git] / src / locales / FLcl_LocaleData.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file        FLclLocaleData.cpp
19  * @brief       This is the implementation file for _LocaleData class.
20  */
21
22 // Includes
23 #include <locale.h>
24 #include <memory>
25 #include <stdlib.h>
26 #include <unistd.h>
27 #include <limits.h>
28 #include <runtime_info.h>
29 #include <unique_ptr.h>
30 #include <FBaseSysLog.h>
31 #include <FSysSettingInfo.h>
32 #include <FLclNumberSymbols.h>
33 #include <FApp_AppInfo.h>
34 #include "FBase_StringConverter.h"
35 #include "FLcl_CalendarImpl.h"
36 #include "FLcl_IcuCalendarImpl.h"
37 #include "FLcl_LocaleData.h"
38 #include "FLcl_LocaleImpl.h"
39
40
41 // Other defines
42 #define LOCALE_DATA_NUM_OF_MILLISEC_IN_HOUR 3600000LL   // number of mili second in a hour
43 #define LOCALE_DATA_NUM_OF_MILLISEC_IN_MINUTE 60000LL   // number of mili second in a minute
44
45 using namespace Tizen::Base;
46 using namespace Tizen::Base::Collection;
47 using namespace Tizen::Base::Utility;
48
49 namespace Tizen { namespace Locales
50 {
51
52 /////////////////////////////////////////////////////////////////////////////////////////////////////
53 // Public Method
54
55 // this function is to convert ICU FieldPosition from OSP _FieldPosition
56 IcuFieldPosition
57 _LocaleData::GetIcuFieldPosition(_FieldPosition pos)
58 {
59         IcuFieldPosition icuPos(pos.GetField());            // Create IcuFieldPosition with field value in pos
60         icuPos.setBeginIndex(pos.GetBeginIndex());          // Set Beginning index
61         icuPos.setEndIndex(pos.GetEndIndex());              // Set End index
62         return icuPos;
63 }
64
65 U_ICU_NAMESPACE::UnicodeString
66 _LocaleData::GetIcuString(const String& ospStr)
67 {
68         IcuUnicodeString icuStr;
69
70         if (!ospStr.IsEmpty())                                                     // if ospStr is not empty
71         {
72                 ByteBuffer* pBuff = null;
73                 pBuff = StringUtil::StringToUtf8N(ospStr);                             // Convert unicode value to UTF8
74                 if (pBuff)
75                 {
76                         icuStr = IcuUnicodeString((const char*) pBuff->GetPointer());        // Create ICU string using UTF8 array
77                         icuStr.setCharAt(0, icuStr.charAt(0));                              // This is to handle ICU copy on write design
78                         delete pBuff;                                                       // delete temporary buffer
79                 }
80         }
81
82         return icuStr;
83 }
84
85 // This function convert ICU string to OSP string
86 String
87 _LocaleData::GetOspString(const IcuUnicodeString& icuStr)
88 {
89         int len = icuStr.length();                                  // get length
90         if (len > 0)                                                    // if icuStr is not empty
91         {
92                 wchar_t wstr[len + 1];
93                 IcuUnicodeString tmpIcuStr(icuStr);
94                 for (int i = 0; i < len ; i++)
95                 {
96                         UChar icuChar;
97                         icuChar = tmpIcuStr.charAt(i);
98                         wstr[i] = (wchar_t)icuChar;
99                 }
100                 wstr[len] = 0;
101                 return String(wstr);
102         }
103         return String("");
104 }
105
106 // This convert OSP string to ICU strings
107 void
108 _LocaleData::GetIcuString(const String& ospStr, IcuUnicodeString& icuStr)
109 {
110         if (!ospStr.IsEmpty())                                                     // if ospStr is not empty
111         {
112                 ByteBuffer* pBuff = null;
113                 pBuff = StringUtil::StringToUtf8N(ospStr);                             // Convert unicode value to UTF8
114                 if (pBuff)
115                 {
116                         icuStr = IcuUnicodeString((const char*) pBuff->GetPointer());        // Create ICU string using UTF8 array
117                         icuStr.setCharAt(0, icuStr.charAt(0));                              // This is to handle ICU copy on write design
118                         delete pBuff;                                                       // delete temporary buffer
119                 }
120         }
121
122 //      return icuStr;
123 }
124
125 // This function return OSP array list of OSP string from ICU string list
126 ArrayList*
127 _LocaleData::ConvertIcuStringArrayToOspArrayN(const IcuUnicodeString* pIcuStrList, int count)
128 {
129         SysTryReturn(NID_LCL, pIcuStrList && count > 0, null, E_INVALID_ARG, "It is invalid argument.");
130         
131         result r = E_SUCCESS;
132         std::unique_ptr< ArrayList> pTempArrayList(new (std::nothrow) ArrayList(SingleObjectDeleter));
133         SysTryReturn(NID_LCL, pTempArrayList, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
134         pTempArrayList->Construct(count);
135         
136         for (int i = 0; i < count; i++)
137         {
138                 std::unique_ptr< String > pString(new (std::nothrow) String(_LocaleData::GetOspString(pIcuStrList[i])));
139                 SysTryReturn(NID_LCL, pString, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
140
141                 if (!pString->IsEmpty())
142                 {
143                         r = pTempArrayList->Add(pString.get());                    // Add OSP string to arraylist if it is not empty
144                         SysTryReturn(NID_LCL, !IsFailed(r), null, E_SYSTEM, "It is failed to add string [%ls]", pString->GetPointer());
145                         pString.release();
146                 }
147         }
148
149         SetLastResult(r);                                                           // Setting last result value
150         return pTempArrayList.release();                                                      // Return array list
151 }
152
153 IcuUnicodeString*
154 _LocaleData::ConvertOspArrayToIcuStringArrayN(const Tizen::Base::Collection::IList* pIcuStrList, int& count)
155 {
156         count = 0;
157         SysTryReturn(NID_LCL, pIcuStrList, null, E_INVALID_ARG, "[%s] Invalid argument is used. pIcuStrList is null.", GetErrorMessage(E_INVALID_ARG));
158
159         count = pIcuStrList->GetCount();
160         SysTryReturn(NID_LCL, count > 0, null, E_INVALID_ARG, "The list is empty.");
161
162         std::unique_ptr< IcuUnicodeString[] > pIcuStrArray(new IcuUnicodeString[count]);
163         SysTryReturn(NID_LCL, pIcuStrArray, null, E_OUT_OF_MEMORY, "It is not enough memory.");
164
165         std::unique_ptr< IEnumerator > pEnum(pIcuStrList->GetEnumeratorN());
166         SysTryReturn(NID_LCL, pEnum, null, E_SYSTEM, "It is failed to get enumerator.");
167
168         int i = 0;
169         String* pObj = null;
170         while (pEnum->MoveNext() == E_SUCCESS)
171         {
172                 pObj = static_cast< String* >(pEnum->GetCurrent());
173                 if (pObj)
174                 {
175                         GetIcuString(*pObj, pIcuStrArray[i]);
176                         i++;
177                 }
178         }
179         return pIcuStrArray.release();
180 }
181
182
183 IcuLocale
184 _LocaleData::GetIcuLocale(const Locale& ospLocale)
185 {
186         ClearLastResult();
187         String language = ospLocale.GetLanguageCodeString();
188         String country = ospLocale.GetCountryCodeString();
189         String variant = ospLocale.GetVariantCodeString();
190
191         const char* pLangStr = _StringConverter::CopyToCharArrayN(language);
192         const char* pCountryStr = _StringConverter::CopyToCharArrayN(country);
193         const char* pVariantStr = null;
194
195         if (!variant.IsEmpty())
196         {
197                 pVariantStr = _StringConverter::CopyToCharArrayN(variant);
198         }
199
200         IcuLocale icuLocale = IcuLocale(pLangStr, pCountryStr, pVariantStr);
201
202         delete[] pLangStr;
203         delete[] pCountryStr;
204         delete[] pVariantStr;
205
206         if (icuLocale.isBogus())
207         {
208                 SetLastResult(E_SYSTEM);
209         }
210
211         return icuLocale;
212 }
213
214
215 const IcuLocale&
216 _LocaleData::GetIcuLocale(void)
217 {
218         return __icuLocale;
219 }
220
221 bool
222 _LocaleData::IsLocaleSupported(void)
223 {
224         return !__icuLocale.isBogus();
225 }
226
227 result
228 _LocaleData::SetLocale(const Locale& ospLocale)
229 {
230         if (_LocaleImpl::IsSupported(ospLocale))
231     {
232         __icuLocale = GetIcuLocale(ospLocale);
233         return E_SUCCESS;
234     }
235
236         __icuLocale.setToBogus();
237         return (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat()) ? E_UNSUPPORTED_OPERATION : E_INVALID_ARG;
238 }
239
240 result
241 _LocaleData::GetNumberSymbols(const Locale& locale, String symbols[])
242 {
243         UErrorCode status = U_ZERO_ERROR;
244         ;
245         SetLocale(locale);
246
247         SysTryReturnResult(NID_LCL, IsLocaleSupported(), E_SYSTEM, "A System error has been occurred. Locale is not supported");
248
249         IcuDecimalFormatSymbols sym(__icuLocale, status);
250         SysTryReturnResult(NID_LCL, U_SUCCESS(status),  E_SYSTEM, "A System error has been occurred. Unable to get ICU Decimal Format Symbols");
251
252         symbols[NUMBER_SYMBOL_DECIMAL_SEPARATOR] = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kDecimalSeparatorSymbol));
253         symbols[NUMBER_SYMBOL_GROUPING_SEPARATOR] = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kGroupingSeparatorSymbol));
254         symbols[NUMBER_SYMBOL_PATTERN_SEPARATOR] = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kPatternSeparatorSymbol));
255         symbols[NUMBER_SYMBOL_PERCENT] = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kPercentSymbol));
256         symbols[NUMBER_SYMBOL_ZERO_DIGIT] = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kZeroDigitSymbol));
257         symbols[NUMBER_SYMBOL_DIGIT] = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kDigitSymbol));
258         symbols[NUMBER_SYMBOL_CURRENCY] = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kCurrencySymbol));
259         symbols[NUMBER_SYMBOL_INTL_CURRENCY] = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kIntlCurrencySymbol));
260         symbols[NUMBER_SYMBOL_MONETARY_SEPARATOR] = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kMonetarySeparatorSymbol));
261         symbols[NUMBER_SYMBOL_PER_MILL] = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kPerMillSymbol));
262         symbols[NUMBER_SYMBOL_EXPONENTIAL] = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kExponentialSymbol));
263         symbols[NUMBER_SYMBOL_PLUS_SIGN] = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kPlusSignSymbol));
264         symbols[NUMBER_SYMBOL_MINUS_SIGN] = _LocaleData::GetOspString(sym.getSymbol(IcuDecimalFormatSymbols::kMinusSignSymbol));
265
266         return E_SUCCESS;
267 }
268
269 result
270 _LocaleData::SetNumberFormatter(const Locale& locale, NumberFormatterStyle style)
271 {
272         if (__pIcuNumberFormatter)
273         {
274                 delete __pIcuNumberFormatter;
275                 __pIcuNumberFormatter = null;
276         }
277
278         IcuNumberFormat* pNumFmt = null;
279         UErrorCode ec = U_ZERO_ERROR;
280         result r = SetLocale(locale);
281
282         if (!IsFailed(r))
283         {
284                 switch (style)
285                 {
286                 case NUM_FORMATTER_STYLE_NUMBER:
287                 {
288                         pNumFmt = IcuNumberFormat::createInstance(__icuLocale, ec);
289                         break;
290                 }
291
292                 case NUM_FORMATTER_STYLE_CURRENCY:
293                 {
294                         pNumFmt = IcuNumberFormat::createCurrencyInstance(__icuLocale, ec);
295                         break;
296                 }
297
298                 case NUM_FORMATTER_STYLE_PERCENT:
299                 {
300                         pNumFmt = IcuNumberFormat::createPercentInstance(__icuLocale, ec);
301                         break;
302                 }
303
304                 default:
305                 {
306                         r = E_UNSUPPORTED_OPERATION;
307                         break;
308                 }
309                 }
310
311                 if (IsFailed(r))
312                 {
313                         return r;
314                 }
315
316                 if (U_SUCCESS(ec))
317                 {
318                         if (pNumFmt && (pNumFmt->getDynamicClassID() == IcuDecimalFormat::getStaticClassID()))
319                         {
320                                 __pIcuNumberFormatter = dynamic_cast< IcuDecimalFormat* >(pNumFmt);
321                                 if (__pIcuNumberFormatter)
322                                 {
323                                         return E_SUCCESS;
324                                 }
325                         }
326                 }
327         }
328
329         return E_UNSUPPORTED_OPERATION;
330 }
331
332 result
333 _LocaleData::FormatNumber(long number, _FieldPosition& pos, Tizen::Base::String& str)
334 {
335         str = "";
336
337         if (__pIcuNumberFormatter)
338         {
339                 IcuUnicodeString icuStr;
340                 IcuFieldPosition icuPos = GetIcuFieldPosition(pos);
341                 icuStr = __pIcuNumberFormatter->format(static_cast< int32_t >(number), icuStr, icuPos);
342
343                 str = _LocaleData::GetOspString(icuStr);
344                 return E_SUCCESS;
345         }
346
347         return E_SYSTEM;
348 }
349
350 result
351 _LocaleData::FormatNumber(double number, _FieldPosition& pos, Tizen::Base::String& str)
352 {
353         str = "";
354
355         if (__pIcuNumberFormatter)
356         {
357                 IcuUnicodeString icuStr;
358                 IcuFieldPosition icuPos = GetIcuFieldPosition(pos);
359                 icuStr = __pIcuNumberFormatter->format(number, icuStr, icuPos);
360
361                 str = _LocaleData::GetOspString(icuStr);
362                 return E_SUCCESS;
363         }
364
365         return E_SYSTEM;
366 }
367
368 result
369 _LocaleData::ApplyNumberPattern(const Tizen::Base::String& pattern, bool localized)
370 {
371         if (__pIcuNumberFormatter)
372         {
373                 IcuUnicodeString icuPattern;
374                 icuPattern = __pIcuNumberFormatter->toPattern(icuPattern);
375
376                 UErrorCode ec = U_ZERO_ERROR;
377                 IcuUParseError parseError = {0,};
378                 IcuUnicodeString icuNewPatter;
379                 GetIcuString(pattern, icuNewPatter);
380
381                 if (localized)
382                 {
383                         __pIcuNumberFormatter->applyLocalizedPattern(icuNewPatter, parseError, ec);
384                 }
385                 else
386                 {
387                         __pIcuNumberFormatter->applyPattern(icuNewPatter, parseError, ec);
388                 }
389
390                 if (U_SUCCESS(ec))
391                 {
392                         return E_SUCCESS;
393                 }
394                 else
395                 {
396                         SysLog(NID_LCL, "Error [%d -> %s] in setting pattern to %ls at %d:%d",
397                                    ec, u_errorName(ec), pattern.GetPointer(), parseError.line, parseError.offset);
398
399                         __pIcuNumberFormatter->applyPattern(icuPattern, ec);
400                 }
401         }
402
403         return E_INVALID_ARG;
404 }
405
406 String
407 _LocaleData::GetNumberFormatterStringAttributes(NumberFormatterAttributes attrName)
408 {
409         IcuUnicodeString icuRetValue;
410
411         if (__pIcuNumberFormatter)
412         {
413                 switch (attrName)
414                 {
415                 case NUM_FORMATTER_FIELD_CURRENCY:
416                 {
417                         icuRetValue = __pIcuNumberFormatter->getCurrency();
418                         break;
419                 }
420
421                 case NUM_FORMATTER_FIELD_POSITIVE_PREFIX:
422                 {
423                         icuRetValue = __pIcuNumberFormatter->getPositivePrefix(icuRetValue);
424                         break;
425                 }
426
427                 case NUM_FORMATTER_FIELD_NEGATIVE_PREFIX:
428                 {
429                         icuRetValue = __pIcuNumberFormatter->getNegativePrefix(icuRetValue);
430                         break;
431                 }
432
433                 case NUM_FORMATTER_FIELD_POSITIVE_SUFFIX:
434                 {
435                         icuRetValue = __pIcuNumberFormatter->getPositiveSuffix(icuRetValue);
436                         break;
437                 }
438
439                 case NUM_FORMATTER_FIELD_NEGATIVE_SUFFIX:
440                 {
441                         icuRetValue = __pIcuNumberFormatter->getNegativeSuffix(icuRetValue);
442                         break;
443                 }
444
445                 case NUM_FORMATTER_FIELD_PATTERN:
446                 {
447                         icuRetValue = __pIcuNumberFormatter->toPattern(icuRetValue);
448                         break;
449                 }
450
451                 case NUM_FORMATTER_FIELD_LOCALIZED_PATTERN:
452                 {
453                         icuRetValue = __pIcuNumberFormatter->toLocalizedPattern(icuRetValue);
454                         break;
455                 }
456
457                 default:
458                 {
459                         break;
460                 }
461                 }
462
463                 return _LocaleData::GetOspString(icuRetValue);
464         }
465
466         return Tizen::Base::String("");
467 }
468
469 void
470 _LocaleData::SetNumberFormatterAttributes(const String& newValue, NumberFormatterAttributes attrName)
471 {
472         if (__pIcuNumberFormatter)
473         {
474                 IcuUnicodeString icuNewValue;
475                 GetIcuString(newValue, icuNewValue);
476
477                 switch (attrName)
478                 {
479                 case NUM_FORMATTER_FIELD_CURRENCY:
480                 {
481                         __pIcuNumberFormatter->setCurrency(icuNewValue.getTerminatedBuffer());
482                         break;
483                 }
484
485                 case NUM_FORMATTER_FIELD_POSITIVE_PREFIX:
486                 {
487                         __pIcuNumberFormatter->setPositivePrefix(icuNewValue);
488                         break;
489                 }
490
491                 case NUM_FORMATTER_FIELD_NEGATIVE_PREFIX:
492                 {
493                         __pIcuNumberFormatter->setNegativePrefix(icuNewValue);
494                         break;
495                 }
496
497                 case NUM_FORMATTER_FIELD_POSITIVE_SUFFIX:
498                 {
499                         __pIcuNumberFormatter->setPositiveSuffix(icuNewValue);
500                         break;
501                 }
502
503                 case NUM_FORMATTER_FIELD_NEGATIVE_SUFFIX:
504                 {
505                         __pIcuNumberFormatter->setNegativeSuffix(icuNewValue);
506                         break;
507                 }
508
509                 default:
510                 {
511                         break;
512                 }
513                 }
514         }
515 }
516
517 int
518 _LocaleData::GetNumberFormatterIntAttributes(NumberFormatterAttributes attrName)
519 {
520         int res = 0;
521         if (__pIcuNumberFormatter)
522         {
523                 switch (attrName)
524                 {
525                 case NUM_FORMATTER_FIELD_MAX_INTEGER_DIGITS:
526                 {
527                         res = __pIcuNumberFormatter->getMaximumIntegerDigits();
528                         break;
529                 }
530
531                 case NUM_FORMATTER_FIELD_MIN_INTEGER_DIGITS:
532                 {
533                         res = __pIcuNumberFormatter->getMinimumIntegerDigits();
534                         break;
535                 }
536
537                 case NUM_FORMATTER_FIELD_MAX_FRACTION_DIGITS:
538                 {
539                         res = __pIcuNumberFormatter->getMaximumFractionDigits();
540                         break;
541                 }
542
543                 case NUM_FORMATTER_FIELD_MIN_FRACTION_DIGITS:
544                 {
545                         res = __pIcuNumberFormatter->getMinimumFractionDigits();
546                         break;
547                 }
548
549                 case NUM_FORMATTER_FIELD_MIN_EXPONENT_DIGITS:
550                 {
551                         res = __pIcuNumberFormatter->getMinimumExponentDigits();
552                         break;
553                 }
554
555                 case NUM_FORMATTER_FIELD_MULTIPLIER:
556                 {
557                         res = __pIcuNumberFormatter->getMultiplier();
558                         break;
559                 }
560
561                 case NUM_FORMATTER_FIELD_GROUPING_SIZE:
562                 {
563                         res = __pIcuNumberFormatter->getGroupingSize();
564                         break;
565                 }
566
567                 default:
568                 {
569                         res = 0;
570                         break;
571                 }
572                 }
573         }
574
575         return res;
576 }
577
578 void
579 _LocaleData::SetNumberFormatterAttributes(const int newValue, NumberFormatterAttributes attrName)
580 {
581         if (__pIcuNumberFormatter)
582         {
583                 switch (attrName)
584                 {
585                 case NUM_FORMATTER_FIELD_MAX_INTEGER_DIGITS:
586                 {
587                         __pIcuNumberFormatter->setMaximumIntegerDigits(newValue);
588                         break;
589                 }
590
591                 case NUM_FORMATTER_FIELD_MIN_INTEGER_DIGITS:
592                 {
593                         __pIcuNumberFormatter->setMinimumIntegerDigits(newValue);
594                         break;
595                 }
596
597                 case NUM_FORMATTER_FIELD_MAX_FRACTION_DIGITS:
598                 {
599                         __pIcuNumberFormatter->setMaximumFractionDigits(newValue);
600                         break;
601                 }
602
603                 case NUM_FORMATTER_FIELD_MIN_FRACTION_DIGITS:
604                 {
605                         __pIcuNumberFormatter->setMinimumFractionDigits(newValue);
606                         break;
607                 }
608
609                 case NUM_FORMATTER_FIELD_MIN_EXPONENT_DIGITS:
610                 {
611                         __pIcuNumberFormatter->setMinimumExponentDigits(newValue);
612                         break;
613                 }
614
615                 case NUM_FORMATTER_FIELD_MULTIPLIER:
616                 {
617                         __pIcuNumberFormatter->setMultiplier(newValue);
618                         break;
619                 }
620
621                 case NUM_FORMATTER_FIELD_GROUPING_SIZE:
622                 {
623                         __pIcuNumberFormatter->setGroupingSize(newValue);
624                         break;
625                 }
626
627                 default:
628                 {
629                         break;
630                 }
631                 }
632         }
633 }
634
635 bool
636 _LocaleData::GetNumberFormatterBoolAttributes(NumberFormatterAttributes attrName)
637 {
638         bool res = false;
639         if (__pIcuNumberFormatter)
640         {
641                 switch (attrName)
642                 {
643                 case NUM_FORMATTER_FIELD_IS_GROUPING_USED:
644                 {
645                         res = __pIcuNumberFormatter->isGroupingUsed();
646                         break;
647                 }
648
649                 case NUM_FORMATTER_FIELD_IS_DECIMAL_SEPARATOR_ALWAYS_SHOWN:
650                 {
651                         res = __pIcuNumberFormatter->isDecimalSeparatorAlwaysShown();
652                         break;
653                 }
654
655                 case NUM_FORMATTER_FIELD_IS_POSITIVE_SIGN_ALWAYS_SHOWN:
656                 {
657                         IcuUnicodeString ps("+");
658                         IcuUnicodeString pp;
659                         pp = __pIcuNumberFormatter->getPositivePrefix(pp);
660
661                         res = (pp == ps);
662                         break;
663                 }
664
665                 default:
666                 {
667                         res = false;
668                         break;
669                 }
670                 }
671         }
672
673         return res;
674 }
675
676 void
677 _LocaleData::SetNumberFormatterAttributes(const bool newValue, NumberFormatterAttributes attrName)
678 {
679         if (__pIcuNumberFormatter)
680         {
681                 switch (attrName)
682                 {
683                 case NUM_FORMATTER_FIELD_IS_GROUPING_USED:
684                 {
685                         __pIcuNumberFormatter->setGroupingUsed(newValue);
686                         break;
687                 }
688
689                 case NUM_FORMATTER_FIELD_IS_DECIMAL_SEPARATOR_ALWAYS_SHOWN:
690                 {
691                         __pIcuNumberFormatter->setDecimalSeparatorAlwaysShown(newValue);
692                         break;
693                 }
694
695                 case NUM_FORMATTER_FIELD_IS_POSITIVE_SIGN_ALWAYS_SHOWN:
696                 {
697                         IcuUnicodeString ps("+");
698                         IcuUnicodeString pp;
699                         pp = __pIcuNumberFormatter->getPositivePrefix(pp);
700
701                         if (newValue)
702                         {
703                                 __pIcuNumberFormatter->setPositivePrefix(ps);
704                         }
705                         else
706                         {
707                                 if (pp == ps)
708                                 {
709                                         __pIcuNumberFormatter->setPositivePrefix("");
710                                 }
711                         }
712                         break;
713                 }
714
715                 default:
716                 {
717                         break;
718                 }
719                 }
720         }
721 }
722
723
724 IcuUDate
725 _LocaleData::GetIcuDate(DateTime date)
726 {
727         DateTime icuBaseTime;
728         icuBaseTime.SetValue(1970, 1, 1);
729         DateTime ospBaseTime = DateTime::GetMinValue();
730
731         result r = icuBaseTime.Subtract(ospBaseTime.GetTime());
732         if (r != E_SUCCESS)
733         {
734                 SysLogException(NID_LCL, r, "[%s] Propagated.", GetErrorMessage(r));
735         }
736
737         TimeSpan tsIcu = icuBaseTime.GetTime();
738         TimeSpan tsOsp = date.GetTime();
739         TimeSpan diff = tsOsp - tsIcu;
740
741         IcuUDate icuDate = diff.GetTicks();
742         return icuDate;
743 }
744
745 _LocaleData::_LocaleData(void)
746         : __icuLocale()
747         , __pIcuNumberFormatter(null)
748 {
749 }
750
751
752 _LocaleData::~_LocaleData(void)
753 {
754         if (__pIcuNumberFormatter)                                                     // Delete __pIcuNumberFormatter and set to null
755         {
756                 delete __pIcuNumberFormatter;
757                 __pIcuNumberFormatter = null;
758         }
759 }
760
761
762 };
763 };      // Tizen::Locales
764