mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 18:19:55 +00:00
Merge pull request #1541 from astillich/4189
Fixed escaping @ in boost program options filter
This commit is contained in:
commit
a5ba1caed1
3 changed files with 41 additions and 10 deletions
|
@ -1,6 +1,6 @@
|
||||||
#include "escape.hpp"
|
#include "escape.hpp"
|
||||||
|
|
||||||
#include <boost/algorithm/string/replace.hpp>
|
#include <components/misc/stringops.hpp>
|
||||||
|
|
||||||
namespace Files
|
namespace Files
|
||||||
{
|
{
|
||||||
|
@ -8,7 +8,7 @@ namespace Files
|
||||||
const int escape_hash_filter::sEscapeIdentifier = 'a';
|
const int escape_hash_filter::sEscapeIdentifier = 'a';
|
||||||
const int escape_hash_filter::sHashIdentifier = 'h';
|
const int escape_hash_filter::sHashIdentifier = 'h';
|
||||||
|
|
||||||
escape_hash_filter::escape_hash_filter() : mNext(), mPrevious(), mSeenNonWhitespace(false), mFinishLine(false)
|
escape_hash_filter::escape_hash_filter() : mSeenNonWhitespace(false), mFinishLine(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,8 +26,14 @@ namespace Files
|
||||||
|
|
||||||
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 = str;
|
||||||
boost::replace_all(temp, std::string() + (char)escape_hash_filter::sEscape + (char)escape_hash_filter::sEscapeIdentifier, std::string((char)escape_hash_filter::sEscape, 1));
|
|
||||||
|
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;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,6 @@ namespace Files
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::queue<int> mNext;
|
std::queue<int> mNext;
|
||||||
int mPrevious;
|
|
||||||
|
|
||||||
bool mSeenNonWhitespace;
|
bool mSeenNonWhitespace;
|
||||||
bool mFinishLine;
|
bool mFinishLine;
|
||||||
|
@ -42,11 +41,9 @@ namespace Files
|
||||||
if (mNext.empty())
|
if (mNext.empty())
|
||||||
{
|
{
|
||||||
int character = boost::iostreams::get(src);
|
int character = boost::iostreams::get(src);
|
||||||
bool record = true;
|
|
||||||
if (character == boost::iostreams::WOULD_BLOCK)
|
if (character == boost::iostreams::WOULD_BLOCK)
|
||||||
{
|
{
|
||||||
mNext.push(character);
|
mNext.push(character);
|
||||||
record = false;
|
|
||||||
}
|
}
|
||||||
else if (character == EOF)
|
else if (character == EOF)
|
||||||
{
|
{
|
||||||
|
@ -78,7 +75,7 @@ namespace Files
|
||||||
mFinishLine = true;
|
mFinishLine = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (mPrevious == sEscape)
|
else if (character == sEscape)
|
||||||
{
|
{
|
||||||
mNext.push(sEscape);
|
mNext.push(sEscape);
|
||||||
mNext.push(sEscapeIdentifier);
|
mNext.push(sEscapeIdentifier);
|
||||||
|
@ -89,8 +86,6 @@ namespace Files
|
||||||
}
|
}
|
||||||
if (!mSeenNonWhitespace && !isspace(character))
|
if (!mSeenNonWhitespace && !isspace(character))
|
||||||
mSeenNonWhitespace = true;
|
mSeenNonWhitespace = true;
|
||||||
if (record)
|
|
||||||
mPrevious = character;
|
|
||||||
}
|
}
|
||||||
int retval = mNext.front();
|
int retval = mNext.front();
|
||||||
mNext.pop();
|
mNext.pop();
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define MISC_STRINGOPS_H
|
#define MISC_STRINGOPS_H
|
||||||
|
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
#include <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
@ -138,6 +139,35 @@ public:
|
||||||
|
|
||||||
return notFound;
|
return notFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @brief Replaces all occurrences of a string in another string.
|
||||||
|
*
|
||||||
|
* @param str The string to operate on.
|
||||||
|
* @param what The string to replace.
|
||||||
|
* @param with The replacement string.
|
||||||
|
* @param whatLen The length of the string to replace.
|
||||||
|
* @param withLen The length of the replacement string.
|
||||||
|
*
|
||||||
|
* @return A reference to the string passed in @p str.
|
||||||
|
*/
|
||||||
|
static std::string &replaceAll(std::string &str, const char *what, const char *with,
|
||||||
|
std::size_t whatLen=std::string::npos, std::size_t withLen=std::string::npos)
|
||||||
|
{
|
||||||
|
if (whatLen == std::string::npos)
|
||||||
|
whatLen = strlen(what);
|
||||||
|
|
||||||
|
if (withLen == std::string::npos)
|
||||||
|
withLen = strlen(with);
|
||||||
|
|
||||||
|
std::size_t found;
|
||||||
|
std::size_t offset = 0;
|
||||||
|
while((found = str.find(what, offset, whatLen)) != std::string::npos)
|
||||||
|
{
|
||||||
|
str.replace(found, whatLen, with, withLen);
|
||||||
|
offset = found + withLen;
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue