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.
25 #include <FBaseSysLog.h>
26 #include <FBase_NativeError.h>
29 namespace Tizen { namespace System
32 static const int _MAX_COUNTRY_LENTH = 2;
33 static const int _LANGUAGE_START_INDEX = 0;
34 static const int _MAX_LANGUAGE_LENTH = 2;
45 _Icu::GetIcuPatternN(const char* pLocale, UChar* pCustomSkeleton)
47 UErrorCode status = U_ZERO_ERROR;
48 UDateTimePatternGenerator* pGenerator = null;
49 UChar bestPattern[64] = {0,};
51 if(pLocale == null || pCustomSkeleton == null)
56 char* pBestPatternString = null;
57 int32_t bestPatternCapacity = 0;
58 int32_t bestPatternLength = 0;
60 pGenerator = udatpg_open(pLocale, &status);
62 if (U_FAILURE(status) == true)
67 status = U_ZERO_ERROR;
69 bestPatternCapacity = (int32_t)(sizeof(bestPattern)/sizeof((bestPattern)[0]));
70 bestPatternLength = udatpg_getBestPattern(pGenerator, pCustomSkeleton, u_strlen(pCustomSkeleton), bestPattern, bestPatternCapacity, &status);
71 if (U_FAILURE(status) == true)
76 status = U_ZERO_ERROR;
77 pBestPatternString = (char*)malloc(128);
78 if (pBestPatternString == null)
82 memset(pBestPatternString, 0, 128);
83 u_austrncpy(pBestPatternString, bestPattern, 128);
84 udatpg_close(pGenerator);
85 SysLog(NID_SYS, "Format is [%s] \n", pBestPatternString);
86 return pBestPatternString;
90 _Icu::GetDateTimeFormatN(const char* pIcuFormat)
92 char* pFormatString = null;
93 char* pDateTimeFormat = null;
95 if (pIcuFormat == null)
100 UChar customSkeleton[256] = {0, };
101 const char* pLocaleDefault = uloc_getDefault();
103 pDateTimeFormat = const_cast< char* > (pLocaleDefault);
105 u_uastrncpy(customSkeleton, pIcuFormat, sizeof(customSkeleton));
106 pFormatString = GetIcuPatternN(pDateTimeFormat, customSkeleton);
108 return pFormatString;