From 2b829f7f7b2f5083f6ab2587fbf96042aba58406 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Thu, 21 Jul 2016 01:07:25 +0100 Subject: [PATCH] Move some stuff to a header, removing the need for a dodgy hack. --- components/files/configurationmanager.cpp | 44 ----------------------- components/files/configurationmanager.hpp | 43 ++++++++++++++++++++-- 2 files changed, 40 insertions(+), 47 deletions(-) diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index ca2c22ecd..127daac65 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -145,9 +145,6 @@ bool ConfigurationManager::loadConfig(const boost::filesystem::path& path, boost::iostreams::filtering_istream configFileStream; configFileStream.push(escape_hash_filter()); configFileStream.push(configFileStreamUnfiltered); - - boost::iostreams::filtering_istream dummyStreamThatShouldMakeOtherCodeCompile; - dummyStreamThatShouldMakeOtherCodeCompile.push(unescape_hash_filter()); if (configFileStreamUnfiltered.is_open()) { boost::program_options::store(boost::program_options::parse_config_file( @@ -167,10 +164,6 @@ bool ConfigurationManager::loadConfig(const boost::filesystem::path& path, return false; } -const int escape_hash_filter::sEscape = '@'; -const int escape_hash_filter::sEscapeIdentifier = 'a'; -const int escape_hash_filter::sHashIdentifier = 'h'; - escape_hash_filter::escape_hash_filter() : mNext(), mSeenNonWhitespace(false), mFinishLine(false) { } @@ -248,43 +241,6 @@ unescape_hash_filter::~unescape_hash_filter() { } -template -int unescape_hash_filter::get(Source & src) -{ - int character; - if (!expectingIdentifier) - character = boost::iostreams::get(src); - else - { - character = escape_hash_filter::sEscape; - expectingIdentifier = false; - } - if (character == escape_hash_filter::sEscape) - { - int nextChar = boost::iostreams::get(src); - int intended; - switch (nextChar) - { - case escape_hash_filter::sEscapeIdentifier: - intended = escape_hash_filter::sEscape; - break; - case escape_hash_filter::sHashIdentifier: - intended = '#'; - break; - case boost::iostreams::WOULD_BLOCK: - expectingIdentifier = true; - intended = nextChar; - break; - default: - intended = '?'; - break; - } - return intended; - } - else - return character; -} - std::string EscapeHashString::processString(const std::string & str) { std::string temp = boost::replace_all_copy(str, std::string() + (char)escape_hash_filter::sEscape + (char)escape_hash_filter::sHashIdentifier, "#"); diff --git a/components/files/configurationmanager.hpp b/components/files/configurationmanager.hpp index 154445be6..1d2d2c419 100644 --- a/components/files/configurationmanager.hpp +++ b/components/files/configurationmanager.hpp @@ -71,9 +71,9 @@ struct ConfigurationManager */ struct escape_hash_filter : public boost::iostreams::input_filter { - static const int sEscape; - static const int sHashIdentifier; - static const int sEscapeIdentifier; + static const int sEscape = '@'; + static const int sHashIdentifier = 'h'; + static const int sEscapeIdentifier = 'a'; escape_hash_filter(); virtual ~escape_hash_filter(); @@ -99,6 +99,43 @@ struct unescape_hash_filter : public boost::iostreams::input_filter bool expectingIdentifier; }; +template +int unescape_hash_filter::get(Source & src) +{ + int character; + if (!expectingIdentifier) + character = boost::iostreams::get(src); + else + { + character = escape_hash_filter::sEscape; + expectingIdentifier = false; + } + if (character == escape_hash_filter::sEscape) + { + int nextChar = boost::iostreams::get(src); + int intended; + switch (nextChar) + { + case escape_hash_filter::sEscapeIdentifier: + intended = escape_hash_filter::sEscape; + break; + case escape_hash_filter::sHashIdentifier: + intended = '#'; + break; + case boost::iostreams::WOULD_BLOCK: + expectingIdentifier = true; + intended = nextChar; + break; + default: + intended = '?'; + break; + } + return intended; + } + else + return character; +} + /** * \class EscapeHashString */