sync with tizen_2.0
[platform/framework/native/appfw.git] / src / locales / FLcl_DateTimeSymbolsImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        FLcl_DateTimeSymbolsImpl.cpp
20  * @brief       This is the implementation file for _DateTimeSymbolsImpl class.
21  */
22
23 #include <unique_ptr.h>
24
25 #include <FBaseSysLog.h>
26 #include <FLclDateTimeSymbols.h>
27 #include "FLcl_DateTimeSymbolsImpl.h"
28 #include "FLcl_LocaleData.h"
29
30
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33 using namespace Tizen::Base::Utility;
34
35 namespace Tizen { namespace Locales
36 {
37
38 // This will be used to define non localized pattern string.
39 static const wchar_t PATTERN_CHARS[] =
40 {
41         // GyMdkHmsSEDFwWahKzYeugAZ
42         0x47, 0x79, 0x4D, 0x64, 0x6B, 0x48, 0x6D, 0x73, 0x53, 0x45, 0x44,
43         0x46, 0x77, 0x57, 0x61, 0x68, 0x4B, 0x7A, 0x59, 0x65, 0x75, 0x67,
44         0x41, 0x5A, 0    // Should be ended with 0 as we are not setting null at the end of the pattern
45 };
46
47 static const int PATTERN_LENGTH = 24 + 1;       // 24 Char and one null (0)
48
49 static const int ERAS_COUNT = 2;
50 static const int MONTH_COUNT = 12;
51 static const int WEEKDAYS_COUNT = 7;
52 static const int AM_PM_COUNT =2;
53
54 static const int MAX_TIMEZONE_NAME = 4;
55
56 WcharBuffer*
57 _DateTimeSymbolsImpl::GetNonLocalizedDateTimePatternN(void)
58 {
59         ClearLastResult();
60         std::unique_ptr< WcharBuffer > pChars(new (std::nothrow) WcharBuffer());
61         SysTryReturn(NID_TEXT, pChars, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
62
63         result r = pChars->Construct(PATTERN_LENGTH);
64         SysTryCatch(NID_LCL, r == E_SUCCESS, , r, "[%s] Propagated.", GetErrorMessage(r));
65
66         r = pChars->SetArray(PATTERN_CHARS, 0, PATTERN_LENGTH);     // Setting value from PATTERN_CHARS defined above
67         SysTryCatch(NID_LCL, r == E_SUCCESS, , r, "[%s] Propagated.", GetErrorMessage(r));
68
69         pChars->Flip();
70         return pChars.release();
71
72 CATCH:
73         return null;
74 }
75
76 _DateTimeSymbolsImpl::_DateTimeSymbolsImpl(void)
77         : __pErasList(null)
78         , __pMonthsList(null)
79         , __pShortMonthsList(null)
80         , __pWeekdaysList(null)
81         , __pShortWeekdaysList(null)
82         , __pAmPmList(null)
83         , __pTimeZonesMap(null)
84         , __CalendarType(CALENDAR_GREGORIAN)
85         , __pIcuDateFormatSymbols(null)
86 {
87 }
88
89 _DateTimeSymbolsImpl::~_DateTimeSymbolsImpl(void)
90 {
91         ReleaseAll();
92         if (__pIcuDateFormatSymbols)
93         {
94                 delete __pIcuDateFormatSymbols;
95         }
96 }
97
98 result
99 _DateTimeSymbolsImpl::Initialize(CalendarType calendarType)
100 {
101         return Initialize(_LocaleData::GetOspSystemLocale(), calendarType);
102 }
103
104 result
105 _DateTimeSymbolsImpl::Initialize(const Locale& locale, CalendarType calendarType)
106 {
107         SysTryReturnResult(NID_LCL, locale.GetCountryCode() != COUNTRY_INVALID, E_INVALID_ARG,
108                                 "Invalid argument is used. Country code is invalid. Given locale is not supported");
109         SysTryReturnResult(NID_LCL, locale.GetLanguageCode() != LANGUAGE_INVALID, E_INVALID_ARG,
110                                 "Invalid argument is used. Language code is invalid. Given locale is not supported");
111
112         _LocaleData localeData;
113         result r = localeData.SetDateFormatSymbols(locale);   // this will set ICU DateTimeSymbol in _LocaleData object for future use
114
115         if (!IsFailed(r))
116         {
117                 __pErasList = localeData.GetDateFormatSymbolAttrArrayN(DATE_FORMAT_SYM_ERA_LIST);
118                 __pMonthsList = localeData.GetDateFormatSymbolAttrArrayN(DATE_FORMAT_SYM_MONTH_LIST);
119                 __pShortMonthsList = localeData.GetDateFormatSymbolAttrArrayN(DATE_FORMAT_SYM_SHORT_MONTH_LIST);
120                 __pWeekdaysList = localeData.GetDateFormatSymbolAttrArrayN(DATE_FORMAT_SYM_WEEKDAY_LIST);
121                 __pShortWeekdaysList = localeData.GetDateFormatSymbolAttrArrayN(DATE_FORMAT_SYM_SHORT_WEEKDAY_LIST);
122                 __pAmPmList = localeData.GetDateFormatSymbolAttrArrayN(DATE_FORMAT_SYM_AM_PM_LIST);
123                 __CalendarType = calendarType;
124
125                 UErrorCode ec = U_ZERO_ERROR;
126                 __pIcuDateFormatSymbols = new IcuDateFormatSymbols(ec);
127         }
128
129         return r;
130 }
131
132 void
133 _DateTimeSymbolsImpl::Set(const _DateTimeSymbolsImpl* pOther)
134 {
135         SysTryReturnVoidResult(NID_LCL, pOther != null, E_INVALID_ARG,
136                                 "[%s] Invalid argument is used. pOther instance is invalid", GetErrorMessage(E_INVALID_ARG));
137
138         __pErasList = CloneArrayListN(pOther->__pErasList);                         // Copying EraList
139         __pMonthsList = CloneArrayListN(pOther->__pMonthsList);                     // Copying Month List
140         __pShortMonthsList = CloneArrayListN(pOther->__pShortMonthsList);           // Copying Short Month List
141         __pWeekdaysList = CloneArrayListN(pOther->__pWeekdaysList);                 // Copying Weekdays List
142         __pShortWeekdaysList = CloneArrayListN(pOther->__pShortWeekdaysList);       // Copying Short Weekdays List
143         __pAmPmList = CloneArrayListN(pOther->__pAmPmList);                         // Copying AM/ PM String
144         if(pOther->__pTimeZonesMap)
145         {
146                 __pTimeZonesMap = CloneMultiHashMapN(pOther->__pTimeZonesMap);                   // Copying available TimeZone List
147         }
148         __CalendarType = pOther->__CalendarType;                                    // Copying Calendar Type
149 }
150
151
152 result
153 _DateTimeSymbolsImpl::AddTimeZoneName(const String& timeZoneId, const String& concatenatedTimeZoneName, bool isOverwrite)
154 {
155         StringTokenizer tokenizer(concatenatedTimeZoneName, L"|");
156         SysTryReturnResult(NID_LCL, (tokenizer.GetTokenCount() == MAX_TIMEZONE_NAME),
157                         E_INVALID_ARG, "Invalid argument is used. %ls is invalid.", concatenatedTimeZoneName.GetPointer());
158         result r;
159
160         if (!isOverwrite)
161         {
162                 String tzName(timeZoneId);    
163                 GetTimeZoneName(tzName, 0); 
164
165                 r = GetLastResult();    
166                 SysTryReturnResult(NID_LCL, r != E_SUCCESS, E_OBJ_ALREADY_EXIST, "The timeZoneId already exists.");
167         }
168
169         if (!__pTimeZonesMap)
170         {
171                 MultiHashMap* pMultiHashMap = new (std::nothrow) MultiHashMap();
172                 SysTryReturnResult(NID_LCL, pMultiHashMap, E_OUT_OF_MEMORY, "Memory allocation failed.");
173                 pMultiHashMap->Construct();
174                 
175                 __pTimeZonesMap = (IMultiMap*) pMultiHashMap;
176         }
177
178         String token;
179         std::unique_ptr< String >pKey(new (std::nothrow) String(timeZoneId));
180         SysTryReturnResult(NID_LCL, pKey, E_OUT_OF_MEMORY, "Memory allocation failed");
181
182         r = E_OUT_OF_MEMORY;
183         while (tokenizer.HasMoreTokens())
184         {
185                 tokenizer.GetNextToken(token);
186                 std::unique_ptr< String >pValue(new (std::nothrow)String(token));
187                 if (pValue)
188                 {
189                         r = __pTimeZonesMap->Add(*pKey, *pValue);
190                         if (IsFailed(r))
191                         {
192                                 __pTimeZonesMap->Remove(*pKey,true);
193                                 return E_OUT_OF_MEMORY;
194                         }
195                         pValue.release();
196                 }
197         }
198
199         pKey.release();
200         return r;
201 }
202
203
204 const IList*
205 _DateTimeSymbolsImpl::GetAmPm(void) const
206 {
207         SysAssertf(__pAmPmList != null, "Not yet constructed! Construct() should be called before use");
208
209         ClearLastResult();  // Setting Last result to E_SUCCESS
210         return __pAmPmList;
211 }
212
213
214 result
215 _DateTimeSymbolsImpl::SetAmPm(const String& amPm)
216 {
217         SysAssertf(__pAmPmList != null, "Not yet constructed! Construct() should be called before use");
218
219         std::unique_ptr< ArrayList, AllElementsDeleter > pTempArrayList(new (std::nothrow) ArrayList());
220         SysTryReturnResult(NID_LCL, pTempArrayList != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
221
222         result r = SetList(pTempArrayList.get(), AM_PM_COUNT, amPm);
223         if (!IsFailed(r))
224         {
225                 __pAmPmList->RemoveAll(true);
226                 delete __pAmPmList;
227                 __pAmPmList = pTempArrayList.release();
228         }
229
230         return  r;
231 }
232
233 const IList*
234 _DateTimeSymbolsImpl::GetEras(void) const
235 {
236         SysAssertf(__pErasList != null, "Not yet constructed! Construct() should be called before use");
237         return __pErasList;
238 }
239
240 result
241 _DateTimeSymbolsImpl::SetEras(const String& eras)
242 {
243         SysAssertf(__pErasList != null, "Not yet constructed! Construct() should be called before use");
244
245         std::unique_ptr< ArrayList, AllElementsDeleter > pTempArrayList(new (std::nothrow) ArrayList());
246         SysTryReturnResult(NID_LCL, pTempArrayList != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
247
248         result r = SetList(pTempArrayList.get(), ERAS_COUNT, eras);
249         if (!IsFailed(r))
250         {
251                 __pErasList->RemoveAll(true);
252                 delete __pErasList;
253
254                 __pErasList = pTempArrayList.release();
255         }
256
257         return  r;
258 }
259
260 const IList*
261 _DateTimeSymbolsImpl::GetMonths(void) const
262 {
263         SysAssertf(__pMonthsList != null, "Not yet constructed! Construct() should be called before use");
264
265         ClearLastResult();   // Setting Last result to E_SUCCESS
266         return __pMonthsList;
267 }
268
269 result
270 _DateTimeSymbolsImpl::SetMonths(const String& months)
271 {
272         SysAssertf(__pMonthsList != null, "Not yet constructed! Construct() should be called before use");
273
274         std::unique_ptr< ArrayList, AllElementsDeleter > pTempArrayList(new (std::nothrow) ArrayList());
275         SysTryReturnResult(NID_LCL, pTempArrayList != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
276
277         result r = SetList(pTempArrayList.get(), MONTH_COUNT, months);
278         if (!IsFailed(r))
279         {
280                 __pMonthsList->RemoveAll(true);
281                 delete __pMonthsList;
282
283                 __pMonthsList = pTempArrayList.release();
284         }
285
286         return  r;
287 }
288 const IList*
289 _DateTimeSymbolsImpl::GetShortMonths(void) const
290 {
291         SysAssertf(__pShortMonthsList != null, "Not yet constructed! Construct() should be called before use");
292
293         ClearLastResult();  // Setting Last result to E_SUCCESS
294         return __pShortMonthsList;
295 }
296
297 result
298 _DateTimeSymbolsImpl::SetShortMonths(const String& shortMonths)
299 {
300         SysAssertf(__pShortMonthsList != null, "Not yet constructed! Construct() should be called before use");
301
302         std::unique_ptr< ArrayList, AllElementsDeleter > pTempArrayList(new (std::nothrow) ArrayList());
303         SysTryReturnResult(NID_LCL, pTempArrayList != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
304
305         result r = SetList(pTempArrayList.get(), MONTH_COUNT, shortMonths);
306         if (!IsFailed(r))
307         {
308                 __pShortMonthsList->RemoveAll(true);
309                 delete __pShortMonthsList;
310
311                 __pShortMonthsList = pTempArrayList.release();
312         }
313
314         return  r;
315 }
316
317 const IList*
318 _DateTimeSymbolsImpl::GetWeekdays(void) const
319 {
320         SysAssertf(__pWeekdaysList != null, "Not yet constructed! Construct() should be called before use");
321
322         ClearLastResult();          // Setting Last result to E_SUCCESS
323         return __pWeekdaysList;
324 }
325
326 result
327 _DateTimeSymbolsImpl::SetWeekdays(const String& weekdays)
328 {
329         SysAssertf(__pWeekdaysList != null, "Not yet constructed! Construct() should be called before use");
330
331         std::unique_ptr< ArrayList, AllElementsDeleter > pTempArrayList(new (std::nothrow) ArrayList());
332         SysTryReturnResult(NID_LCL, pTempArrayList != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
333
334         result r = SetList(pTempArrayList.get(), WEEKDAYS_COUNT, weekdays);
335         if (!IsFailed(r))
336         {
337                 __pWeekdaysList->RemoveAll(true);
338                 delete __pWeekdaysList;
339
340                 __pWeekdaysList = pTempArrayList.release();
341         }
342
343         return  r;
344 }
345
346
347 const IList*
348 _DateTimeSymbolsImpl::GetShortWeekdays(void) const
349 {
350         SysAssertf(__pShortWeekdaysList != null, "Not yet constructed! Construct() should be called before use");
351
352         ClearLastResult();          // Setting Last result to E_SUCCESS
353         return __pShortWeekdaysList;
354 }
355
356 result
357 _DateTimeSymbolsImpl::SetShortWeekdays(const String& shortWeekdays)
358 {
359         SysAssertf(__pShortWeekdaysList != null, "Not yet constructed! Construct() should be called before use");
360
361         std::unique_ptr< ArrayList, AllElementsDeleter > pTempArrayList(new (std::nothrow) ArrayList());
362         SysTryReturnResult(NID_LCL, pTempArrayList != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
363
364         result r = SetList(pTempArrayList.get(), WEEKDAYS_COUNT, shortWeekdays);
365         if (!IsFailed(r))
366         {
367                 __pShortWeekdaysList->RemoveAll(true);
368                 delete __pShortWeekdaysList;
369
370                 __pShortWeekdaysList = pTempArrayList.release();
371         }
372
373         return  r;
374 }
375
376
377 String
378 _DateTimeSymbolsImpl::GetTimeZoneName(Tizen::Base::String& timeZoneId, int timeZoneStyle)
379 {
380         SysTryReturn(NID_LCL, timeZoneStyle < MAX_TIMEZONE_NAME, String(), E_INVALID_ARG,
381                         "[%s] Invalid argument is used. timeZoneStyle(%d) is grater than MAX_TIMEZONE_NAME", GetErrorMessage(E_INVALID_ARG), timeZoneStyle);
382
383         ClearLastResult();
384         
385         if (__pTimeZonesMap && __pTimeZonesMap->GetValuesN(timeZoneId))
386         {
387                 std::unique_ptr< IEnumerator >pValueEnum(__pTimeZonesMap->GetValuesN(timeZoneId));
388         
389                 int i = 0;
390                 String timeZoneName;
391                 while(pValueEnum->MoveNext() == E_SUCCESS)
392                 {
393                         if (i++ == timeZoneStyle)
394                         {
395                                 timeZoneName = *(static_cast<String*> (pValueEnum->GetCurrent()));
396                         }
397                 }
398                 SetLastResult(E_SUCCESS);
399                 return timeZoneName;
400         }
401
402         const IcuUnicodeString** pIcuMap = null;
403
404         int rowCount = 0;
405         int columnCount = 0;
406
407         pIcuMap = __pIcuDateFormatSymbols->getZoneStrings(rowCount, columnCount);
408         if (pIcuMap && rowCount && columnCount)
409         {
410                 for (int rc = 0; rc < rowCount; rc++)
411                 {
412                         if (timeZoneId == _LocaleData::GetOspString(pIcuMap[rc][0]))
413                         {
414                                 SetLastResult(E_SUCCESS);
415                                 return _LocaleData::GetOspString(pIcuMap[rc][timeZoneStyle+1]);
416                         }                       
417                 }               
418         }
419         SetLastResult(E_OBJ_NOT_FOUND);
420         return String();
421 }
422
423 result
424 _DateTimeSymbolsImpl::SetTimeZoneName(const Tizen::Base::String& timeZoneId, const Tizen::Base::String& concatenatedTimeZoneName)
425 {
426         // checking if concatenatedTimeZoneName has 4 names
427         StringTokenizer tokenizer(concatenatedTimeZoneName, L"|");
428         SysTryReturnResult(NID_LCL, (tokenizer.GetTokenCount() == MAX_TIMEZONE_NAME),
429                         E_INVALID_ARG, "Invalid argument is used. %ls is invalid.", concatenatedTimeZoneName.GetPointer());
430
431         if (__pTimeZonesMap)
432         {
433                 bool check = true;
434                 __pTimeZonesMap->ContainsKey(timeZoneId, check);                           // checking if Time zone is already exist
435                 
436                 if (check)
437                 {
438                         __pTimeZonesMap->Remove(timeZoneId, true);
439                         return AddTimeZoneName(timeZoneId, concatenatedTimeZoneName, true);
440                 }
441         }
442         
443         String tzName(timeZoneId);      
444         GetTimeZoneName(tzName, 0);
445         
446         result r = GetLastResult();     
447         
448         if(!IsFailed(r))
449         {
450                 return AddTimeZoneName(timeZoneId, concatenatedTimeZoneName, true);
451         }
452         return E_OBJ_NOT_FOUND;
453 }
454
455
456 // internal function
457 // This function makes a copy of input array list of strings
458 IList*
459 _DateTimeSymbolsImpl::CloneArrayListN(const IList* pList) const
460 {
461         SysTryReturn(NID_LCL, pList, null, E_INVALID_ARG, "[%s] Invalid argument is used. pList is Null", GetErrorMessage(E_INVALID_ARG));
462
463         ClearLastResult();  // Setting last result to E_SUCCESS
464         std::unique_ptr< ArrayList, AllElementsDeleter > pClonedArrayList(new (std::nothrow) ArrayList());
465         SysTryReturn(NID_LCL, pClonedArrayList, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
466
467         result r = pClonedArrayList->Construct(pList->GetCount());
468         SysTryReturn(NID_LCL, !IsFailed(r), null, r, "[%s] Unable to construct ArrayList.", GetErrorMessage(r));
469
470         for (int i = 0; i < pList->GetCount(); i++)
471         {
472                 std::unique_ptr< String > pClonedString(new (std::nothrow) String(*(static_cast<const String*>(pList->GetAt(i)))));
473                 SysTryReturn(NID_LCL, pClonedString, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
474
475                 r = pClonedArrayList->Add(*pClonedString);
476                 SysTryReturn(NID_LCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
477
478                 pClonedString.release();
479         }
480
481         return pClonedArrayList.release();
482 }
483
484
485
486 IMultiMap*
487 _DateTimeSymbolsImpl::CloneMultiHashMapN(const Tizen::Base::Collection::IMultiMap* pMultiMap) const
488 {
489         SysTryReturn(NID_LCL, pMultiMap, null, E_INVALID_ARG, "[%s] Invalid argument is used. pMultiMap is null.", GetErrorMessage(E_INVALID_ARG));
490
491         ClearLastResult();
492
493         std::unique_ptr< MultiHashMap, AllElementsDeleter > pClonedMultiHashMap(new (std::nothrow) MultiHashMap());
494         SysTryReturn(NID_LCL, pClonedMultiHashMap, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
495
496         result r = pClonedMultiHashMap->Construct();
497         SysTryReturn(NID_LCL, !IsFailed(r), null, r, "[%s] Unable to construct hash map.", GetErrorMessage(r));
498
499         std::unique_ptr< IList > pKeys(pMultiMap->GetKeysN());
500         r = GetLastResult();
501         SysTryReturn(NID_LCL, pKeys != null, null, r, "[%s] Unable to get key list.", GetErrorMessage(r));
502
503         for (int i = 0; i < pKeys->GetCount(); i++)
504         {
505                 String* pKey = static_cast< String* >(pKeys->GetAt(i));
506                 SysTryReturn(NID_LCL, pKey != null, null, r, "[%s] Propagated.", GetLastResult());
507
508                 std::unique_ptr< IEnumerator > pValueEnum(pMultiMap->GetValuesN(*pKey));
509                 r = GetLastResult();
510                 SysTryReturn(NID_LCL, pValueEnum != null, null, r, "[%s] Unable to get values for key.", GetErrorMessage(r));
511
512                 std::unique_ptr< String > pMapKey(new (std::nothrow)String(*pKey));
513                 SysTryReturn(NID_LCL, pMapKey != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
514
515                 while (pValueEnum->MoveNext() == E_SUCCESS)
516                 {
517                         std::unique_ptr< String > pTimeZoneName(new (std::nothrow) String(*(static_cast<String*> (pValueEnum->GetCurrent()))));
518                         if (pTimeZoneName)
519                         {
520                                 r = pClonedMultiHashMap->Add(*pMapKey, *pTimeZoneName);
521                                 if (IsFailed(r))
522                                 {
523                                         pClonedMultiHashMap->Remove(*pMapKey,true);
524                                         break;
525                                 }
526
527                                 pTimeZoneName.release();
528                         }
529                         else
530                         {
531                                 pClonedMultiHashMap->Remove(*pMapKey,true);
532                                 break;
533                         }
534                 }
535
536                 pMapKey.release();
537         }
538
539         return pClonedMultiHashMap.release();
540 }
541
542 result
543 _DateTimeSymbolsImpl::SetList(Tizen::Base::Collection::ArrayList* pArrayList, int tokenCount, const Tizen::Base::String& stringWillBeTokenized)
544 {
545         StringTokenizer tokenizer(stringWillBeTokenized, L"|");
546
547         SysTryReturnResult(NID_LCL, (tokenizer.GetTokenCount() == tokenCount), E_INVALID_ARG,
548                                 "Invalid argument is used. stringWillBeTokenized=%ls", stringWillBeTokenized.GetPointer());
549
550         std::unique_ptr< ArrayList, AllElementsDeleter > pTmpArrayList(pArrayList);
551         SysTryReturnResult(NID_LCL, pTmpArrayList, E_INVALID_ARG, "Invalid argument is used. pArrayList should not be null");
552
553         result r = pTmpArrayList->Construct(tokenCount);  // Constructing list for tokenCount elements
554         if (!IsFailed(r))
555         {
556                 String token;
557                 std::unique_ptr< String > pListStr(null);
558                 while (tokenizer.GetNextToken(token) == E_SUCCESS)
559                 {
560                         pListStr.reset(new (std::nothrow) String(token));
561                         SysTryReturnResult(NID_LCL, pListStr, E_OUT_OF_MEMORY, "Memory allocation failed.");
562
563                         r = pTmpArrayList->Add(*pListStr);
564                         SysTryReturnResult(NID_LCL, r == E_SUCCESS, r, "Failed to add value to array list.");
565
566                         pListStr.release();
567                 }
568         }
569
570         pTmpArrayList.release();
571         return r;
572 }
573
574 void
575 _DateTimeSymbolsImpl::ReleaseList(IList* pList)
576 {
577         if (pList)
578         {
579                 pList->RemoveAll(true);         // Remove elements and de-allocate memory used by them
580                 delete pList;
581         }
582 }
583
584 // This function release all the list after deleting their contents
585 void
586 _DateTimeSymbolsImpl::ReleaseAll(void)
587 {
588         ReleaseList(__pErasList);                           // Deleting EraList after deleting its contents
589         ReleaseList(__pMonthsList);                         // Deleting MonthsList after deleting its contents
590         ReleaseList(__pShortMonthsList);                    // Deleting ShortMonthsList after deleting its contents
591         ReleaseList(__pWeekdaysList);                       // Deleting WeekdaysList after deleting its contents
592         ReleaseList(__pShortWeekdaysList);                  // Deleting ShortWeekdaysList after deleting its contents
593         ReleaseList(__pAmPmList);                           // Deleting AmPmList after deleting its contents
594
595         if (__pTimeZonesMap)
596         {
597                 __pTimeZonesMap->RemoveAll(true);               // Removing and deleting contents of TimeZonesMap
598                 delete __pTimeZonesMap;                         // Deleting TimeZonesMap
599         }
600 }
601
602 _DateTimeSymbolsImpl*
603 _DateTimeSymbolsImpl::GetDateTimeSymbolsImpl(DateTimeSymbols* pDateTimeSymbols)
604 {
605         return pDateTimeSymbols->__pDateTimeSymbolsImpl;
606 }
607
608 };
609 };      // Tizen::Locale
610