Skip to content

Commit

Permalink
fix issue 18993 - toLower is broken for UTF chars
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars-Kristiansen committed Jun 17, 2018
1 parent 8d4e394 commit 7dc672f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions std/uni.d
Original file line number Diff line number Diff line change
Expand Up @@ -9003,16 +9003,18 @@ if (isSomeString!S || (isRandomAccessRange!S && hasLength!S && hasSlicing!S && i
{
import std.array : appender, array;
import std.ascii : isASCII;
import std.utf : byDchar;
import std.utf : byDchar, codeLength;

alias C = ElementEncodingType!S;

auto r = s.byDchar;
for (size_t i; !r.empty; ++i, r.popFront())
for (size_t i; !r.empty; i += r.front.codeLength!C , r.popFront())
{
auto cOuter = r.front;
ushort idx = indexFn(cOuter);
if (idx == ushort.max)
continue;
auto result = appender!(ElementEncodingType!S[])();
auto result = appender!(C[])();
result.put(s[0 .. i]);
result.reserve(s.length);
foreach (dchar c; s[i .. $].byDchar)
Expand Down Expand Up @@ -9062,6 +9064,11 @@ if (isSomeString!S || (isRandomAccessRange!S && hasLength!S && hasSlicing!S && i
assert(s == "abcdefghij");
}

@safe unittest // 18993
{
static assert(`몬스터/A`.toLower.length == `몬스터/a`.toLower.length);
}


// generic toUpper/toLower on whole range, returns range
private auto toCaser(alias indexFn, uint maxIdx, alias tableFn, alias asciiConvert, Range)(Range str)
Expand Down

0 comments on commit 7dc672f

Please sign in to comment.