View previous topic :: View next topic |
Author |
Message |
jicman
Joined: 22 Dec 2004 Posts: 298 Location: Rochester, NY
|
Posted: Sat Feb 28, 2009 12:32 am Post subject: mtext question |
|
|
Greetings.
I have a bunch of Unicode XML text files with English and other languages on it. I have been searching in the D sites for some help, but I can not seem to find any. I found mtext by looking at this site,
http://www.prowiki.org/wiki4d/wiki.cgi?DanielKeep/TextInD
but I am still lost. This Unicode stuff is really annoying. Anyway, I have tried to read the file and I can read the text and search and find by reading the file to char[], but when I write the file back, it loses the Unicode characteristic. I found mtext and I would like to know how to use it.
if I read a file that is Unicode, how to I get the input to a mtext variable. I tried,
Code: | mstring mstr = f.readline();
And I am getting an UTF8 sequence error.
Another question, once i have the content in a mstring variable, how do I write that mstring back to a file as Unicode?
thanks,
jose |
|
|
Back to top |
|
|
jicman
Joined: 22 Dec 2004 Posts: 298 Location: Rochester, NY
|
Posted: Sat Feb 28, 2009 11:38 pm Post subject: |
|
|
Here is a small example:
Code: | // testing MString
import std.stdio;
import std.file;
import jic.libs.mtext;
void main()
{
char[] f0 = "Unicode.ttx.xml";
char[] f1 = "UnicodeNew.ttx.xml";
auto text = cast(string) f0.read();
mstring ms;
writefln("here... 0");
ms.opAssign(text);
writefln("here... 1");
if (ms.find("DisplayText=\"TrixieTag\">"c, false) > 0)
{
writefln("Found Trixie Tags in " ~ f0);
}
//f1.write(cast(void[]) text);
}
|
The program compiles ok, but when I run it, here is what I get:
Quote: |
0:29:01.32>unicode0
here... 0
Error: 4invalid UTF-8 sequence
|
How do I get the data to the ms variable? |
|
Back to top |
|
|
Chris Miller
Joined: 27 Mar 2004 Posts: 514 Location: The Internet
|
Posted: Tue Mar 03, 2009 7:32 pm Post subject: |
|
|
The file might have a BOM or not actually be UTF-8. std.stream has some stuff for dealing with a BOM. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|