35 lines
1,014 B
C++
35 lines
1,014 B
C++
|
#include "resourceloc.hpp"
|
||
|
#include <boost/algorithm/string/split.hpp>
|
||
|
#include <boost/algorithm/string/trim.hpp>
|
||
|
#include <boost/format.hpp>
|
||
|
#include <boost/log/trivial.hpp>
|
||
|
#include <iostream>
|
||
|
#include <sstream>
|
||
|
#include <string>
|
||
|
#include <vector>
|
||
|
|
||
|
namespace resourceloc {
|
||
|
std::string resolve(std::string inp) {
|
||
|
boost::algorithm::trim_if(inp, boost::is_any_of(" \n\r\""));
|
||
|
|
||
|
std::vector<std::string> components;
|
||
|
boost::algorithm::split(components, inp, boost::is_any_of("/"));
|
||
|
|
||
|
if (components.size() < 3 || components[0] != "" || components[1] != "mods") {
|
||
|
BOOST_LOG_TRIVIAL(warning) << "invalid resourceloc";
|
||
|
return "<invalid>";
|
||
|
}
|
||
|
|
||
|
std::string path_component;
|
||
|
for (unsigned int i = 3; i < components.size(); i++) {
|
||
|
path_component += components[i];
|
||
|
if (i != components.size() - 1) {
|
||
|
path_component += "/";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return boost::str(boost::format("new ResourceLocation(\"%1%\", \"%2%\")") %
|
||
|
components[2] % path_component);
|
||
|
}
|
||
|
} // namespace resourceloc
|