2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @brief This is the implementation file for _Icu class.
24 #include <runtime_info.h>
26 #include <FBaseSysLog.h>
27 #include <FBase_NativeError.h>
30 namespace Tizen { namespace System
33 static const int _MAX_COUNTRY_LENTH = 2;
34 static const int _LANGUAGE_START_INDEX = 0;
35 static const int _MAX_LANGUAGE_LENTH = 2;
46 _Icu::GetIcuPatternN(const char* pLocale, UChar* pCustomSkeleton)
48 UErrorCode status = U_ZERO_ERROR;
49 UDateTimePatternGenerator* pGenerator = null;
50 UChar bestPattern[64] = {0,};
52 if(pLocale == null || pCustomSkeleton == null)
57 char* pBestPatternString = null;
58 int32_t bestPatternCapacity = 0;
59 int32_t bestPatternLength = 0;
61 pGenerator = udatpg_open(pLocale, &status);
63 if (U_FAILURE(status) == true)
68 status = U_ZERO_ERROR;
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)
77 status = U_ZERO_ERROR;
78 pBestPatternString = (char*)malloc(128);
79 if (pBestPatternString == null)
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;
91 _Icu::GetDateTimeFormatN(const char* pIcuFormat)
93 char* pFormatString = null;
94 char* pDateTimeFormat = null;
96 if (pIcuFormat == null)
101 UChar customSkeleton[256] = {0, };
103 if (runtime_info_get_value_string(RUNTIME_INFO_KEY_REGION, &pRegionPtr) == RUNTIME_INFO_ERROR_NONE)
105 u_uastrncpy(customSkeleton, pIcuFormat, sizeof(customSkeleton));
106 pFormatString = GetIcuPatternN(pRegionPtr, customSkeleton);
109 return pFormatString;