Skip to content

Commit

Permalink
Update to latest stdutils::string changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-dejoue committed Dec 22, 2023
1 parent 0cd25cb commit b299ae9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/cli/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <cassert>
#include <chrono>
#include <exception>
#include <filesystem>
#include <functional>
#include <iostream>
#include <limits>
Expand Down Expand Up @@ -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)
{
Expand Down
5 changes: 3 additions & 2 deletions src/gui/src/picross_file.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "picross_file.h"

#include <picross/picross.h>
#include <stdutils/string.h>

#include <cassert>
#include <filesystem>
#include <iostream>
#include <iterator>

Expand All @@ -30,9 +30,10 @@ void PicrossFile::visit_windows(bool& can_be_erased, Settings& settings)
std::optional<picross::OutputGrid> goal;
std::vector<picross::IOGrid> 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<GridWindow>(std::move(io_grid), stdutils::string::filename(file_path)));
windows.push_back(std::make_unique<GridWindow>(std::move(io_grid), source_file));
}
}
else
Expand Down
5 changes: 2 additions & 3 deletions src/utils/src/bitmap_io.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#include <utils/bitmap_io.h>

#include <stdutils/string.h>

#include <pnm.hpp>

#include <cassert>
#include <cstddef>
#include <exception>
#include <filesystem>


picross::OutputGrid import_bitmap_pbm(const std::string& filepath, const picross::io::ErrorHandler& error_handler) noexcept
{
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())
Expand Down
12 changes: 7 additions & 5 deletions src/utils/src/picross_file_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <cassert>
#include <exception>
#include <filesystem>
#include <fstream>
#include <sstream>

Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions src/utils/src/text_io.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#include <utils/text_io.h>

#include <stdutils/string.h>

#include <algorithm>
#include <cassert>
#include <exception>
#include <filesystem>
#include <fstream>
#include <sstream>

Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit b299ae9

Please sign in to comment.