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.
18 * @file FBase_StringConverter.cpp
19 * @brief This is the implementation for _StringConverter class.
24 #include <FBaseResult.h>
25 #include "FBase_StringConverter.h"
26 #include <FBaseSysLog.h>
30 namespace Tizen { namespace Base
34 _StringConverter::CopyToCharArrayN(const String& str)
36 return CopyToCharArrayN(str.GetPointer());
40 _StringConverter::CopyToCharArrayN(const wchar_t* pValue)
44 int len = wcstombs(0, pValue, 0);
45 SysTryReturn(NID_BASE, len != -1, null, E_INVALID_ARG, "[%s] Invalid argument is used. Invalid string.",
46 GetErrorMessage(E_INVALID_ARG));
48 pRet = new (std::nothrow) char[len + 1];
49 SysTryReturn(NID_BASE, pRet != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
50 GetErrorMessage(E_OUT_OF_MEMORY));
52 len = wcstombs(pRet, pValue, len);