Eliminated the need for boost::xpressive, boost::algorithm and boost::variant

This commit is contained in:
Tomas Jakobsson 2017-11-29 20:57:43 +01:00
parent b8dd51ddf4
commit 5e8d6b7f45
10 changed files with 93 additions and 44 deletions

View file

@ -1,6 +1,7 @@
#include "CollectionSystemManager.h"
#include "guis/GuiInfoPopup.h"
#include "utils/StringUtil.h"
#include "views/gamelist/IGameListView.h"
#include "views/ViewController.h"
#include "FileData.h"
@ -10,9 +11,7 @@
#include "SystemData.h"
#include "ThemeData.h"
#include "Util.h"
#include <boost/algorithm/string/predicate.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/xpressive/xpressive.hpp>
#include <pugixml/src/pugixml.hpp>
#include <fstream>
#include <unordered_map>
@ -351,26 +350,33 @@ bool CollectionSystemManager::isThemeCustomCollectionCompatible(std::vector<std:
std::string CollectionSystemManager::getValidNewCollectionName(std::string inName, int index)
{
// filter name - [^A-Za-z0-9\[\]\(\)\s]
using namespace boost::xpressive;
std::string name;
sregex regexp = sregex::compile("[^A-Za-z0-9\\-\\[\\]\\(\\)\\s']");
if (index == 0)
std::string name = inName;
if(index == 0)
{
name = regex_replace(inName, regexp, "");
if (name == "")
size_t remove = std::string::npos;
// get valid name
while((remove = name.find_first_not_of("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-[]() ")) != std::string::npos)
{
name = "New Collection";
name.erase(remove, 1);
}
}
else
{
name = inName + " (" + std::to_string(index) + ")";
name += " (" + std::to_string(index) + ")";
}
if(name == "")
{
name = "New Collection";
}
if(name != inName)
{
LOG(LogInfo) << "Had to change name, from: " << inName << " to: " << name;
}
// get used systems in es_systems.cfg
std::vector<std::string> systemsInUse = getSystemsFromConfig();
// get folders assigned to custom collections
@ -948,7 +954,7 @@ std::vector<std::string> CollectionSystemManager::getCollectionsFromConfigFolder
std::string filename = file.substr(configPath.string().size());
// need to confirm filename matches config format
if (boost::algorithm::ends_with(filename, ".cfg") && boost::algorithm::starts_with(filename, "custom-") && filename != "custom-.cfg")
if (filename != "custom-.cfg" && Utils::String::startsWith(filename, "custom-") && Utils::String::endsWith(filename, ".cfg"))
{
filename = filename.substr(7, filename.size()-11);
systems.push_back(filename);

View file

@ -1,5 +1,6 @@
#include "FileData.h"
#include "utils/StringUtil.h"
#include "utils/TimeUtil.h"
#include "AudioManager.h"
#include "CollectionSystemManager.h"
@ -11,7 +12,6 @@
#include "Util.h"
#include "VolumeControl.h"
#include "Window.h"
#include <boost/algorithm/string/trim.hpp>
#include <boost/filesystem/operations.hpp>
namespace fs = boost::filesystem;
@ -327,7 +327,7 @@ const std::string& CollectionFileData::getName()
{
if (mDirty) {
mCollectionFileName = removeParenthesis(mSourceFileData->metadata.get("name"));
boost::trim(mCollectionFileName);
Utils::String::trim(mCollectionFileName);
mCollectionFileName += " [" + strToUpper(mSourceFileData->getSystem()->getName()) + "]";
mDirty = false;
}

View file

@ -1,11 +1,11 @@
#include "FileFilterIndex.h"
#include "utils/StringUtil.h"
#include "views/UIModeController.h"
#include "FileData.h"
#include "Log.h"
#include "Settings.h"
#include "Util.h"
#include <boost/algorithm/string/trim.hpp>
#define UNKNOWN_LABEL "UNKNOWN"
#define INCLUDE_UNKNOWN false;
@ -94,7 +94,7 @@ std::string FileFilterIndex::getIndexableKey(FileData* game, FilterIndexType typ
case GENRE_FILTER:
{
key = strToUpper(game->metadata.get("genre"));
boost::trim(key);
Utils::String::trim(key);
if (getSecondary && !key.empty()) {
std::istringstream f(key);
std::string newKey;
@ -121,7 +121,7 @@ std::string FileFilterIndex::getIndexableKey(FileData* game, FilterIndexType typ
case PUBDEV_FILTER:
{
key = strToUpper(game->metadata.get("publisher"));
boost::trim(key);
Utils::String::trim(key);
if ((getSecondary && !key.empty()) || (!getSecondary && key.empty()))
key = strToUpper(game->metadata.get("developer"));
@ -173,7 +173,7 @@ std::string FileFilterIndex::getIndexableKey(FileData* game, FilterIndexType typ
break;
}
}
boost::trim(key);
Utils::String::trim(key);
if (key.empty() || (type == RATINGS_FILTER && key == "0 STARS")) {
key = UNKNOWN_LABEL;
}

View file

@ -2,7 +2,6 @@
#ifndef ES_APP_VIEWS_UI_MODE_CONTROLLER_H
#define ES_APP_VIEWS_UI_MODE_CONTROLLER_H
//#include "InputConfig.h"
#include <vector>
#include <string>

View file

@ -6,7 +6,6 @@
#include "platform.h"
#include "Settings.h"
#include <boost/filesystem/operations.hpp>
#include <boost/xpressive/xpressive_static.hpp>
#include <pugixml/src/pugixml.hpp>
std::vector<std::string> ThemeData::sSupportedViews { { "system" }, { "basic" }, { "detailed" }, { "video" } };
@ -176,24 +175,24 @@ std::string resolvePath(const char* in, const fs::path& relative)
std::map<std::string, std::string> mVariables;
std::string &format_variables(const boost::xpressive::smatch &what)
{
return mVariables[what[1].str()];
}
std::string resolvePlaceholders(const char* in)
{
if(!in || in[0] == '\0')
return std::string(in);
std::string inStr(in);
using namespace boost::xpressive;
sregex rex = "${" >> (s1 = +('.' | _w)) >> '}';
if(inStr.empty())
return inStr;
std::string output = regex_replace(inStr, rex, format_variables);
const size_t variableBegin = inStr.find("${");
const size_t variableEnd = inStr.find("}", variableBegin);
return output;
if((variableBegin == std::string::npos) || (variableEnd == std::string::npos))
return inStr;
std::string prefix = inStr.substr(0, variableBegin);
std::string replace = inStr.substr(variableBegin + 2, variableEnd - (variableBegin + 2));
std::string suffix = inStr.substr(variableEnd + 1);
return prefix + mVariables[replace] + suffix;
}
ThemeData::ThemeData()

View file

@ -4,8 +4,6 @@
#include "math/Vector2f.h"
#include <boost/filesystem/path.hpp>
#include <boost/variant/get.hpp>
#include <boost/variant/variant.hpp>
#include <deque>
#include <map>
#include <sstream>
@ -91,10 +89,33 @@ public:
bool extra;
std::string type;
std::map< std::string, boost::variant<Vector2f, std::string, unsigned int, float, bool> > properties;
struct Property
{
void operator= (const Vector2f& value) { v = value; }
void operator= (const std::string& value) { s = value; }
void operator= (const unsigned int& value) { i = value; }
void operator= (const float& value) { f = value; }
void operator= (const bool& value) { b = value; }
Vector2f v;
std::string s;
unsigned int i;
float f;
bool b;
};
std::map< std::string, Property > properties;
template<typename T>
T get(const std::string& prop) const { return boost::get<T>(properties.at(prop)); }
const T get(const std::string& prop) const
{
if( std::is_same<T, Vector2f>::value) return *(const T*)&properties.at(prop).v;
else if(std::is_same<T, std::string>::value) return *(const T*)&properties.at(prop).s;
else if(std::is_same<T, unsigned int>::value) return *(const T*)&properties.at(prop).i;
else if(std::is_same<T, float>::value) return *(const T*)&properties.at(prop).f;
else if(std::is_same<T, bool>::value) return *(const T*)&properties.at(prop).b;
return T();
}
inline bool has(const std::string& prop) const { return (properties.find(prop) != properties.cend()); }
};

View file

@ -1,8 +1,6 @@
#include "Util.h"
#include "platform.h"
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/filesystem/operations.hpp>
namespace fs = boost::filesystem;
@ -248,8 +246,20 @@ std::vector<std::string> commaStringToVector(std::string commaString)
{
// from a comma separated string, get a vector of strings
std::vector<std::string> strs;
boost::split(strs, commaString, boost::is_any_of(","));
std::sort(strs.begin(), strs.end());
size_t start = 0;
size_t comma = commaString.find(",");
strs.push_back(commaString.substr(start, comma));
if(comma != std::string::npos)
{
start = comma + 1;
while((comma = commaString.find(",", start)) != std::string::npos)
{
strs.push_back(commaString.substr(start, comma - start));
start = comma + 1;
}
strs.push_back(commaString.substr(start));
std::sort(strs.begin(), strs.end());
}
return strs;
}

View file

@ -1,9 +1,9 @@
#ifdef _RPI_
#include "components/VideoPlayerComponent.h"
#include "utils/StringUtil.h"
#include "AudioManager.h"
#include "Settings.h"
#include <boost/algorithm/string/predicate.hpp>
#include <fcntl.h>
#include <wait.h>
@ -68,7 +68,7 @@ void VideoPlayerComponent::startVideo()
mPlayingVideoPath = mVideoPath;
// Disable AudioManager so video can play, in case we're requesting ALSA
if (boost::starts_with(Settings::getInstance()->getString("OMXAudioDev").c_str(), "alsa"))
if (Utils::String::startsWith(Settings::getInstance()->getString("OMXAudioDev").c_str(), "alsa"))
{
AudioManager::getInstance()->deinit();
}

View file

@ -144,6 +144,18 @@ namespace Utils
} // trim
bool startsWith(const std::string& _string, const std::string& _test)
{
return (_string.find(_test) == 0);
} // startsWith
bool endsWith(const std::string& _string, const std::string& _test)
{
return (_string.find(_test) == (_string.size() - _test.size()));
} // endsWith
} // String::
} // Utils::

View file

@ -14,6 +14,8 @@ namespace Utils
size_t prevCursor (const std::string& _string, const size_t _cursor);
size_t moveCursor (const std::string& _string, const size_t _cursor, const int _amount);
std::string trim (const std::string& _path);
bool startsWith (const std::string& _string, const std::string& _test);
bool endsWith (const std::string& _string, const std::string& _test);
} // Utils::String::