Applied sizeof operator on fixed sized array to calculate size.
[platform/framework/native/appfw.git] / src / system-server / setting / providers / FSys_Icu.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                FSys_Icu.cpp
19  * @brief               This is the implementation file for _Icu class.
20  */
21
22 #include <stdlib.h>
23 #include <memory.h>
24 #include <runtime_info.h>
25
26 #include <FBaseSysLog.h>
27 #include <FBase_NativeError.h>
28 #include "FSys_Icu.h"
29
30 namespace Tizen { namespace System
31 {
32
33 static const int _MAX_COUNTRY_LENTH = 2;
34 static const int _LANGUAGE_START_INDEX = 0;
35 static const int _MAX_LANGUAGE_LENTH = 2;
36
37 _Icu::_Icu()
38 {
39 }
40
41 _Icu::~_Icu()
42 {
43 }
44
45 char*
46 _Icu::GetIcuPatternN(const char* pLocale, UChar* pCustomSkeleton)
47 {
48         UErrorCode status = U_ZERO_ERROR;
49         UDateTimePatternGenerator* pGenerator = null;
50         UChar bestPattern[64] = {0,};
51
52         if(pLocale == null || pCustomSkeleton == null)
53         {
54                 return null;
55         }
56
57         char*   pBestPatternString = null;
58         int32_t bestPatternCapacity = 0;
59         int32_t bestPatternLength = 0;
60
61         pGenerator = udatpg_open(pLocale, &status);
62
63         if (U_FAILURE(status) == true)
64         {
65                 return null;
66         }
67
68         status = U_ZERO_ERROR;
69
70         bestPatternCapacity = (int32_t)(sizeof(bestPattern)/sizeof((bestPattern)[0]));
71         bestPatternLength = udatpg_getBestPattern(pGenerator, pCustomSkeleton, u_strlen(pCustomSkeleton), bestPattern, bestPatternCapacity, &status);
72         if (U_FAILURE(status) == true)
73         {
74                 return null;
75         }
76
77         status = U_ZERO_ERROR;
78         pBestPatternString = (char*)malloc(128);
79         if (pBestPatternString == null)
80         {
81                 return null;
82         }
83         memset(pBestPatternString, 0, 128);
84         u_austrncpy(pBestPatternString, bestPattern, 128);
85         udatpg_close(pGenerator);
86         SysLog(NID_SYS, "Format is [%s] \n", pBestPatternString);
87         return pBestPatternString;
88 }
89
90 char*
91 _Icu::GetDateTimeFormatN(const char* pIcuFormat)
92 {
93         char* pFormatString = null;
94         char* pDateTimeFormat = null;
95
96         if (pIcuFormat == null)
97         {
98                 return null;
99         }
100
101         UChar   customSkeleton[256] = {0, };
102         char* pRegionPtr;
103         if (runtime_info_get_value_string(RUNTIME_INFO_KEY_REGION, &pRegionPtr) == RUNTIME_INFO_ERROR_NONE)
104         {
105                 u_uastrncpy(customSkeleton, pIcuFormat, sizeof(customSkeleton));
106                 pFormatString = GetIcuPatternN(pRegionPtr, customSkeleton);
107                 free(pRegionPtr);
108         }
109         return pFormatString;
110 }
111
112 } } // Tizen::System