2,427 karma · joined Jun 15, 2023 (3y ago) · 1,641 submissions
comment 3y ago · link · parent
C++ also supports wstring, but its implementation is dependent on the platform for god knows what reason.
utf-16 is also supported in C11:
https://en.wikipedia.org/wiki/C11_(C_standard_revision)#Chan...
> Improved Unicode support based on the C Unicode Technical Report ISO/IEC TR 19769:2004 (char16_t and char32_t types for storing UTF-16/UTF-32 encoded data, including conversion functions in <uchar.h> and the corresponding u and U string literal prefixes, as well as the u8 prefix for UTF-8 encoded literals).
You can use uchar.h for converting instead of the Win32 functions.
Here's a helper I wrote to wrap these string types in std::string and std::wstring:
bool mbStrToWideChar(string const& in, wstring& out)
{
bool status = true;
i32 bufferSize = MultiByteToWideChar(
CP_ACP, 0, in.c_str(), -1, nullptr, 0
);
WCHAR* buffer = new WCHAR[bufferSize];
i32 conversionResult = MultiByteToWideChar(
CP_ACP, 0,
in.c_str(), -1,
buffer, bufferSize
);
if (!conversionResult)
{
cerr << "Failed to convert ANSI string [" << in << "] to Wide string!" << endl;
status = false;
goto Delete;
}
out = wstring(buffer);
Delete:
if (buffer)
{
delete[] buffer;
}
return status;
}
and bool wideStrToMbStr(wstring const& in, string& out)
{
// Get buffer size
i32 bufferSize = WideCharToMultiByte(
CP_UTF8, 0,
in.c_str(), (i32)in.size(),
nullptr, 0,
nullptr, nullptr
);
// Set outstring to new buffer size
out = string(bufferSize, '\0');
//Convert
i32 res = WideCharToMultiByte(
CP_UTF8, 0,
in.c_str(), (i32)in.size(),
&out[0], (i32)out.size(),
nullptr, nullptr
);
if (!res)
{
wcerr << L"Failed to convert Wide string [" << in << L"] to ANSI string!" << endl;
return false;
}
return true;
}comment 3y ago · link · parent
There is no need to do this; you can just call the A variant by name. Wide char and ascii functions are distinguished with W or A at the end, such as CreateFileA or CreateFileW. CreateFile is a macro.
comment 3y ago · link · parent
This statement:
> The PROGRAMS. Who wants to rewrite everything because you can no longer pipe or redirect?
Is almost unintelligible, aside from the fact that I guess it qualifies as a nearly-correct statement in English
comment 3y ago · link · parent
Oh cool just more bullshit from a bought and paid for Russian asset
comment 3y ago · link · parent
I'd estimate (generously) that maybe 25% of the people who go to college these days should, and 75% should not
comment 3y ago · link · parent
comment 3y ago · link · parent
https://docs.oracle.com/en/java/javase/11/docs/api/java.base...
https://docs.oracle.com/en/java/javase/17/docs/api/java.base...
comment 3y ago · link · parent
comment 3y ago · link · parent
In C#, the string `"""Hello world"` is invalid, but `@"""Hello world"` is, because double quotes are valid with verbatim string literals.