Set C locale, treat EPUB file names as UTF-8.

EPUB file names MUST be UTF-8. ASCII is a subset of UTF-8.
This commit is contained in:
tastytea 2021-05-23 06:32:56 +02:00
parent 6c040fa951
commit 28c6c80def
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
3 changed files with 7 additions and 1 deletions

View File

@ -22,6 +22,7 @@
#include <boost/program_options/errors.hpp>
#include <boost/program_options/variables_map.hpp>
#include <clocale>
#include <cstdlib>
#include <exception>
#include <iostream>
@ -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");

View File

@ -50,7 +50,7 @@ std::vector<std::string> list(const fs::path &filepath)
std::vector<std::string> 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);
}

View File

@ -3,12 +3,14 @@
#include <catch.hpp>
#include <clocale>
#include <exception>
#include <string>
#include <vector>
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<std::string> filelist;