From b299ae9f9107320d13fa84a497889a7b4bea1456 Mon Sep 17 00:00:00 2001 From: Pierre Dejoue Date: Fri, 22 Dec 2023 15:53:09 +0100 Subject: [PATCH] Update to latest stdutils::string changes --- src/cli/src/main.cpp | 3 ++- src/gui/src/picross_file.cpp | 5 +++-- src/utils/src/bitmap_io.cpp | 5 ++--- src/utils/src/picross_file_io.cpp | 12 +++++++----- src/utils/src/text_io.cpp | 6 +++--- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/cli/src/main.cpp b/src/cli/src/main.cpp index 3135efe..3ff724e 100644 --- a/src/cli/src/main.cpp +++ b/src/cli/src/main.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -223,7 +224,7 @@ int main(int argc, char *argv[]) for (const char* filepath : args.pos) { ValidationModeData file_data; - file_data.filename = stdutils::string::filename(filepath); + file_data.filename = std::filesystem::path(filepath).filename().string(); const picross::io::ErrorHandler err_handler_classic = [&return_status, &file_data](picross::io::ErrorCodeT code, std::string_view msg) { diff --git a/src/gui/src/picross_file.cpp b/src/gui/src/picross_file.cpp index 2d677ba..6b229b3 100644 --- a/src/gui/src/picross_file.cpp +++ b/src/gui/src/picross_file.cpp @@ -1,9 +1,9 @@ #include "picross_file.h" #include -#include #include +#include #include #include @@ -30,9 +30,10 @@ void PicrossFile::visit_windows(bool& can_be_erased, Settings& settings) std::optional goal; std::vector grids_to_solve = picross::io::parse_picross_file(file_path, file_format, err_handler); windows.reserve(grids_to_solve.size()); + const auto source_file = std::filesystem::path(file_path).filename().string(); for (auto& io_grid : grids_to_solve) { - windows.push_back(std::make_unique(std::move(io_grid), stdutils::string::filename(file_path))); + windows.push_back(std::make_unique(std::move(io_grid), source_file)); } } else diff --git a/src/utils/src/bitmap_io.cpp b/src/utils/src/bitmap_io.cpp index 0069a10..80bf303 100644 --- a/src/utils/src/bitmap_io.cpp +++ b/src/utils/src/bitmap_io.cpp @@ -1,12 +1,11 @@ #include -#include - #include #include #include #include +#include picross::OutputGrid import_bitmap_pbm(const std::string& filepath, const picross::io::ErrorHandler& error_handler) noexcept @@ -14,7 +13,7 @@ picross::OutputGrid import_bitmap_pbm(const std::string& filepath, const picross try { const pnm::pbm_image bitmap = pnm::read_pbm(filepath); - const auto grid_name = stdutils::string::filename_wo_extension(filepath); + const auto grid_name = std::filesystem::path(filepath).stem().string(); picross::OutputGrid output_grid(bitmap.width(), bitmap.height(), picross::Tile::UNKNOWN, grid_name); std::size_t y = 0u; for (const auto& line : bitmap.lines()) diff --git a/src/utils/src/picross_file_io.cpp b/src/utils/src/picross_file_io.cpp index 0a6b06f..72cb706 100644 --- a/src/utils/src/picross_file_io.cpp +++ b/src/utils/src/picross_file_io.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -44,17 +45,18 @@ std::ostream& operator<<(std::ostream& out, PicrossFileFormat format) PicrossFileFormat picross_file_format_from_filepath(std::string_view filepath) { - std::string ext = stdutils::string::file_extension(filepath); - ext = stdutils::string::tolower(ext); - if (ext == "nin") + std::string ext = stdutils::string::tolower( + std::filesystem::path(filepath).extension().string() + ); + if (ext == ".nin") { return PicrossFileFormat::NIN; } - else if (ext == "non") + else if (ext == ".non") { return PicrossFileFormat::NON; } - else if (ext == "pbm") + else if (ext == ".pbm") { return PicrossFileFormat::PBM; } diff --git a/src/utils/src/text_io.cpp b/src/utils/src/text_io.cpp index 4a54a77..a2ae0fe 100644 --- a/src/utils/src/text_io.cpp +++ b/src/utils/src/text_io.cpp @@ -1,10 +1,9 @@ #include -#include - #include #include #include +#include #include #include @@ -100,7 +99,8 @@ OutputGrid io::parse_output_grid_from_file(std::string_view filepath, const io:: file_content.push_back(c); } file_content.push_back('\0'); - return build_output_grid_from(std::string_view(file_content.data()), stdutils::string::filename(filepath)); + const auto filename = std::filesystem::path(filepath).filename().string(); + return build_output_grid_from(std::string_view(file_content.data()), filename); } else {