Move some stuff to a header, removing the need for a dodgy hack.

pull/29/head
AnyOldName3 8 years ago
parent becc053555
commit 2b829f7f7b

@ -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 <typename Source>
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<std::string>(str, std::string() + (char)escape_hash_filter::sEscape + (char)escape_hash_filter::sHashIdentifier, "#");

@ -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 <typename Source>
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
*/

Loading…
Cancel
Save