We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2f24a0a commit 3cc0a7cCopy full SHA for 3cc0a7c
std/utf.d
@@ -2470,15 +2470,19 @@ char[] toUTF8(return out char[4] buf, dchar c) nothrow @nogc @safe pure
2470
*/
2471
string toUTF8(S)(S s) if (isSomeString!S)
2472
{
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;
+ static if (is(S : string))
+ {
+ return s.idup;
+ }
+ else
+ import std.array : appender;
+ auto app = appender!string();
+ app.reserve(s.length);
2482
+ foreach (c; s.byUTF2!char)
2483
+ app.put(c);
2484
+ return app.data;
2485
2486
}
2487
2488
///
0 commit comments