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
42 _Icu::GetIcuPatternN(const char* pLocale, UChar* pCustomSkeleton)
44 UErrorCode status = U_ZERO_ERROR;
45 UDateTimePatternGenerator* pGenerator = null;
46 UChar bestPattern[64] = {0,};
48 if(pLocale == null || pCustomSkeleton == null)
53 char* pBestPatternString = null;
54 int32_t bestPatternCapacity = 0;
55 int32_t bestPatternLength = 0;
57 pGenerator = udatpg_open(pLocale, &status);
59 if (U_FAILURE(status) == true)
64 status = U_ZERO_ERROR;
66 bestPatternCapacity = (int32_t)(sizeof(bestPattern)/sizeof((bestPattern)[0]));
67 bestPatternLength = udatpg_getBestPattern(pGenerator, pCustomSkeleton, u_strlen(pCustomSkeleton), bestPattern, bestPatternCapacity, &status);
68 if (U_FAILURE(status) == true)
73 status = U_ZERO_ERROR;
74 pBestPatternString = (char*)malloc(128);
75 if (pBestPatternString == null)
79 memset(pBestPatternString, 0, 128);
80 u_austrncpy(pBestPatternString, bestPattern, 128);
81 udatpg_close(pGenerator);
82 SysLog(NID_SYS, "Format is [%s] \n", pBestPatternString);
83 return pBestPatternString;
87 _Icu::GetDateTimeFormatN(const char* pIcuFormat)
89 char* pFormatString = null;
90 char* pDateTimeFormat = null;
92 if (pIcuFormat == null)
97 UChar customSkeleton[256] = {0, };
99 if (runtime_info_get_value_string(RUNTIME_INFO_KEY_REGION, &pRegionPtr) == RUNTIME_INFO_ERROR_NONE)
101 u_uastrncpy(customSkeleton, pIcuFormat, sizeof(customSkeleton));
102 pFormatString = GetIcuPatternN(pRegionPtr, customSkeleton);
105 return pFormatString;