1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 22:53:50 +00:00

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

This commit is contained in:
AnyOldName3 2016-07-21 01:07:25 +01:00
parent becc053555
commit 2b829f7f7b
2 changed files with 40 additions and 47 deletions

View file

@ -145,9 +145,6 @@ bool ConfigurationManager::loadConfig(const boost::filesystem::path& path,
boost::iostreams::filtering_istream configFileStream; boost::iostreams::filtering_istream configFileStream;
configFileStream.push(escape_hash_filter()); configFileStream.push(escape_hash_filter());
configFileStream.push(configFileStreamUnfiltered); configFileStream.push(configFileStreamUnfiltered);
boost::iostreams::filtering_istream dummyStreamThatShouldMakeOtherCodeCompile;
dummyStreamThatShouldMakeOtherCodeCompile.push(unescape_hash_filter());
if (configFileStreamUnfiltered.is_open()) if (configFileStreamUnfiltered.is_open())
{ {
boost::program_options::store(boost::program_options::parse_config_file( boost::program_options::store(boost::program_options::parse_config_file(
@ -167,10 +164,6 @@ bool ConfigurationManager::loadConfig(const boost::filesystem::path& path,
return false; 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) 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 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, "#"); std::string temp = boost::replace_all_copy<std::string>(str, std::string() + (char)escape_hash_filter::sEscape + (char)escape_hash_filter::sHashIdentifier, "#");

View file

@ -71,9 +71,9 @@ struct ConfigurationManager
*/ */
struct escape_hash_filter : public boost::iostreams::input_filter struct escape_hash_filter : public boost::iostreams::input_filter
{ {
static const int sEscape; static const int sEscape = '@';
static const int sHashIdentifier; static const int sHashIdentifier = 'h';
static const int sEscapeIdentifier; static const int sEscapeIdentifier = 'a';
escape_hash_filter(); escape_hash_filter();
virtual ~escape_hash_filter(); virtual ~escape_hash_filter();
@ -99,6 +99,43 @@ struct unescape_hash_filter : public boost::iostreams::input_filter
bool expectingIdentifier; 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 * \class EscapeHashString
*/ */