D1: UTF8 char[] casting to wchar[] array cast misalignment ERROR

jicman via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jun 18 10:15:29 PDT 2014


On Wednesday, 18 June 2014 at 02:25:34 UTC, Jesse Phillips wrote:
> On Tuesday, 17 June 2014 at 02:27:43 UTC, jicman wrote:
>>
>> Greetings!
>>
>> I have a bunch of files plain ASCII, UTF8 and UTF16 with and 
>> without BOM (Byte Order Mark).  I had, "I thought", a nice way 
>> of figuring out what type of encoding the file was (ASCII, 
>> UTF8 or UTF16) when the BOM was missing, by reading the 
>> content and applying the std.utf.validate function to the 
>> char[] or, wchar[] string.  The problem is that lately, I am 
>> hitting into a wall with the "array cast misalignment" when 
>> casting wchar[].
>
> If the BOM is missing and it is not UTF-8, it isn't a valid UTF 
> encoding.
>
> Otherwise you have your answer. Don't cast a char[] to wchar[], 
> if you have a valid char[] then it must be converted (use 
> std.conv.to);
>
> Some testing, the mentioned check for UTF-16 being even is 
> exactly what caused the "array cast misalignment" error (the 
> array wasn't an even number of bytes).

Thanks.


More information about the Digitalmars-d-learn mailing list