From 6640912578e4d5a4567fd7ae20f0da2bf6fb7058 Mon Sep 17 00:00:00 2001 From: John Fultz Date: Sat, 2 Jul 2016 22:45:25 -0500 Subject: More character encoding stuff A few character encoding things that had still been missed, and preliminary support for #character-encoding in GCG files. --- quacker/quacker.cpp | 1 + quackleio/gcgio.cpp | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/quacker/quacker.cpp b/quacker/quacker.cpp index 4b7f29c..69bf9f9 100644 --- a/quacker/quacker.cpp +++ b/quacker/quacker.cpp @@ -1319,6 +1319,7 @@ void TopLevel::reportAs(Quackle::ComputerPlayer *player) Quackle::ComputerPlayer *clone = player->clone(); QTextStream stream(&file); + stream.setCodec(QTextCodec::codecForName("UTF-8")); QuackleIO::StreamingReporter::reportGame(*m_game, clone, stream); delete clone; } diff --git a/quackleio/gcgio.cpp b/quackleio/gcgio.cpp index cafbf49..dfe23a0 100644 --- a/quackleio/gcgio.cpp +++ b/quackleio/gcgio.cpp @@ -43,6 +43,7 @@ Quackle::Game *GCGIO::read(QTextStream &stream, int flags) bool gameStarted = false; QString line; + stream.setCodec(QTextCodec::codecForName("ISO-8859-1")); while (!stream.atEnd()) { line = stream.readLine(); @@ -111,6 +112,11 @@ Quackle::Game *GCGIO::read(QTextStream &stream, int flags) incompleteRack = Util::encode(rackString); hasIncompleteRack = true; } + else if (line.startsWith("#character-encoding")) + { + QString encoding{line.right(line.length() - 20).trimmed()}; + stream.setCodec(QTextCodec::codecForName(encoding.toAscii())); + } } else if (line.startsWith(">")) { @@ -293,6 +299,7 @@ bool GCGIO::canRead(QTextStream &stream) const void GCGIO::write(const Quackle::Game &game, QTextStream &stream) { Quackle::PlayerList players = game.players(); + stream.setCodec(QTextCodec::codecForName("ISO-8859-1")); for (Quackle::PlayerList::iterator it = players.begin(); it != players.end(); ++it) { stream << "#player" << (*it).id() + 1 << " " << Util::uvStringToQString((*it).abbreviatedName()) << " " << Util::uvStringToQString((*it).name()) << endl; -- cgit v1.2.3