From 28c6c80def53917c21d4bb4e870e9dbfa6d4d641 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 23 May 2021 06:32:56 +0200 Subject: [PATCH] Set C locale, treat EPUB file names as UTF-8. EPUB file names MUST be UTF-8. ASCII is a subset of UTF-8. --- src/main.cpp | 4 ++++ src/zip.cpp | 2 +- tests/test_zip_list.cpp | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 036be46..bc82761 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -37,6 +38,9 @@ int main(int argc, char *argv[]) using std::cerr; using std::cout; + // locale_generator("").name.c_str() returns "*" instead of "". That's why + // the global C locale isn't changed. So we have to set it additionally. + std::setlocale(LC_ALL, ""); boost::locale::generator locale_generator; locale_generator.add_messages_path("translations"); locale_generator.add_messages_path("/usr/share/locale"); diff --git a/src/zip.cpp b/src/zip.cpp index 17134c2..3fe0d86 100644 --- a/src/zip.cpp +++ b/src/zip.cpp @@ -50,7 +50,7 @@ std::vector list(const fs::path &filepath) std::vector toc; while (archive_read_next_header(zipfile, &entry) == ARCHIVE_OK) { - toc.emplace_back(archive_entry_pathname(entry)); + toc.emplace_back(archive_entry_pathname_utf8(entry)); archive_read_data_skip(zipfile); } diff --git a/tests/test_zip_list.cpp b/tests/test_zip_list.cpp index 9c8af06..e7f76ba 100644 --- a/tests/test_zip_list.cpp +++ b/tests/test_zip_list.cpp @@ -3,12 +3,14 @@ #include +#include #include #include #include SCENARIO("epubgrep::zip::list() doesn't fail and returns the right file list") { + std::setlocale(LC_CTYPE, ""); // Needed for utf-8 support in libarchive. bool exception{false}; std::vector filelist;