From 8a94fb7db0e62d602a23d17254d1002f7c607bd4 Mon Sep 17 00:00:00 2001 From: Daniel Wolf Date: Fri, 18 Jun 2021 22:00:01 +0200 Subject: [PATCH] Replace boost::filesystem with std::filesystem This allows us to use a header-only copy of Boost --- rhubarb/CMakeLists.txt | 2 +- rhubarb/src/audio/OggVorbisFileReader.cpp | 2 +- rhubarb/src/audio/OggVorbisFileReader.h | 6 ++--- rhubarb/src/audio/WaveFileReader.cpp | 2 +- rhubarb/src/audio/WaveFileReader.h | 6 ++--- rhubarb/src/audio/audioFileReading.cpp | 6 ++--- rhubarb/src/audio/audioFileReading.h | 4 ++-- rhubarb/src/exporters/Exporter.h | 6 ++--- rhubarb/src/exporters/JsonExporter.cpp | 3 +-- rhubarb/src/exporters/XmlExporter.cpp | 3 +-- rhubarb/src/lib/rhubarbLib.cpp | 2 +- rhubarb/src/lib/rhubarbLib.h | 4 ++-- .../src/recognition/PhoneticRecognizer.cpp | 4 ++-- .../recognition/PocketSphinxRecognizer.cpp | 10 ++++---- rhubarb/src/recognition/languageModels.cpp | 10 ++++---- rhubarb/src/recognition/pocketSphinxTools.cpp | 2 +- rhubarb/src/recognition/pocketSphinxTools.h | 4 ++-- rhubarb/src/rhubarb/main.cpp | 23 +++++++++---------- rhubarb/src/rhubarb/semanticEntries.cpp | 6 ++--- rhubarb/src/rhubarb/semanticEntries.h | 8 +++---- rhubarb/src/rhubarb/sinks.cpp | 6 ++--- rhubarb/src/rhubarb/sinks.h | 4 ++-- rhubarb/src/tools/NiceCmdLineOutput.cpp | 2 +- rhubarb/src/tools/fileTools.cpp | 2 +- rhubarb/src/tools/fileTools.h | 5 ++-- rhubarb/src/tools/platformTools.cpp | 19 +++++---------- rhubarb/src/tools/platformTools.h | 10 ++++---- rhubarb/src/tools/textFiles.cpp | 11 ++++----- rhubarb/src/tools/textFiles.h | 4 ++-- 29 files changed, 83 insertions(+), 93 deletions(-) diff --git a/rhubarb/CMakeLists.txt b/rhubarb/CMakeLists.txt index ade5059..c2981e5 100644 --- a/rhubarb/CMakeLists.txt +++ b/rhubarb/CMakeLists.txt @@ -65,7 +65,7 @@ set(Boost_USE_STATIC_LIBS ON) # Use static libs set(Boost_USE_MULTITHREADED ON) # Enable multithreading support set(Boost_USE_STATIC_RUNTIME ON) # Use static C++ runtime set(Boost_NO_BOOST_CMAKE ON) # Workaround for https://gitlab.kitware.com/cmake/cmake/-/issues/18865 -find_package(Boost 1.54 REQUIRED COMPONENTS filesystem locale system) +find_package(Boost 1.54 REQUIRED) include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) link_libraries(${Boost_LIBRARIES}) # Just about every project needs Boost diff --git a/rhubarb/src/audio/OggVorbisFileReader.cpp b/rhubarb/src/audio/OggVorbisFileReader.cpp index f84aaa4..fc86532 100644 --- a/rhubarb/src/audio/OggVorbisFileReader.cpp +++ b/rhubarb/src/audio/OggVorbisFileReader.cpp @@ -6,7 +6,7 @@ #include #include "tools/fileTools.h" -using boost::filesystem::path; +using std::filesystem::path; using std::vector; using std::make_shared; using std::ifstream; diff --git a/rhubarb/src/audio/OggVorbisFileReader.h b/rhubarb/src/audio/OggVorbisFileReader.h index 76b0324..a143211 100644 --- a/rhubarb/src/audio/OggVorbisFileReader.h +++ b/rhubarb/src/audio/OggVorbisFileReader.h @@ -1,11 +1,11 @@ #pragma once #include "AudioClip.h" -#include +#include class OggVorbisFileReader : public AudioClip { public: - OggVorbisFileReader(const boost::filesystem::path& filePath); + OggVorbisFileReader(const std::filesystem::path& filePath); std::unique_ptr clone() const override; int getSampleRate() const override { return sampleRate; } size_type size() const override { return sampleCount; } @@ -13,7 +13,7 @@ public: private: SampleReader createUnsafeSampleReader() const override; - boost::filesystem::path filePath; + std::filesystem::path filePath; int sampleRate; int channelCount; size_type sampleCount; diff --git a/rhubarb/src/audio/WaveFileReader.cpp b/rhubarb/src/audio/WaveFileReader.cpp index 5e4ae58..df24ccb 100644 --- a/rhubarb/src/audio/WaveFileReader.cpp +++ b/rhubarb/src/audio/WaveFileReader.cpp @@ -12,7 +12,7 @@ using namespace little_endian; using std::unique_ptr; using std::make_unique; using std::make_shared; -using boost::filesystem::path; +using std::filesystem::path; #define INT24_MIN (-8388608) #define INT24_MAX 8388607 diff --git a/rhubarb/src/audio/WaveFileReader.h b/rhubarb/src/audio/WaveFileReader.h index df68f19..c200f35 100644 --- a/rhubarb/src/audio/WaveFileReader.h +++ b/rhubarb/src/audio/WaveFileReader.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "AudioClip.h" enum class SampleFormat { @@ -12,7 +12,7 @@ enum class SampleFormat { class WaveFileReader : public AudioClip { public: - WaveFileReader(const boost::filesystem::path& filePath); + WaveFileReader(const std::filesystem::path& filePath); std::unique_ptr clone() const override; int getSampleRate() const override; size_type size() const override; @@ -29,7 +29,7 @@ private: std::streampos dataOffset; }; - boost::filesystem::path filePath; + std::filesystem::path filePath; WaveFormatInfo formatInfo; }; diff --git a/rhubarb/src/audio/audioFileReading.cpp b/rhubarb/src/audio/audioFileReading.cpp index f5b2d4c..3cccfbb 100644 --- a/rhubarb/src/audio/audioFileReading.cpp +++ b/rhubarb/src/audio/audioFileReading.cpp @@ -4,7 +4,7 @@ #include #include "OggVorbisFileReader.h" -using boost::filesystem::path; +using std::filesystem::path; using std::string; using std::runtime_error; using fmt::format; @@ -12,7 +12,7 @@ using fmt::format; std::unique_ptr createAudioFileClip(path filePath) { try { const string extension = - boost::algorithm::to_lower_copy(boost::filesystem::extension(filePath)); + boost::algorithm::to_lower_copy(filePath.extension().u8string()); if (extension == ".wav") { return std::make_unique(filePath); } @@ -24,6 +24,6 @@ std::unique_ptr createAudioFileClip(path filePath) { extension )); } catch (...) { - std::throw_with_nested(runtime_error(format("Could not open sound file {}.", filePath))); + std::throw_with_nested(runtime_error(format("Could not open sound file {}.", filePath.u8string()))); } } diff --git a/rhubarb/src/audio/audioFileReading.h b/rhubarb/src/audio/audioFileReading.h index daa8412..78beef2 100644 --- a/rhubarb/src/audio/audioFileReading.h +++ b/rhubarb/src/audio/audioFileReading.h @@ -2,6 +2,6 @@ #include #include "AudioClip.h" -#include +#include -std::unique_ptr createAudioFileClip(boost::filesystem::path filePath); +std::unique_ptr createAudioFileClip(std::filesystem::path filePath); diff --git a/rhubarb/src/exporters/Exporter.h b/rhubarb/src/exporters/Exporter.h index 1be1092..0be901c 100644 --- a/rhubarb/src/exporters/Exporter.h +++ b/rhubarb/src/exporters/Exporter.h @@ -2,19 +2,19 @@ #include "core/Shape.h" #include "time/ContinuousTimeline.h" -#include +#include class ExporterInput { public: ExporterInput( - const boost::filesystem::path& inputFilePath, + const std::filesystem::path& inputFilePath, const JoiningContinuousTimeline& animation, const ShapeSet& targetShapeSet) : inputFilePath(inputFilePath), animation(animation), targetShapeSet(targetShapeSet) {} - boost::filesystem::path inputFilePath; + std::filesystem::path inputFilePath; JoiningContinuousTimeline animation; ShapeSet targetShapeSet; }; diff --git a/rhubarb/src/exporters/JsonExporter.cpp b/rhubarb/src/exporters/JsonExporter.cpp index 1cd3c50..60ee841 100644 --- a/rhubarb/src/exporters/JsonExporter.cpp +++ b/rhubarb/src/exporters/JsonExporter.cpp @@ -1,7 +1,6 @@ #include "JsonExporter.h" #include "exporterTools.h" #include "tools/stringTools.h" -#include using std::string; @@ -11,7 +10,7 @@ void JsonExporter::exportAnimation(const ExporterInput& input, std::ostream& out // the formatting. outputStream << "{\n"; outputStream << " \"metadata\": {\n"; - outputStream << " \"soundFile\": \"" << escapeJsonString(absolute(input.inputFilePath).string()) << "\",\n"; + outputStream << " \"soundFile\": \"" << escapeJsonString(absolute(input.inputFilePath).u8string()) << "\",\n"; outputStream << " \"duration\": " << formatDuration(input.animation.getRange().getDuration()) << "\n"; outputStream << " },\n"; outputStream << " \"mouthCues\": [\n"; diff --git a/rhubarb/src/exporters/XmlExporter.cpp b/rhubarb/src/exporters/XmlExporter.cpp index 763f473..073ef68 100644 --- a/rhubarb/src/exporters/XmlExporter.cpp +++ b/rhubarb/src/exporters/XmlExporter.cpp @@ -3,7 +3,6 @@ #include #include #include "exporterTools.h" -#include using std::string; using boost::property_tree::ptree; @@ -12,7 +11,7 @@ void XmlExporter::exportAnimation(const ExporterInput& input, std::ostream& outp ptree tree; // Add metadata - tree.put("rhubarbResult.metadata.soundFile", absolute(input.inputFilePath).string()); + tree.put("rhubarbResult.metadata.soundFile", absolute(input.inputFilePath).u8string()); tree.put( "rhubarbResult.metadata.duration", formatDuration(input.animation.getRange().getDuration()) diff --git a/rhubarb/src/lib/rhubarbLib.cpp b/rhubarb/src/lib/rhubarbLib.cpp index 5f8460f..8b624cb 100644 --- a/rhubarb/src/lib/rhubarbLib.cpp +++ b/rhubarb/src/lib/rhubarbLib.cpp @@ -6,7 +6,7 @@ using boost::optional; using std::string; -using boost::filesystem::path; +using std::filesystem::path; JoiningContinuousTimeline animateAudioClip( const AudioClip& audioClip, diff --git a/rhubarb/src/lib/rhubarbLib.h b/rhubarb/src/lib/rhubarbLib.h index ae841a6..6d7c4d1 100644 --- a/rhubarb/src/lib/rhubarbLib.h +++ b/rhubarb/src/lib/rhubarbLib.h @@ -4,7 +4,7 @@ #include "time/ContinuousTimeline.h" #include "audio/AudioClip.h" #include "tools/progress.h" -#include +#include #include "animation/targetShapeSet.h" #include "recognition/Recognizer.h" @@ -17,7 +17,7 @@ JoiningContinuousTimeline animateAudioClip( ProgressSink& progressSink); JoiningContinuousTimeline animateWaveFile( - boost::filesystem::path filePath, + std::filesystem::path filePath, const boost::optional& dialog, const Recognizer& recognizer, const ShapeSet& targetShapeSet, diff --git a/rhubarb/src/recognition/PhoneticRecognizer.cpp b/rhubarb/src/recognition/PhoneticRecognizer.cpp index 262ba48..68fb6fc 100644 --- a/rhubarb/src/recognition/PhoneticRecognizer.cpp +++ b/rhubarb/src/recognition/PhoneticRecognizer.cpp @@ -17,9 +17,9 @@ static lambda_unique_ptr createDecoder(optional dialo cmd_ln_init( nullptr, ps_args(), true, // Set acoustic model - "-hmm", (getSphinxModelDirectory() / "acoustic-model").string().c_str(), + "-hmm", (getSphinxModelDirectory() / "acoustic-model").u8string().c_str(), // Set phonetic language model - "-allphone", (getSphinxModelDirectory() / "en-us-phone.lm.bin").string().c_str(), + "-allphone", (getSphinxModelDirectory() / "en-us-phone.lm.bin").u8string().c_str(), "-allphone_ci", "yes", // Set language model probability weight. // Low values (<= 0.4) can lead to fluttering animation. diff --git a/rhubarb/src/recognition/PocketSphinxRecognizer.cpp b/rhubarb/src/recognition/PocketSphinxRecognizer.cpp index ca41050..9eaf5e3 100644 --- a/rhubarb/src/recognition/PocketSphinxRecognizer.cpp +++ b/rhubarb/src/recognition/PocketSphinxRecognizer.cpp @@ -20,7 +20,7 @@ using std::unique_ptr; using std::string; using std::vector; using std::map; -using boost::filesystem::path; +using std::filesystem::path; using std::regex; using std::regex_replace; using boost::optional; @@ -58,10 +58,10 @@ void addMissingDictionaryWords(const vector& words, ps_decoder_t& decode lambda_unique_ptr createDefaultLanguageModel(ps_decoder_t& decoder) { path modelPath = getSphinxModelDirectory() / "en-us.lm.bin"; lambda_unique_ptr result( - ngram_model_read(decoder.config, modelPath.string().c_str(), NGRAM_AUTO, decoder.lmath), + ngram_model_read(decoder.config, modelPath.u8string().c_str(), NGRAM_AUTO, decoder.lmath), [](ngram_model_t* lm) { ngram_model_free(lm); }); if (!result) { - throw runtime_error(fmt::format("Error reading language model from {}.", modelPath)); + throw runtime_error(fmt::format("Error reading language model from {}.", modelPath.u8string())); } return result; @@ -120,9 +120,9 @@ static lambda_unique_ptr createDecoder(optional dialo cmd_ln_init( nullptr, ps_args(), true, // Set acoustic model - "-hmm", (getSphinxModelDirectory() / "acoustic-model").string().c_str(), + "-hmm", (getSphinxModelDirectory() / "acoustic-model").u8string().c_str(), // Set pronunciation dictionary - "-dict", (getSphinxModelDirectory() / "cmudict-en-us.dict").string().c_str(), + "-dict", (getSphinxModelDirectory() / "cmudict-en-us.dict").u8string().c_str(), // Add noise against zero silence // (see http://cmusphinx.sourceforge.net/wiki/faq#qwhy_my_accuracy_is_poor) "-dither", "yes", diff --git a/rhubarb/src/recognition/languageModels.cpp b/rhubarb/src/recognition/languageModels.cpp index f46d2d6..cfb3723 100644 --- a/rhubarb/src/recognition/languageModels.cpp +++ b/rhubarb/src/recognition/languageModels.cpp @@ -5,7 +5,7 @@ #include #include #include "tools/platformTools.h" -#include +#include #include "core/appInfo.h" #include #include @@ -17,7 +17,7 @@ using std::map; using std::tuple; using std::get; using std::endl; -using boost::filesystem::path; +using std::filesystem::path; using Unigram = string; using Bigram = tuple; @@ -151,7 +151,7 @@ void createLanguageModelFile(const vector& words, const path& filePath) map bigramBackoffWeights = getBigramBackoffWeights(bigramCounts, bigramProbabilities, trigramCounts, discountMass); - boost::filesystem::ofstream file(filePath); + std::ofstream file(filePath); file << "Generated by " << appName << " " << appVersion << endl << endl; file << "\\data\\" << endl; @@ -193,9 +193,9 @@ lambda_unique_ptr createLanguageModel( ) { path tempFilePath = getTempFilePath(); createLanguageModelFile(words, tempFilePath); - auto deleteTempFile = gsl::finally([&]() { boost::filesystem::remove(tempFilePath); }); + auto deleteTempFile = gsl::finally([&]() { std::filesystem::remove(tempFilePath); }); return lambda_unique_ptr( - ngram_model_read(decoder.config, tempFilePath.string().c_str(), NGRAM_ARPA, decoder.lmath), + ngram_model_read(decoder.config, tempFilePath.u8string().c_str(), NGRAM_ARPA, decoder.lmath), [](ngram_model_t* lm) { ngram_model_free(lm); }); } diff --git a/rhubarb/src/recognition/pocketSphinxTools.cpp b/rhubarb/src/recognition/pocketSphinxTools.cpp index d571cc5..6736ec8 100644 --- a/rhubarb/src/recognition/pocketSphinxTools.cpp +++ b/rhubarb/src/recognition/pocketSphinxTools.cpp @@ -19,7 +19,7 @@ using std::invalid_argument; using std::unique_ptr; using std::string; using std::vector; -using boost::filesystem::path; +using std::filesystem::path; using std::regex; using boost::optional; using std::chrono::duration_cast; diff --git a/rhubarb/src/recognition/pocketSphinxTools.h b/rhubarb/src/recognition/pocketSphinxTools.h index bd47a80..2c34a2e 100644 --- a/rhubarb/src/recognition/pocketSphinxTools.h +++ b/rhubarb/src/recognition/pocketSphinxTools.h @@ -4,7 +4,7 @@ #include "core/Phone.h" #include "audio/AudioClip.h" #include "tools/progress.h" -#include +#include extern "C" { #include @@ -32,7 +32,7 @@ BoundedTimeline recognizePhones( constexpr int sphinxSampleRate = 16000; -const boost::filesystem::path& getSphinxModelDirectory(); +const std::filesystem::path& getSphinxModelDirectory(); JoiningTimeline getNoiseSounds(TimeRange utteranceTimeRange, const Timeline& phones); diff --git a/rhubarb/src/rhubarb/main.cpp b/rhubarb/src/rhubarb/main.cpp index 4e512a9..85eec62 100644 --- a/rhubarb/src/rhubarb/main.cpp +++ b/rhubarb/src/rhubarb/main.cpp @@ -9,10 +9,9 @@ #include #include "exporters/Exporter.h" #include "time/ContinuousTimeline.h" -#include #include "tools/stringTools.h" #include -#include +#include #include "tools/parallel.h" #include "tools/exceptions.h" #include "tools/textFiles.h" @@ -39,7 +38,8 @@ using std::unique_ptr; using std::make_unique; using std::shared_ptr; using std::make_shared; -using boost::filesystem::path; +using std::filesystem::path; +using std::filesystem::u8path; using boost::adaptors::transformed; using boost::optional; @@ -64,7 +64,7 @@ namespace TCLAP { } shared_ptr createFileSink(const path& path, logging::Level minLevel) { - auto file = make_shared(); + auto file = make_shared(); file->exceptions(std::ifstream::failbit | std::ifstream::badbit); file->open(path); auto FileSink = @@ -121,9 +121,8 @@ int main(int platformArgc, char* platformArgv[]) { shared_ptr defaultSink = make_shared(defaultMinStderrLevel); logging::addSink(defaultSink); - // Use UTF-8 throughout + // Make sure the console uses UTF-8 on all platforms including Windows useUtf8ForConsole(); - useUtf8ForBoostFilesystem(); // Convert command-line arguments to UTF-8 const vector args = argsToUtf8(platformArgc, platformArgv); @@ -229,7 +228,7 @@ int main(int platformArgc, char* platformArgv[]) { logging::removeSink(defaultSink); // ... to log file if (logFileName.isSet()) { - auto fileSink = createFileSink(path(logFileName.getValue()), logLevel.getValue()); + auto fileSink = createFileSink(u8path(logFileName.getValue()), logLevel.getValue()); logging::addSink(fileSink); } @@ -237,7 +236,7 @@ int main(int platformArgc, char* platformArgv[]) { if (maxThreadCount.getValue() < 1) { throw std::runtime_error("Thread count must be 1 or higher."); } - path inputFilePath(inputFileName.getValue()); + path inputFilePath = u8path(inputFileName.getValue()); ShapeSet targetShapeSet = getTargetShapeSet(extendedShapes.getValue()); unique_ptr exporter = createExporter( @@ -262,7 +261,7 @@ int main(int platformArgc, char* platformArgv[]) { JoiningContinuousTimeline animation = animateWaveFile( inputFilePath, dialogFile.isSet() - ? readUtf8File(path(dialogFile.getValue())) + ? readUtf8File(u8path(dialogFile.getValue())) : boost::optional(), *createRecognizer(recognizerType.getValue()), targetShapeSet, @@ -271,9 +270,9 @@ int main(int platformArgc, char* platformArgv[]) { logging::info("Done animating."); // Export animation - optional outputFile; + optional outputFile; if (outputFileName.isSet()) { - outputFile = boost::in_place(outputFileName.getValue()); + outputFile = boost::in_place(u8path(outputFileName.getValue())); outputFile->exceptions(std::ifstream::failbit | std::ifstream::badbit); } ExporterInput exporterInput = ExporterInput(inputFilePath, animation, targetShapeSet); @@ -284,7 +283,7 @@ int main(int platformArgc, char* platformArgv[]) { logging::log(SuccessEntry()); } catch (...) { std::throw_with_nested( - std::runtime_error(fmt::format("Error processing file {}.", inputFilePath)) + std::runtime_error(fmt::format("Error processing file {}.", inputFilePath.u8string())) ); } diff --git a/rhubarb/src/rhubarb/semanticEntries.cpp b/rhubarb/src/rhubarb/semanticEntries.cpp index 7ee8b02..f191a04 100644 --- a/rhubarb/src/rhubarb/semanticEntries.cpp +++ b/rhubarb/src/rhubarb/semanticEntries.cpp @@ -7,12 +7,12 @@ SemanticEntry::SemanticEntry(Level level, const string& message) : Entry(level, message) {} -StartEntry::StartEntry(const boost::filesystem::path& inputFilePath) : - SemanticEntry(Level::Info, fmt::format("Application startup. Input file: {}.", inputFilePath)), +StartEntry::StartEntry(const std::filesystem::path& inputFilePath) : + SemanticEntry(Level::Info, fmt::format("Application startup. Input file: {}.", inputFilePath.u8string())), inputFilePath(inputFilePath) {} -boost::filesystem::path StartEntry::getInputFilePath() const { +std::filesystem::path StartEntry::getInputFilePath() const { return inputFilePath; } diff --git a/rhubarb/src/rhubarb/semanticEntries.h b/rhubarb/src/rhubarb/semanticEntries.h index 344fb67..c7ee717 100644 --- a/rhubarb/src/rhubarb/semanticEntries.h +++ b/rhubarb/src/rhubarb/semanticEntries.h @@ -1,6 +1,6 @@ #pragma once #include "logging/Entry.h" -#include +#include // Marker class for semantic entries class SemanticEntry : public logging::Entry { @@ -10,10 +10,10 @@ public: class StartEntry : public SemanticEntry { public: - StartEntry(const boost::filesystem::path& inputFilePath); - boost::filesystem::path getInputFilePath() const; + StartEntry(const std::filesystem::path& inputFilePath); + std::filesystem::path getInputFilePath() const; private: - boost::filesystem::path inputFilePath; + std::filesystem::path inputFilePath; }; class ProgressEntry : public SemanticEntry { diff --git a/rhubarb/src/rhubarb/sinks.cpp b/rhubarb/src/rhubarb/sinks.cpp index 487377e..1c8b5e4 100644 --- a/rhubarb/src/rhubarb/sinks.cpp +++ b/rhubarb/src/rhubarb/sinks.cpp @@ -24,7 +24,7 @@ void NiceStderrSink::receive(const logging::Entry& entry) { // the technical log message. if (const auto* startEntry = dynamic_cast(&entry)) { std::cerr - << fmt::format("Generating lip sync data for {}.", startEntry->getInputFilePath()) + << fmt::format("Generating lip sync data for {}.", startEntry->getInputFilePath().u8string()) << std::endl; startProgressIndication(); } else if (const auto* progressEntry = dynamic_cast(&entry)) { @@ -75,7 +75,7 @@ void QuietStderrSink::receive(const logging::Entry& entry) { if (quietSoFar) { // This is the first message we print. Give a bit of context. const string intro = inputFilePath - ? fmt::format("{} {} processing file {}:", appName, appVersion, *inputFilePath) + ? fmt::format("{} {} processing file {}:", appName, appVersion, inputFilePath->u8string()) : fmt::format("{} {}:", appName, appVersion); std::cerr << intro << std::endl; quietSoFar = false; @@ -100,7 +100,7 @@ void MachineReadableStderrSink::receive(const logging::Entry& entry) { optional line; if (dynamic_cast(&entry)) { if (const auto* startEntry = dynamic_cast(&entry)) { - const string file = escapeJsonString(startEntry->getInputFilePath().string()); + const string file = escapeJsonString(startEntry->getInputFilePath().u8string()); line = fmt::format( R"({{ "type": "start", "file": "{}", {} }})", file, diff --git a/rhubarb/src/rhubarb/sinks.h b/rhubarb/src/rhubarb/sinks.h index 9bf47e3..5de4e25 100644 --- a/rhubarb/src/rhubarb/sinks.h +++ b/rhubarb/src/rhubarb/sinks.h @@ -3,7 +3,7 @@ #include "logging/Entry.h" #include "logging/Sink.h" #include "tools/ProgressBar.h" -#include +#include // Prints nicely formatted progress to stderr. // Non-semantic entries are only printed if their log level at least matches the specified minimum level. @@ -31,7 +31,7 @@ public: private: logging::Level minLevel; bool quietSoFar = true; - boost::optional inputFilePath; + boost::optional inputFilePath; std::shared_ptr innerSink; }; diff --git a/rhubarb/src/tools/NiceCmdLineOutput.cpp b/rhubarb/src/tools/NiceCmdLineOutput.cpp index cb1a700..ddf165f 100644 --- a/rhubarb/src/tools/NiceCmdLineOutput.cpp +++ b/rhubarb/src/tools/NiceCmdLineOutput.cpp @@ -10,7 +10,7 @@ using std::cout; using std::endl; string getBinaryName() { - return getBinPath().filename().string(); + return getBinPath().filename().u8string(); } void NiceCmdLineOutput::version(CmdLineInterface& cli) { diff --git a/rhubarb/src/tools/fileTools.cpp b/rhubarb/src/tools/fileTools.cpp index f08eb0d..c60eb85 100644 --- a/rhubarb/src/tools/fileTools.cpp +++ b/rhubarb/src/tools/fileTools.cpp @@ -2,7 +2,7 @@ #include -using boost::filesystem::path; +using std::filesystem::path; std::ifstream openFile(path filePath) { try { diff --git a/rhubarb/src/tools/fileTools.h b/rhubarb/src/tools/fileTools.h index 8e6053f..d709c6a 100644 --- a/rhubarb/src/tools/fileTools.h +++ b/rhubarb/src/tools/fileTools.h @@ -1,7 +1,8 @@ #pragma once #include "platformTools.h" #include +#include -std::ifstream openFile(boost::filesystem::path filePath); +std::ifstream openFile(std::filesystem::path filePath); -void throwIfNotReadable(boost::filesystem::path filePath); \ No newline at end of file +void throwIfNotReadable(std::filesystem::path filePath); \ No newline at end of file diff --git a/rhubarb/src/tools/platformTools.cpp b/rhubarb/src/tools/platformTools.cpp index 2e51ea9..c375914 100644 --- a/rhubarb/src/tools/platformTools.cpp +++ b/rhubarb/src/tools/platformTools.cpp @@ -1,5 +1,4 @@ -#include -#include +#include #include #include #include @@ -9,14 +8,14 @@ #include #include #include "tools.h" -#include +#include #include #ifdef _WIN32 #include #endif -using boost::filesystem::path; +using std::filesystem::path; using std::string; using std::vector; @@ -39,9 +38,9 @@ path getBinPath() { } buffer[pathLength] = 0; - // Convert to boost::filesystem::path + // Convert to std::filesystem::path const string pathString(buffer.data()); - path result(boost::filesystem::canonical(pathString).make_preferred()); + path result(std::filesystem::canonical(pathString).make_preferred()); return result; } catch (...) { std::throw_with_nested(std::runtime_error("Could not determine path of bin directory.")); @@ -55,7 +54,7 @@ path getBinDirectory() { } path getTempFilePath() { - const path tempDirectory = boost::filesystem::temp_directory_path(); + const path tempDirectory = std::filesystem::temp_directory_path(); static boost::uuids::random_generator generateUuid; const string fileName = to_string(generateUuid()); return tempDirectory / fileName; @@ -145,9 +144,3 @@ void useUtf8ForConsole() { std::cerr.rdbuf(new ConsoleBuffer(stderr)); #endif } - -void useUtf8ForBoostFilesystem() { - const std::locale globalLocale = std::locale(); - const std::locale utf8Locale(globalLocale, new boost::filesystem::detail::utf8_codecvt_facet); - path::imbue(utf8Locale); -} diff --git a/rhubarb/src/tools/platformTools.h b/rhubarb/src/tools/platformTools.h index 34a0e35..e93b056 100644 --- a/rhubarb/src/tools/platformTools.h +++ b/rhubarb/src/tools/platformTools.h @@ -1,12 +1,13 @@ #pragma once -#include +#include #include #include +#include -boost::filesystem::path getBinPath(); -boost::filesystem::path getBinDirectory(); -boost::filesystem::path getTempFilePath(); +std::filesystem::path getBinPath(); +std::filesystem::path getBinDirectory(); +std::filesystem::path getTempFilePath(); std::tm getLocalTime(const time_t& time); std::string errorNumberToString(int errorNumber); @@ -14,4 +15,3 @@ std::string errorNumberToString(int errorNumber); std::vector argsToUtf8(int argc, char* argv[]); void useUtf8ForConsole(); -void useUtf8ForBoostFilesystem(); \ No newline at end of file diff --git a/rhubarb/src/tools/textFiles.cpp b/rhubarb/src/tools/textFiles.cpp index d266f65..f7086db 100644 --- a/rhubarb/src/tools/textFiles.cpp +++ b/rhubarb/src/tools/textFiles.cpp @@ -1,18 +1,17 @@ #include "textFiles.h" -#include #include -#include +#include #include "stringTools.h" using std::string; -using boost::filesystem::path; +using std::filesystem::path; string readUtf8File(path filePath) { if (!exists(filePath)) { - throw std::invalid_argument(fmt::format("File {} does not exist.", filePath)); + throw std::invalid_argument(fmt::format("File {} does not exist.", filePath.u8string())); } try { - boost::filesystem::ifstream file; + std::ifstream file; file.exceptions(std::ifstream::failbit | std::ifstream::badbit); file.open(filePath); string text((std::istreambuf_iterator(file)), std::istreambuf_iterator()); @@ -22,7 +21,7 @@ string readUtf8File(path filePath) { return text; } catch (...) { - std::throw_with_nested(std::runtime_error(fmt::format("Error reading file {0}.", filePath))); + std::throw_with_nested(std::runtime_error(fmt::format("Error reading file {0}.", filePath.u8string()))); } } diff --git a/rhubarb/src/tools/textFiles.h b/rhubarb/src/tools/textFiles.h index adfe96b..4f1d5cd 100644 --- a/rhubarb/src/tools/textFiles.h +++ b/rhubarb/src/tools/textFiles.h @@ -1,5 +1,5 @@ #pragma once -#include +#include -std::string readUtf8File(boost::filesystem::path filePath); \ No newline at end of file +std::string readUtf8File(std::filesystem::path filePath); \ No newline at end of file