wxTextCtrl::LoadFile

19 views
Skip to first unread message

tecn...@cabsagt.com

unread,
Sep 1, 2008, 1:54:54 AM9/1/08
to wx-u...@lists.wxwidgets.org
Hi,
 
msw, 2.8.8, unicode
 
I am using wxTextCtrl::LoadFile to load a list of files on a m3u file to a wxTextCtrl
 
But it only works if m3u is utf-8, I also have problems with wxTextInputStream when using ReadLine
 
Is there a function to know what is the encoding of a text file?
If not, can someone help me how to do it/ where to search how to do it
 
thanks

Vadim Zeitlin

unread,
Sep 1, 2008, 9:59:48 AM9/1/08
to wx-u...@lists.wxwidgets.org
On Sun, 31 Aug 2008 23:54:54 -0600 tecn...@cabsagt.com wrote:

> I am using wxTextCtrl::LoadFile to load a list of files on a m3u file to
> a wxTextCtrl
>
> But it only works if m3u is utf-8,

This function uses wxFFile::ReadAll() internally which uses wxConvAuto to
convert the file contents to Unicode. wxConvAuto only supports Unicode
encodings in 2.8, i.e. UTF-16/32 if there is a BOM in the beginning of the
file or UTF-8 otherwise. In svn trunk it was modified to fall back to the
current (single byte) encoding if the file doesn't have BOM and isn't valid
UTF-8 but in 2.8 you will need to do it yourself, i.e. use
wxFFile::ReadAll() and wxTextCtrl::SetValue() instead of just calling
wxTextCtrl::LoadFile().

> Is there a function to know what is the encoding of a text file?

If you mean whether it's in UTF-8 or not then the simplest test is to try
to read it in UTF-8 and see if it succeeds. Chances are the file is in
UTF-8 if it does. If you mean whether it's possible to detect the file
single byte encoding (e.g. CP1252, Latin-1, KOI8-R, Shift-JIS, ...) then
the answer in general is no although there are libraries implementing some
heuristics for this.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

Reply all
Reply to author
Forward
0 new messages