D1: UTF8 char[] casting to wchar[] array cast misalignment ERROR
Jacob Carlborg via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jun 16 23:44:39 PDT 2014
On 17/06/14 04:27, 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[]. ie.
>
> auto text = cast(string) file.read();
> wchar[] temp = cast(wchar[]) text;
How about casting to "wchar[]" directory, instead of going through "string".
> What would be the correct process to find out a text file encoding?
>
> Any help would be greatly appreciated. This is the code that I have
> right now...
I don't know if you use Tango [1], but it has a module [2] to help with
this sort of things.
[1] http://dsource.org/projects/tango
[2] http://dsource.org/projects/tango/docs/stable/tango.io.UnicodeFile.html
--
/Jacob Carlborg
More information about the Digitalmars-d-learn
mailing list