Covert EOL End of Line from mac to windows.

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
papayrus
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 204
Joined: Tue Jan 25, 2011 4:55 pm
Location: USA

Covert EOL End of Line from mac to windows.

Post by papayrus »

Is there anyway to convert an ini file that has a mac EOL conversion to a windows conversion on the fly with wx other than using a third party program like notepad++. My program cannot read and write the data from the ini file it just deletes all the text in it. It works fine if I use notepad++ to convert the ini file to windows EOL and then run my program on the ini.
User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: Covert EOL End of Line from mac to windows.

Post by eranon »

The different types of EOL from different OS'es (CRLF under Windows, CR under OSX, LF under Linux) are just a matter of preliminary conversion before to parse your text file (INI or other). So, you just have to write a (global or not, depending of the frequency of usage, if useful in a given class only or everywhere) function like "bool DoAdjustEOL(wx[Text]File file)" or "wxString AdjustEOL(wxString strContent)"...
Last edited by eranon on Thu Jan 30, 2014 1:12 pm, edited 1 time in total.
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Covert EOL End of Line from mac to windows.

Post by PB »

papayrus, as I told you in the related thread, wxTextFile handles different line endings just fine (as of wxWidgets 3.0), the real problem problem being that wxTextFile doesn't write UTF BOM which the original ini file has and you supposedly have to preserve.
papayrus
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 204
Joined: Tue Jan 25, 2011 4:55 pm
Location: USA

Re: Covert EOL End of Line from mac to windows.

Post by papayrus »

I updated to 3.0.0 and have tested it. It works fine as it is as long as I just convert the EOL to Windows so there was no need to convert the encoding actually it just works. I just want to know how I can convert it or do something else that will work with the mac EOL or all 3 globally. ALso I tried converting to other encoding like ansi and it still erased all the text in the file. The only thing that worked and the only thing I had to do was change the EOL.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Covert EOL End of Line from mac to windows.

Post by PB »

Again, as I wrote before - It worked for me out of the box using autodetection (aside from not preserving the BOM marker) with the file you provided, no changes were necessary. I still believe you should treat the file as UTF-8 encoded (based on the BOM marker your original file had), have you tested a file with strings (e.g. the player name) using non-ASCII characters? In the end, I guess that the character encoding and EOL markers depends on the application that created the file and you have to use it...
papayrus
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 204
Joined: Tue Jan 25, 2011 4:55 pm
Location: USA

Re: Covert EOL End of Line from mac to windows.

Post by papayrus »

I have no idea how I would do what you are talking about. I don't know how to not preserve the BOM Marker and I do not know how to treat the file as UTF-8 encoded and also I don't know how to change the characters and use non asci ones. LOL sorry that is all confusing to me of how I could go about doing those things.
papayrus
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 204
Joined: Tue Jan 25, 2011 4:55 pm
Location: USA

Re: Covert EOL End of Line from mac to windows.

Post by papayrus »

If I wanted to make a restore file incase the original file got damaged how can I write a file like that with that many lines? Would I need to use file.AddLine for each and every line of the ini to write it in full?
papayrus
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 204
Joined: Tue Jan 25, 2011 4:55 pm
Location: USA

Re: Covert EOL End of Line from mac to windows.

Post by papayrus »

THis is my code it is simple I do not understand what I need to change to make it work globally.

Code: Select all

wxTextFile tfile;
    //tfile.Open(_("REV\\rev.ini"));
    tfile.Open(_("..\\rev.ini"));

    for (size_t n=0; n < tfile.GetLineCount(); ++n)
    {
        wxString &line = tfile.GetLine(n);
        //wxLogMessage( wxT("Line %d: %s"), n, line.c_str());
        if( line.StartsWith( wxT("PlayerName =") ) )
            {
                //wxLogMessage( wxT("interesting line found"));
                line = ( wxT("PlayerName =") ) + TextCtrl1->GetValue();
            }
    }
    tfile.Write();
Post Reply