text file and 8859-2 encoding [SOLVED]

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Berico3
Earned a small fee
Earned a small fee
Posts: 15
Joined: Mon Sep 17, 2007 5:43 am
Location: Italy

text file and 8859-2 encoding [SOLVED]

Post by Berico3 »

Hello to all,
I have a question about writing a wxTextfile: I can not find a way to let my file be saved with iso 8859-2 encoding.
In practice, I would like to force the encoding of the file in the way I exposed it.
It's possible?
Last edited by Berico3 on Wed Sep 27, 2017 9:48 pm, edited 3 times in total.
OS: Windows XP Pro & Debiam Linux COMPILER: MingW, Version: wxWidgets 2.8.0, IDE: wx-Devcpp
Ellan
Experienced Solver
Experienced Solver
Posts: 57
Joined: Mon May 15, 2017 10:11 am

Re: text file and 8859-2 encoding

Post by Ellan »

My understanding is that the string is iso 8859-2 encoded in memory and then written to file
Thanks

Best Regards

Ellan
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: text file and 8859-2 encoding

Post by PB »

Using wxCSConv with wxTextFile::Write works as expected for me:

Code: Select all

#include <wx/wx.h>
#include <wx/textdlg.h>
#include <wx/textfile.h>

class MyApp : public wxApp
{
public:          
    bool OnInit()
    {
        wxTextEntryDialog dlg(NULL, "Input text");

        if ( dlg.ShowModal() != wxID_OK || dlg.GetValue().empty() )
            return false;

        wxTextFile textFile;

        if ( textFile.Create("test.txt") )            
        {
            textFile.AddLine(dlg.GetValue());
            textFile.Write(wxTextFileType_None, wxCSConv("iso8859-2"));        
        }

        return false;
    }   
}; wxIMPLEMENT_APP(MyApp);
I tested the code with "Příliš žluťoučký kůň úpěl ďábelské ódy." and checked the actual character values (for š and ž in particular) displaying the resulting file with a hex viewer.

But I am using wxWidgets 3 in Unicode mode, your signature hints that you are not?
Berico3
Earned a small fee
Earned a small fee
Posts: 15
Joined: Mon Sep 17, 2007 5:43 am
Location: Italy

Re: text file and 8859-2 encoding

Post by Berico3 »

Thank you for your answers.
I also normally use unicode encoding, but I'm working on a software that modifies text files (that is Gcode), since the files will then have to be read by a CNC machine, I would prefer that they keep the original encoding.
Thanks again. =D>
OS: Windows XP Pro & Debiam Linux COMPILER: MingW, Version: wxWidgets 2.8.0, IDE: wx-Devcpp
Post Reply