StrokeSeg 1.0.0
Loading...
Searching...
No Matches
helpers.cpp
1#include "helpers.h"
2
3// Helper function to convert char* (ANSI/UTF-8) to std::wstring (UTF-16)
4std::wstring ConvertToWideString(const char* str)
5{
6 if (str == nullptr)
7 {
8 return std::wstring();
9 }
10
11 // Get the required buffer size for the wide string
12 int size_needed = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
13 if (size_needed == 0)
14 {
15 // Handle conversion error, e.g., return empty string or throw
16 return std::wstring();
17 }
18
19 // Create a wstring with the required size
20 std::wstring wstr(size_needed - 1, 0); // -1 to exclude the null terminator for std::wstring
21
22 // Perform the conversion
23 MultiByteToWideChar(CP_UTF8, 0, str, -1, &wstr[0], size_needed);
24
25 return wstr;
26}
Header file for helper functions. This file contains declarations for various utility functions used ...