Skip to content

Commit

Permalink
Merge pull request #3210 from WalterBright/refactorTranslate
Browse files Browse the repository at this point in the history
Refactor: remove pointless std.string.translateImplAscii()
  • Loading branch information
MartinNowak committed Apr 22, 2015
2 parents f9e6ee7 + aca2ed5 commit 10f4739
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions std/string.d
Expand Up @@ -3632,7 +3632,14 @@ body
}

auto buffer = new char[count];
translateImplAscii(str, transTable, remTable, buffer, toRemove);

size_t i = 0;
foreach (char c; str)
{
if (!remTable[c])
buffer[i++] = transTable[c];
}

return cast(C[])(buffer);
}

Expand Down Expand Up @@ -3738,7 +3745,11 @@ body
foreach (char c; toRemove)
remTable[c] = true;

translateImplAscii(str, transTable, remTable, buffer, toRemove);
foreach (char c; str)
{
if (!remTable[c])
put(buffer, transTable[c]);
}
}

///
Expand All @@ -3755,28 +3766,6 @@ body
assert(buffer.data == "h5 rd");
}

private void translateImplAscii(C = immutable char, Buffer)(in char[] str,
in char[] transTable, ref bool[256] remTable, Buffer buffer,
in char[] toRemove = null) @trusted pure
{
static if (isOutputRange!(Buffer, char))
{
foreach (char c; str)
{
if (!remTable[c])
put(buffer, transTable[c]);
}
}
else
{
size_t i = 0;
foreach (char c; str)
{
if (!remTable[c])
buffer[i++] = transTable[c];
}
}
}

/***********************************************
* See if character c is in the pattern.
Expand Down

0 comments on commit 10f4739

Please sign in to comment.