Using a char value >= 128

Per Nordlöw per.nordlow at gmail.com
Sun Oct 27 12:44:05 UTC 2019


In which circumstances can a `char` be initialized a non-7-bit 
value (>= 128)? Is it possible only in non- at safe code?

And, if so, what will be the result of casting such a value to 
`dchar`? Will that result in an exception or will it interpret 
the `char` using a 8-bit character encoding?

I'm asking because I'm pondering about how to specialize the 
non-7-bit `needle`-case of the following array-overload of 
`startsWith` when `T` is `char`:

bool startsWith(T)(scope const(T)[] haystack,
                    scope const T needle)
{
     static if (is(T : char)) { assert(needle < 128); } // TODO 
convert needle to `char[]` and call itself
     if (haystack.length >= 1)
     {
         return haystack[0] == needle;
     }
     return false;
}



More information about the Digitalmars-d-learn mailing list