1 // Created on: 2016-02-23
2 // Created by: Kirill Gavrilov
3 // Copyright (c) 2016 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
20 #include <NCollection_UtfString.hxx>
22 #if !defined(__ANDROID__)
23 //=======================================================================
24 //function : ~NCollection_UtfStringTool
26 //=======================================================================
27 NCollection_UtfStringTool::~NCollection_UtfStringTool()
29 delete[] myWideBuffer;
32 //=======================================================================
33 //function : FromLocale()
35 //=======================================================================
36 wchar_t* NCollection_UtfStringTool::FromLocale (const char* theString)
38 if (myWideBuffer != NULL)
40 delete[] myWideBuffer;
46 int aWideSize = MultiByteToWideChar (CP_ACP, MB_PRECOMPOSED, theString, -1, NULL, 0);
52 myWideBuffer = new wchar_t[aWideSize + 1];
53 MultiByteToWideChar (CP_ACP, MB_PRECOMPOSED, theString, -1, myWideBuffer, aWideSize);
54 myWideBuffer[aWideSize] = L'\0';
56 // this is size in bytes but should probably be enough to store string in wide chars
57 // notice that these functions are sensitive to locale set by application!
58 int aMbLen = mblen (theString, MB_CUR_MAX);
64 myWideBuffer = new wchar_t[aMbLen + 1];
65 mbstowcs (myWideBuffer, theString, aMbLen);
66 myWideBuffer[aMbLen] = L'\0';
71 //=======================================================================
72 //function : ToLocale()
74 //=======================================================================
75 bool NCollection_UtfStringTool::ToLocale (const wchar_t* theWideString,
77 const Standard_Integer theSizeBytes)
80 int aMbBytes = WideCharToMultiByte (CP_ACP, 0, theWideString, -1, theBuffer, theSizeBytes, NULL, NULL);
82 std::size_t aMbBytes = std::wcstombs (theBuffer, theWideString, theSizeBytes);