Re: unicode file
- From: "Giovanni Dicanio" <giovanni.dicanio@xxxxxxxxxxx>
- Date: Mon, 23 Jun 2008 00:47:05 +0200
"Mihai N." <nmihai_year_2000@xxxxxxxxx> ha scritto nel messaggio
news:Xns9AC67703E353MihaiN@xxxxxxxxxxxxxxxx
If you use a VS8, take a loot at _open:
http://msdn.microsoft.com/en-us/library/z0kc8e3z(VS.80).aspx
You can specify _O_TEXT, _O_U16TEXT, _O_U8TEXT or _O_WTEXT
And the nicest part about _O_WTEXT:
"If _O_WTEXT is used to open a file for reading, _open reads the
beginning of the file and check for a byte order mark (BOM).
If there is a BOM, the file is treated as UTF-8 or UTF-16LE
depending on the BOM. If no BOM is present, the file is treated
as ANSI. When a file is opened for writing using _O_WTEXT, UTF-16
is used. If _O_UTF8 is used, the file is always opened as UTF-8
and if _O_UTF16 is used, the file is always opened as UTF-16
regardless of any previous setting or byte order mark."
No extra libraries (sorry Giovanni :-) and no need to do your own
conversion
(sorry Tom :-)
I'm glad that VC8 introduced that Unicode option.
However, the extra library I wrote (nothing special, of course) is useful
for its simplicity and to give a RAII approach to Unicode UTF-8 text file
management.
For example, to write text, you can just do:
<code>
UTF8TextFileWriter writer( L"filename..." );
writer.WriteLine( ...some unicode UTF-16 string );
</code>
it is simpler than calling _open, specifying some flags, converting
UTF-16 -> UTF-8, closing the file, etc.
Moreover, if you pass a UTF-16 string to VC8 specific functions, is this
string automatically converted to UTF-8 before writing to file?
My small library does the UTF-16 to UTF-8 conversion behind the scene.
And similar things for reading (UTF-8 text is converted back to UTF-16,
automatically; the programmer does not need to pay attention to these
details - he just needs to call a ReadLine method, and he gets a UTF-16
string).
Of course, my library is limited to the particular case (which I use) to use
UTF-8 in external files, and UTF-16 inside the app.
(It does not manage UTF-16 LE/BE files, or UTF-32 files.)
Thanks,
Giovanni
.
- Follow-Ups:
- Re: unicode file
- From: Mihai N.
- Re: unicode file
- References:
- Re: unicode file
- From: Mihai N.
- Re: unicode file
- Prev by Date: Re: Finding no of elements in the pointers
- Next by Date: Re: Dialog size in pixel
- Previous by thread: Re: unicode file
- Next by thread: Re: unicode file
- Index(es):
Relevant Pages
|