Comment #0 by bearophile_hugs — 2013-03-18T15:11:02Z
std.string.translate precondition contains code like this:
C[] translate(C = immutable char)(in char[] str, in char[] transTable, in char[] toRemove = null) @trusted nothrow
if(is(Unqual!C == char))
in
{
assert(transTable.length == 256);
foreach(char c; str)
assert(c <= 256);
foreach(char c; transTable)
assert(c <= 256);
foreach(char c; toRemove)
assert(c <= 256);
}
I think those asserts should be:
assert(c < 256);
Comment #1 by andrej.mitrovich — 2013-03-18T15:13:58Z
Why are those asserts in there anyway? A char can't be larger than 255..?
Comment #2 by bearophile_hugs — 2013-03-18T15:36:03Z
(In reply to comment #1)
> Why are those asserts in there anyway? A char can't be larger than 255..?
Ah, right. My brain was switched too much off.
This looks better:
foreach (dchar c; str)
assert(c < 256);
But this is a full-range translate(), so it should work in the whole range of [0, 256[, so I this precondition:
in
{
assert(transTable.length == 256);
foreach(char c; str)
assert(c <= 256);
foreach(char c; transTable)
assert(c <= 256);
foreach(char c; toRemove)
assert(c <= 256);
}
Should be:
in
{
assert(transTable.length == 256);
}
Comment #3 by andrej.mitrovich — 2013-03-18T15:46:49Z