On Tuesday, 11 October 2016 at 03:00:45 UTC, Stefan Koch wrote:
On Tuesday, 11 October 2016 at 02:48:22 UTC, Andrei
Alexandrescu wrote:
That looks good. I'm just worried about the jump forward -
ideally the case c < 127 would simply entail a quick return. I
tried a fix, but it didn't do what I wanted in ldc. We
shouldn't assert(0) if wrong - just skip one byte. Also, are
we right to not worry about 5- and 6-byte sequences? The docs
keep on threatening with it, and then immediately mention
those are not valid.
[ ... ]
Andrei
If you want to skip a byte it's easy to do as well.
void popFront3(ref char[] s) @trusted pure nothrow {
immutable c = s[0];
uint char_length = 1;
if (c < 127)
{
Lend :
s = s.ptr[char_length .. s.length];
} else {
if ((c & b01100_0000) == 0b1000_0000)
{
//just skip one in case this is not the beginning of a
code-point char
goto Lend;
}
if (c < 192)
{
char_length = 2;
goto Lend;
}
if (c < 240)
{
char_length = 3;
goto Lend;
}
if (c < 248)
{
char_length = 4;
goto Lend;
}
}
}
Pardon me asking, but why all these gotos instead of else ifs:
if (c < 192)
{
char_length = 2;
}
else if (c < 240)
{
char_length = 3;
} else if (...) {
}
Does it have any effect on generated code (I don't think it
should)?