Revert "Change the way to conver Mbs to Wcs and vice versa"
[platform/framework/native/appfw.git] / src / base / FBaseString.cpp
index 900b491..24dda81 100644 (file)
@@ -38,7 +38,7 @@
 #include <FBaseResult.h>
 #include <FBaseSysLog.h>
 #include <unique_ptr.h>
-#include "FBaseUtil_IcuConverter.h"
+
 
 namespace Tizen { namespace Base
 {
@@ -127,23 +127,25 @@ String::String(const char* pValue)
        , __pValue(null)
        , __pStringImpl(null)
 {
-       if (pValue == null || strlen(pValue) == 0)
+       int len = (pValue != null) ? mbstowcs(null, pValue, 0) : 0;
+
+       if (pValue == null)
        {
                result r = InitializeToDefault(DEFAULT_CAPACITY);
                SysTryReturnVoidResult(NID_BASE, r == E_SUCCESS, E_OUT_OF_MEMORY, "Memory allocation failed.");
        }
        else
        {
-               std::unique_ptr< wchar_t[] > pStr(Tizen::Base::Utility::ConvertMbsToWcsN(pValue));
-               SysTryReturnVoidResult(NID_BASE, pStr != null, GetLastResult(), "Propagating.");
+               result r = InitializeToDefault(len + DEFAULT_CAPACITY);
+               SysTryReturnVoidResult(NID_BASE, r == E_SUCCESS, E_OUT_OF_MEMORY, "Memory allocation failed.");
 
-               int strLen = wcslen(pStr.get());
-               std::unique_ptr<int> pRefCntTemp(new (std::nothrow) int(1));
-               SysTryReturnVoidResult(NID_BASE, pRefCntTemp != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
-               __pRefCount = pRefCntTemp.release();
-               __pValue = pStr.release();
-               __length = strLen;
-               __capacity = strLen + 1;
+               len = mbstowcs(__pValue, pValue, len);
+               if (len == -1)
+               {
+                       SysLog(NID_BASE, "Invalid encoding range[%s].", pValue);
+               }
+               __pValue[len] = '\0';
+               __length = len;
        }
 }