Skip to content

Commit f6e18bf

Browse files
Merge pull request #5083 from JackStouffer/toUTF-deprecation
Deprecate Obsolete Encoding Functions in std.utf
2 parents 2016659 + 0a6c31b commit f6e18bf

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

std/stdio.d

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2690,7 +2690,7 @@ $(D Range) that locks the file and allows fast writing to it.
26902690
}
26912691
else static if (c.sizeof == 2)
26922692
{
2693-
import std.utf : toUTF8;
2693+
import std.utf : encode, UseReplacementDchar;
26942694

26952695
if (orientation_ <= 0)
26962696
{
@@ -2701,9 +2701,9 @@ $(D Range) that locks the file and allows fast writing to it.
27012701
else
27022702
{
27032703
char[4] buf;
2704-
auto b = toUTF8(buf, c);
2705-
foreach (i ; 0 .. b.length)
2706-
trustedFPUTC(b[i], handle_);
2704+
immutable size = encode!(UseReplacementDchar.yes)(buf, c);
2705+
foreach (i ; 0 .. size)
2706+
trustedFPUTC(buf[i], handle_);
27072707
}
27082708
}
27092709
else
@@ -4462,12 +4462,12 @@ private struct ReadlnAppender
44624462
}
44634463
void putdchar(dchar dc) @trusted
44644464
{
4465-
import std.utf : toUTF8;
4465+
import std.utf : encode, UseReplacementDchar;
44664466

44674467
char[4] ubuf;
4468-
char[] u = toUTF8(ubuf, dc);
4469-
reserve(u.length);
4470-
foreach (c; u)
4468+
immutable size = encode!(UseReplacementDchar.yes)(ubuf, dc);
4469+
reserve(size);
4470+
foreach (c; ubuf)
44714471
buf.ptr[pos++] = c;
44724472
}
44734473
void putonly(char[] b) @trusted

std/utf.d

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2654,7 +2654,8 @@ void validate(S)(in S str) @safe pure
26542654
}());
26552655
}
26562656

2657-
/* =================== Conversion to UTF8 ======================= */
2657+
//@@@DEPRECATED_2017-10@@@
2658+
deprecated("To be removed November 2017. Please use std.utf.encode instead.")
26582659
char[] toUTF8(return out char[4] buf, dchar c) nothrow @nogc @safe pure
26592660
{
26602661
if (c <= 0x7F)
@@ -2735,9 +2736,8 @@ string toUTF8(S)(S s) if (isInputRange!S && isSomeChar!(ElementEncodingType!S))
27352736
assert(r2.toUTF8.equal([0xF0, 0x90, 0x90, 0xB7]));
27362737
}
27372738

2738-
2739-
/* =================== Conversion to UTF16 ======================= */
2740-
2739+
//@@@DEPRECATED_2017-10@@@
2740+
deprecated("To be removed November 2017. Please use std.utf.encode instead.")
27412741
wchar[] toUTF16(return ref wchar[2] buf, dchar c) nothrow @nogc @safe pure
27422742
in
27432743
{

0 commit comments

Comments
 (0)