From 9be606a40de19ea7636694beda2f8790f605774b Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Sun, 17 Oct 2021 23:40:34 +0100 Subject: [PATCH] Finish removing old Escape classes --- apps/openmw/main.cpp | 1 - apps/openmw/options.cpp | 2 +- apps/openmw_test_suite/mwworld/test_store.cpp | 1 - apps/openmw_test_suite/openmw/options.cpp | 1 - components/CMakeLists.txt | 2 +- components/fallback/validate.cpp | 9 +- components/fallback/validate.hpp | 2 - components/files/configurationmanager.cpp | 1 - components/files/escape.cpp | 145 ------------- components/files/escape.hpp | 191 ------------------ 10 files changed, 6 insertions(+), 349 deletions(-) delete mode 100644 components/files/escape.cpp delete mode 100644 components/files/escape.hpp diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 18b1ab267f..7a3a21b149 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include #include diff --git a/apps/openmw/options.cpp b/apps/openmw/options.cpp index 167c275598..dd94590f2a 100644 --- a/apps/openmw/options.cpp +++ b/apps/openmw/options.cpp @@ -1,7 +1,7 @@ #include "options.hpp" #include -#include +#include #include #include diff --git a/apps/openmw_test_suite/mwworld/test_store.cpp b/apps/openmw_test_suite/mwworld/test_store.cpp index 13a9ebee9c..9aa5a6758f 100644 --- a/apps/openmw_test_suite/mwworld/test_store.cpp +++ b/apps/openmw_test_suite/mwworld/test_store.cpp @@ -3,7 +3,6 @@ #include #include -#include #include #include #include diff --git a/apps/openmw_test_suite/openmw/options.cpp b/apps/openmw_test_suite/openmw/options.cpp index b087fd03fb..7cf0df1066 100644 --- a/apps/openmw_test_suite/openmw/options.cpp +++ b/apps/openmw_test_suite/openmw/options.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index b9db26dbc1..b61ba11466 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -104,7 +104,7 @@ IF(NOT WIN32 AND NOT APPLE) add_definitions(-DGLOBAL_CONFIG_PATH="${GLOBAL_CONFIG_PATH}") ENDIF() add_component_dir (files - linuxpath androidpath windowspath macospath fixedpath multidircollection collections configurationmanager escape + linuxpath androidpath windowspath macospath fixedpath multidircollection collections configurationmanager lowlevelfile constrainedfilestream memorystream configfileparser ) diff --git a/components/fallback/validate.cpp b/components/fallback/validate.cpp index a482d40faf..6f5d529e05 100644 --- a/components/fallback/validate.cpp +++ b/components/fallback/validate.cpp @@ -11,13 +11,12 @@ void Fallback::validate(boost::any& v, std::vector const& tokens, F for (const auto& token : tokens) { - std::string temp = Files::EscapeHashString::processString(token); - size_t sep = temp.find(','); - if (sep < 1 || sep == temp.length() - 1 || sep == std::string::npos) + size_t sep = token.find(','); + if (sep < 1 || sep == token.length() - 1 || sep == std::string::npos) throw boost::program_options::validation_error(boost::program_options::validation_error::invalid_option_value); - std::string key(temp.substr(0, sep)); - std::string value(temp.substr(sep + 1)); + std::string key(token.substr(0, sep)); + std::string value(token.substr(sep + 1)); map->mMap[key] = value; } diff --git a/components/fallback/validate.hpp b/components/fallback/validate.hpp index 96690f50a5..2b9af88da2 100644 --- a/components/fallback/validate.hpp +++ b/components/fallback/validate.hpp @@ -3,8 +3,6 @@ #include -#include - // Parses and validates a fallback map from boost program_options. // Note: for boost to pick up the validate function, you need to pull in the namespace e.g. // by using namespace Fallback; diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index dad52a7ee4..23c25fd413 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -2,7 +2,6 @@ #include #include -#include #include #include diff --git a/components/files/escape.cpp b/components/files/escape.cpp deleted file mode 100644 index 8b11504d34..0000000000 --- a/components/files/escape.cpp +++ /dev/null @@ -1,145 +0,0 @@ -#include "escape.hpp" - -#include - -namespace Files -{ - 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() : mSeenNonWhitespace(false), mFinishLine(false) - { - } - - escape_hash_filter::~escape_hash_filter() - { - } - - unescape_hash_filter::unescape_hash_filter() : expectingIdentifier(false) - { - } - - unescape_hash_filter::~unescape_hash_filter() - { - } - - std::string EscapeHashString::processString(const std::string & str) - { - std::string temp = str; - - static const char hash[] = { escape_hash_filter::sEscape, escape_hash_filter::sHashIdentifier }; - Misc::StringUtils::replaceAll(temp, hash, "#", 2, 1); - - static const char escape[] = { escape_hash_filter::sEscape, escape_hash_filter::sEscapeIdentifier }; - Misc::StringUtils::replaceAll(temp, escape, "@", 2, 1); - - return temp; - } - - EscapeHashString::EscapeHashString() : mData() - { - } - - EscapeHashString::EscapeHashString(const std::string & str) : mData(EscapeHashString::processString(str)) - { - } - - EscapeHashString::EscapeHashString(const std::string & str, size_t pos, size_t len) : mData(EscapeHashString::processString(str), pos, len) - { - } - - EscapeHashString::EscapeHashString(const char * s) : mData(EscapeHashString::processString(std::string(s))) - { - } - - EscapeHashString::EscapeHashString(const char * s, size_t n) : mData(EscapeHashString::processString(std::string(s)), 0, n) - { - } - - EscapeHashString::EscapeHashString(size_t n, char c) : mData(n, c) - { - } - - template - EscapeHashString::EscapeHashString(InputIterator first, InputIterator last) : mData(EscapeHashString::processString(std::string(first, last))) - { - } - - std::string EscapeHashString::toStdString() const - { - return std::string(mData); - } - - std::istream & operator>> (std::istream & is, EscapeHashString & eHS) - { - std::string temp; - is >> temp; - eHS = EscapeHashString(temp); - return is; - } - - std::ostream & operator<< (std::ostream & os, const EscapeHashString & eHS) - { - os << eHS.mData; - return os; - } - - EscapeStringVector::EscapeStringVector() : mVector() - { - } - - EscapeStringVector::~EscapeStringVector() - { - } - - std::vector EscapeStringVector::toStdStringVector() const - { - std::vector temp = std::vector(); - for (std::vector::const_iterator it = mVector.begin(); it != mVector.end(); ++it) - { - temp.push_back(it->toStdString()); - } - return temp; - } - - // boost program options validation - - void validate(boost::any &v, const std::vector &tokens, Files::EscapeHashString * eHS, int a) - { - boost::program_options::validators::check_first_occurrence(v); - - if (v.empty()) - v = boost::any(EscapeHashString(boost::program_options::validators::get_single_string(tokens))); - } - - void validate(boost::any &v, const std::vector &tokens, EscapeStringVector *, int) - { - if (v.empty()) - v = boost::any(EscapeStringVector()); - - EscapeStringVector * eSV = boost::any_cast(&v); - - for (std::vector::const_iterator it = tokens.begin(); it != tokens.end(); ++it) - eSV->mVector.emplace_back(*it); - } - - PathContainer EscapePath::toPathContainer(const EscapePathContainer & escapePathContainer) - { - PathContainer temp; - for (EscapePathContainer::const_iterator it = escapePathContainer.begin(); it != escapePathContainer.end(); ++it) - temp.push_back(it->mPath); - return temp; - } - - std::istream & operator>> (std::istream & istream, EscapePath & escapePath) - { - boost::iostreams::filtering_istream filteredStream; - filteredStream.push(unescape_hash_filter()); - filteredStream.push(istream); - - filteredStream >> escapePath.mPath; - - return istream; - } -} diff --git a/components/files/escape.hpp b/components/files/escape.hpp deleted file mode 100644 index d01bd8d980..0000000000 --- a/components/files/escape.hpp +++ /dev/null @@ -1,191 +0,0 @@ -#ifndef COMPONENTS_FILES_ESCAPE_HPP -#define COMPONENTS_FILES_ESCAPE_HPP - -#include - -#include - -#include -#include -#include - -/** - * \namespace Files - */ -namespace Files -{ - /** - * \struct escape_hash_filter - */ - struct escape_hash_filter : public boost::iostreams::input_filter - { - static const int sEscape; - static const int sHashIdentifier; - static const int sEscapeIdentifier; - - escape_hash_filter(); - virtual ~escape_hash_filter(); - - template int get(Source & src); - - private: - std::queue mNext; - - bool mSeenNonWhitespace; - bool mFinishLine; - }; - - template - int escape_hash_filter::get(Source & src) - { - if (mNext.empty()) - { - int character = boost::iostreams::get(src); - if (character == boost::iostreams::WOULD_BLOCK) - { - mNext.push(character); - } - else if (character == EOF) - { - mSeenNonWhitespace = false; - mFinishLine = false; - mNext.push(character); - } - else if (character == '\n') - { - mSeenNonWhitespace = false; - mFinishLine = false; - mNext.push(character); - } - else if (mFinishLine) - { - mNext.push(character); - } - else if (character == '#') - { - if (mSeenNonWhitespace) - { - mNext.push(sEscape); - mNext.push(sHashIdentifier); - } - else - { - //it's fine being interpreted by Boost as a comment, and so is anything afterwards - mNext.push(character); - mFinishLine = true; - } - } - else if (character == sEscape) - { - mNext.push(sEscape); - mNext.push(sEscapeIdentifier); - } - else - { - mNext.push(character); - } - if (!mSeenNonWhitespace && !isspace(character)) - mSeenNonWhitespace = true; - } - int retval = mNext.front(); - mNext.pop(); - return retval; - } - - struct unescape_hash_filter : public boost::iostreams::input_filter - { - unescape_hash_filter(); - virtual ~unescape_hash_filter(); - - template int get(Source & src); - - private: - 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; - if (nextChar == escape_hash_filter::sEscapeIdentifier) - intended = escape_hash_filter::sEscape; - else if (nextChar == escape_hash_filter::sHashIdentifier) - intended = '#'; - else if (nextChar == boost::iostreams::WOULD_BLOCK) - { - expectingIdentifier = true; - intended = nextChar; - } - else - intended = '?'; - return intended; - } - else - return character; - } - - /** - * \class EscapeHashString - */ - class EscapeHashString - { - private: - std::string mData; - public: - static std::string processString(const std::string & str); - - EscapeHashString(); - EscapeHashString(const std::string & str); - EscapeHashString(const std::string & str, size_t pos, size_t len = std::string::npos); - EscapeHashString(const char * s); - EscapeHashString(const char * s, size_t n); - EscapeHashString(size_t n, char c); - template - EscapeHashString(InputIterator first, InputIterator last); - - std::string toStdString() const; - - friend std::ostream & operator<< (std::ostream & os, const EscapeHashString & eHS); - }; - - std::istream & operator>> (std::istream & is, EscapeHashString & eHS); - - struct EscapeStringVector - { - std::vector mVector; - - EscapeStringVector(); - virtual ~EscapeStringVector(); - - std::vector toStdStringVector() const; - }; - - //boost program options validation - - void validate(boost::any &v, const std::vector &tokens, Files::EscapeHashString * eHS, int a); - - void validate(boost::any &v, const std::vector &tokens, EscapeStringVector *, int); - - struct EscapePath - { - boost::filesystem::path mPath; - - static PathContainer toPathContainer(const std::vector & escapePathContainer); - }; - - typedef std::vector EscapePathContainer; - - std::istream & operator>> (std::istream & istream, EscapePath & escapePath); -} /* namespace Files */ -#endif /* COMPONENTS_FILES_ESCAPE_HPP */