mirror of
https://github.com/dlang/phobos.git
synced 2025-04-30 23:20:29 +03:00
minor
This commit is contained in:
parent
36220eb549
commit
6ec5113812
1 changed files with 20 additions and 21 deletions
|
@ -13,7 +13,6 @@ private import std.windows.syserror;
|
||||||
private import std.utf;
|
private import std.utf;
|
||||||
private import std.string;
|
private import std.string;
|
||||||
|
|
||||||
|
|
||||||
/******************************************
|
/******************************************
|
||||||
* Converts the UTF-8 string s into a null-terminated string in a Windows
|
* Converts the UTF-8 string s into a null-terminated string in a Windows
|
||||||
* 8-bit character set.
|
* 8-bit character set.
|
||||||
|
@ -29,33 +28,33 @@ private import std.string;
|
||||||
* yaneurao, Walter Bright, Stewart Gordon
|
* yaneurao, Walter Bright, Stewart Gordon
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const(char)* toMBSz(string s, uint codePage = 0)
|
const(char)* toMBSz(in char[] s, uint codePage = 0)
|
||||||
{
|
{
|
||||||
// Only need to do this if any chars have the high bit set
|
// Only need to do this if any chars have the high bit set
|
||||||
foreach (char c; s)
|
foreach (char c; s)
|
||||||
{
|
{
|
||||||
if (c >= 0x80)
|
if (c >= 0x80)
|
||||||
{
|
{
|
||||||
char[] result;
|
char[] result;
|
||||||
int readLen;
|
int readLen;
|
||||||
auto ws = std.utf.toUTF16z(s);
|
auto ws = std.utf.toUTF16z(s);
|
||||||
result.length = WideCharToMultiByte(codePage, 0, ws, -1, null, 0,
|
result.length = WideCharToMultiByte(codePage, 0, ws, -1, null, 0,
|
||||||
null, null);
|
null, null);
|
||||||
|
|
||||||
if (result.length)
|
if (result.length)
|
||||||
{
|
{
|
||||||
readLen = WideCharToMultiByte(codePage, 0, ws, -1, result.ptr,
|
readLen = WideCharToMultiByte(codePage, 0, ws, -1, result.ptr,
|
||||||
result.length, null, null);
|
result.length, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!readLen || readLen != result.length)
|
if (!readLen || readLen != result.length)
|
||||||
{
|
{
|
||||||
throw new Exception("Couldn't convert string: " ~
|
throw new Exception("Couldn't convert string: " ~
|
||||||
sysErrorString(GetLastError()));
|
sysErrorString(GetLastError()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.ptr;
|
return result.ptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return std.string.toStringz(s);
|
return std.string.toStringz(s);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue