Replace filesystem::ends_with
with boost::algorithm::ends_with
The former had nothing to do with fs functionality at all.
This commit is contained in:
parent
2f85001897
commit
0a9d351fe2
6 changed files with 7 additions and 19 deletions
|
@ -29,6 +29,7 @@
|
|||
#include "serialization/unicode.hpp"
|
||||
#include "utils/general.hpp"
|
||||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
#include <boost/iostreams/device/file_descriptor.hpp>
|
||||
|
@ -520,7 +521,7 @@ void get_files_in_dir(const std::string& dir,
|
|||
if(files != nullptr && reorder == reorder_mode::DO_REORDER) {
|
||||
// move finalcfg_filename, if present, to the end of the vector
|
||||
for(unsigned int i = 0; i < files->size(); i++) {
|
||||
if(ends_with((*files)[i], "/" + finalcfg_filename)) {
|
||||
if(boost::algorithm::ends_with((*files)[i], "/" + finalcfg_filename)) {
|
||||
files->push_back((*files)[i]);
|
||||
files->erase(files->begin() + i);
|
||||
break;
|
||||
|
@ -530,7 +531,7 @@ void get_files_in_dir(const std::string& dir,
|
|||
// move initialcfg_filename, if present, to the beginning of the vector
|
||||
int foundit = -1;
|
||||
for(unsigned int i = 0; i < files->size(); i++)
|
||||
if(ends_with((*files)[i], "/" + initialcfg_filename)) {
|
||||
if(boost::algorithm::ends_with((*files)[i], "/" + initialcfg_filename)) {
|
||||
foundit = i;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -327,8 +327,6 @@ int file_size(const std::string& fname);
|
|||
/** Returns the sum of the sizes of the files contained in a directory. */
|
||||
int dir_size(const std::string& path);
|
||||
|
||||
bool ends_with(const std::string& str, const std::string& suffix);
|
||||
|
||||
/**
|
||||
* Returns the base filename of a file, with directory name stripped.
|
||||
* Equivalent to a portable basename() function.
|
||||
|
|
|
@ -291,15 +291,6 @@ bool file_tree_checksum::operator==(const file_tree_checksum &rhs) const
|
|||
modified == rhs.modified;
|
||||
}
|
||||
|
||||
bool ends_with(const std::string& str, const std::string& suffix)
|
||||
{
|
||||
#ifdef __cpp_lib_starts_ends_with
|
||||
return str.ends_with(suffix);
|
||||
#else
|
||||
return str.size() >= suffix.size() && std::equal(suffix.begin(),suffix.end(),str.end()-suffix.size());
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string read_map(const std::string& name)
|
||||
{
|
||||
std::string res;
|
||||
|
|
|
@ -354,7 +354,7 @@ static surface load_image_file(const image::locator& loc)
|
|||
// but the old filename may still be saved in savegame files etc.
|
||||
// If the file does not exist in ".png" format, also try ".webp".
|
||||
// Similarly for ".jpg", which conveniently has the same number of letters as ".png".
|
||||
if(!location && (filesystem::ends_with(name, ".png") || filesystem::ends_with(name, ".jpg"))) {
|
||||
if(!location && (boost::algorithm::ends_with(name, ".png") || boost::algorithm::ends_with(name, ".jpg"))) {
|
||||
std::string webp_name = name.substr(0, name.size() - 4) + ".webp";
|
||||
location = filesystem::get_binary_file_location("images", webp_name);
|
||||
if(location) {
|
||||
|
@ -932,14 +932,14 @@ save_result save_image(const surface& surf, const std::string& filename)
|
|||
return save_result::no_image;
|
||||
}
|
||||
|
||||
if(filesystem::ends_with(filename, ".jpeg") || filesystem::ends_with(filename, ".jpg") || filesystem::ends_with(filename, ".jpe")) {
|
||||
if(boost::algorithm::ends_with(filename, ".jpeg") || boost::algorithm::ends_with(filename, ".jpg") || boost::algorithm::ends_with(filename, ".jpe")) {
|
||||
LOG_IMG << "Writing a JPG image to " << filename;
|
||||
|
||||
const int err = IMG_SaveJPG_RW(surf, filesystem::make_write_RWops(filename).release(), true, 75); // SDL takes ownership of the RWops
|
||||
return err == 0 ? save_result::success : save_result::save_failed;
|
||||
}
|
||||
|
||||
if(filesystem::ends_with(filename, ".png")) {
|
||||
if(boost::algorithm::ends_with(filename, ".png")) {
|
||||
LOG_IMG << "Writing a PNG image to " << filename;
|
||||
|
||||
const int err = IMG_SavePNG_RW(surf, filesystem::make_write_RWops(filename).release(), true); // SDL takes ownership of the RWops
|
||||
|
|
|
@ -107,7 +107,7 @@ void find_translations(const config& base_dir, config& addon)
|
|||
{
|
||||
for(const config& file : base_dir.child_range("file")) {
|
||||
const std::string& fn = file["name"].str();
|
||||
if(filesystem::ends_with(fn, ".po")) {
|
||||
if(boost::algorithm::ends_with(fn, ".po")) {
|
||||
support_translation(addon, filesystem::base_name(fn, true));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -215,8 +215,6 @@ BOOST_AUTO_TEST_CASE( test_fs_search )
|
|||
|
||||
BOOST_AUTO_TEST_CASE( test_fs_fluff )
|
||||
{
|
||||
BOOST_CHECK( ends_with("foobarbazbat", "bazbat") );
|
||||
|
||||
BOOST_CHECK( looks_like_pbl("foo.pbl") );
|
||||
BOOST_CHECK( looks_like_pbl("FOO.PBL") );
|
||||
BOOST_CHECK( looks_like_pbl("Foo.Pbl") );
|
||||
|
|
Loading…
Add table
Reference in a new issue