Skip to content

Commit 3cc0a7c

Browse files
committed
Added string specific logic
1 parent 2f24a0a commit 3cc0a7c

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

std/utf.d

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,15 +2470,19 @@ char[] toUTF8(return out char[4] buf, dchar c) nothrow @nogc @safe pure
24702470
*/
24712471
string toUTF8(S)(S s) if (isSomeString!S)
24722472
{
2473-
import std.array : appender;
2474-
2475-
auto app = appender!string();
2476-
app.reserve(s.length);
2477-
2478-
foreach (c; s.byChar)
2479-
app.put(c);
2480-
2481-
return app.data;
2473+
static if (is(S : string))
2474+
{
2475+
return s.idup;
2476+
}
2477+
else
2478+
{
2479+
import std.array : appender;
2480+
auto app = appender!string();
2481+
app.reserve(s.length);
2482+
foreach (c; s.byUTF2!char)
2483+
app.put(c);
2484+
return app.data;
2485+
}
24822486
}
24832487

24842488
///

0 commit comments

Comments
 (0)