//
-// Open Service Platform
// Copyright (c) 2012 Samsung Electronics Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the License);
return icuStr;
}
+
// This function convert ICU string to OSP string
String
_LocaleData::GetOspString(const IcuUnicodeString& icuStr)
{
- setlocale(LC_ALL, "C");
int len = icuStr.length(); // get length
- if (len) // if icuStr is not empty
+ if (len > 0) // if icuStr is not empty
{
- char out[len * 3 + 1]; // Create buffer of thrice the icuStr length
- int end = icuStr.extract(0, len, out);
- out[end] = 0; // icuStr.extract() converts Unicode to UTF8
- setlocale(LC_ALL, "");
- return String(out);
+ wchar_t wstr[len + 1];
+ IcuUnicodeString tmpIcuStr(icuStr);
+ for (int i = 0; i < len ; i++)
+ {
+ UChar icuChar;
+ icuChar = tmpIcuStr.charAt(i);
+ wstr[i] = (wchar_t)icuChar;
+ }
+ wstr[len] = 0;
+ return String(wstr);
}
- setlocale(LC_ALL, "");
return String("");
}
ArrayList*
_LocaleData::ConvertIcuStringArrayToOspArrayN(const IcuUnicodeString* pIcuStrList, int count)
{
+ SysTryReturn(NID_LCL, pIcuStrList && count > 0, null, E_INVALID_ARG, "It is invalid argument.");
+
result r = E_SUCCESS;
- ArrayList* pTempArrayList = null;
- if (pIcuStrList && count > 0) // validating inputs
+ std::unique_ptr< ArrayList> pTempArrayList(new (std::nothrow) ArrayList(SingleObjectDeleter));
+ SysTryReturn(NID_LCL, pTempArrayList, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ pTempArrayList->Construct(count);
+
+ for (int i = 0; i < count; i++)
{
- pTempArrayList = new (std::nothrow) ArrayList();
- if (pTempArrayList) // If allocation is successful
+ std::unique_ptr< String > pString(new (std::nothrow) String(_LocaleData::GetOspString(pIcuStrList[i])));
+ SysTryReturn(NID_LCL, pString, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+ if (!pString->IsEmpty())
{
- r = pTempArrayList->Construct(count);
- if (!IsFailed(r)) // If ArrayList::Construct() is successful
- {
- for (int i = 0; i < count; i++)
- {
- String* pString = new (std::nothrow) String();
- if (pString != null)
- {
- *pString = _LocaleData::GetOspString(pIcuStrList[i]); // Get OSP string from ICU string
-
- if (!pString->IsEmpty())
- {
- pTempArrayList->Add(*pString); // Add OSP string to arraylist if it is not empty
- }
- else
- {
- delete pString;
- }
- }
- }
- }
+ r = pTempArrayList->Add(pString.get()); // Add OSP string to arraylist if it is not empty
+ SysTryReturn(NID_LCL, !IsFailed(r), null, E_SYSTEM, "It is failed to add string [%ls]", pString->GetPointer());
+ pString.release();
}
}
SetLastResult(r); // Setting last result value
- return pTempArrayList; // Return array list
+ return pTempArrayList.release(); // Return array list
}
// this function convert OSP string array list to ICU string array list
// set by this method have no effects in an instance of SimpleDateFormat for formatting time zones.
// __pIcuDateFormatSymbols->setZoneStrings();
+ __pIcuDateFormat->setDateFormatSymbols(*__pIcuDateFormatSymbols);
return E_SUCCESS;
}