mirror of https://github.com/x64dbg/GleeBug
added string conversion helper functions
This commit is contained in:
parent
cb5ec1fae0
commit
be4549a361
|
|
@ -0,0 +1,41 @@
|
||||||
|
#include "GleeBug.h"
|
||||||
|
|
||||||
|
namespace GleeBug
|
||||||
|
{
|
||||||
|
//Conversion functions taken from: http://www.nubaria.com/en/blog/?p=289
|
||||||
|
std::string Utf16ToUtf8(const std::wstring & wstr)
|
||||||
|
{
|
||||||
|
std::string convertedString;
|
||||||
|
auto requiredSize = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, nullptr, 0, nullptr, nullptr);
|
||||||
|
if(requiredSize > 0)
|
||||||
|
{
|
||||||
|
std::vector<char> buffer(requiredSize);
|
||||||
|
WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, &buffer[0], requiredSize, nullptr, nullptr);
|
||||||
|
convertedString.assign(buffer.begin(), buffer.end() - 1);
|
||||||
|
}
|
||||||
|
return convertedString;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Utf16ToUtf8(const wchar_t* wstr)
|
||||||
|
{
|
||||||
|
return Utf16ToUtf8(wstr ? std::wstring(wstr) : std::wstring());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::wstring Utf8ToUtf16(const std::string & str)
|
||||||
|
{
|
||||||
|
std::wstring convertedString;
|
||||||
|
int requiredSize = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, nullptr, 0);
|
||||||
|
if(requiredSize > 0)
|
||||||
|
{
|
||||||
|
std::vector<wchar_t> buffer(requiredSize);
|
||||||
|
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, &buffer[0], requiredSize);
|
||||||
|
convertedString.assign(buffer.begin(), buffer.end() - 1);
|
||||||
|
}
|
||||||
|
return convertedString;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::wstring Utf8ToUtf16(const char* str)
|
||||||
|
{
|
||||||
|
return Utf8ToUtf16(str ? std::string(str) : std::string());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -53,6 +53,11 @@ namespace GleeBug
|
||||||
return a.second < b.first;
|
return a.second < b.first;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::string Utf16ToUtf8(const std::wstring & wstr);
|
||||||
|
std::string Utf16ToUtf8(const wchar_t* wstr);
|
||||||
|
std::wstring Utf8ToUtf16(const std::string & str);
|
||||||
|
std::wstring Utf8ToUtf16(const char* str);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //GLEEBUG_H
|
#endif //GLEEBUG_H
|
||||||
|
|
@ -168,6 +168,7 @@
|
||||||
<ClCompile Include="Debugger.Thread.HardwareBreakpoint.cpp" />
|
<ClCompile Include="Debugger.Thread.HardwareBreakpoint.cpp" />
|
||||||
<ClCompile Include="Debugger.Thread.Registers.cpp" />
|
<ClCompile Include="Debugger.Thread.Registers.cpp" />
|
||||||
<ClCompile Include="Debugger.Thread.Registers.GetSet.cpp" />
|
<ClCompile Include="Debugger.Thread.Registers.GetSet.cpp" />
|
||||||
|
<ClCompile Include="GleeBug.cpp" />
|
||||||
<ClCompile Include="Static.BufferFile.cpp" />
|
<ClCompile Include="Static.BufferFile.cpp" />
|
||||||
<ClCompile Include="Static.File.cpp" />
|
<ClCompile Include="Static.File.cpp" />
|
||||||
<ClCompile Include="Static.Pattern.cpp" />
|
<ClCompile Include="Static.Pattern.cpp" />
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,9 @@
|
||||||
<ClCompile Include="..\capstone_wrapper\capstone_wrapper.cpp">
|
<ClCompile Include="..\capstone_wrapper\capstone_wrapper.cpp">
|
||||||
<Filter>Source Files\capstone_wrapper</Filter>
|
<Filter>Source Files\capstone_wrapper</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="GleeBug.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Debugger.h">
|
<ClInclude Include="Debugger.h">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue