From 0cf934c06ab504aff2784b23e41de02526b3a54b Mon Sep 17 00:00:00 2001 From: Kevin Brubeck Unhammer Date: Fri, 2 Feb 2018 13:24:47 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20remove=20rest=20of=20?= =?UTF-8?q?=20in=20favor=20of=20utfcpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.org | 5 ----- python/libdivvun.i | 32 ++++++++++++++++++++++---------- src/blanktag.hpp | 1 - src/cgspell.hpp | 1 - src/pipeline.hpp | 1 - src/pipespec.cpp | 5 ----- src/pipespec.hpp | 1 - 7 files changed, 22 insertions(+), 24 deletions(-) diff --git a/README.org b/README.org index 2f95cd2..73b4f80 100644 --- a/README.org +++ b/README.org @@ -748,11 +748,6 @@ from the regular suggestion generator, and saves some duplicate work. If you get : terminate called after throwing an instance of 'std::regex_error' : what(): regex_error -or -: util.hpp:36:19: fatal error: codecvt: No such file or directory -: #include -: ^ -: compilation terminated. then your C++ compiler is too old. See [[*Prerequisites][Prerequisites]]. diff --git a/python/libdivvun.i b/python/libdivvun.i index 082ac74..465d6ec 100644 --- a/python/libdivvun.i +++ b/python/libdivvun.i @@ -31,6 +31,7 @@ %{ #include "../src/checkertypes.hpp" #include "../src/checker.hpp" +#include "../src/utf8.h" %} #ifdef _MSC_VER @@ -57,6 +58,7 @@ wrap_unique_ptr(CheckerUniquePtr, divvun::Checker); %include "../src/checkertypes.hpp" %include "../src/checker.hpp" +%include "../src/utf8.h" %template(StringVector) std::vector; @@ -66,7 +68,6 @@ wrap_unique_ptr(CheckerUniquePtr, divvun::Checker); // on trying to access err.rep[0]) %inline %{ #include -#include #include typedef std::vector StringVector; struct ErrBytes { @@ -84,24 +85,35 @@ wrap_unique_ptr(CheckerUniquePtr, divvun::Checker); %inline %{ typedef std::vector ErrBytesVector; + const std::string toUtf8(const std::u16string& from) { + std::string to; + utf8::utf16to8(from.begin(), from.end(), std::back_inserter(to)); + return to; + } + const ErrBytesVector proc_errs_bytes(std::unique_ptr& checker, const std::string& input) { - std::wstring_convert, char16_t> utf16conv; std::stringstream ss = std::stringstream(input); const auto& errs = checker->proc_errs(ss); ErrBytesVector errs_bytes; for(const divvun::Err& e : errs) { std::vector rep; for(const std::u16string& r : e.rep) { - rep.push_back(utf16conv.to_bytes(r)); + std::string r8; + utf8::utf16to8(r.begin(), r.end(), std::back_inserter(r8)); + rep.push_back(r8); } + std::string form8, err8, msg8; + utf8::utf16to8(e.form.begin(), e.form.end(), std::back_inserter(form8)); + utf8::utf16to8(e.err.begin(), e.err.end(), std::back_inserter(err8)); + utf8::utf16to8(e.msg.begin(), e.msg.end(), std::back_inserter(msg8)); errs_bytes.push_back({ - utf16conv.to_bytes(e.form), - e.beg, - e.end, - utf16conv.to_bytes(e.err), - utf16conv.to_bytes(e.msg), - rep - }); + form8, + e.beg, + e.end, + err8, + msg8, + rep + }); } return errs_bytes; }; diff --git a/src/blanktag.hpp b/src/blanktag.hpp index 32b78f0..306ce0f 100644 --- a/src/blanktag.hpp +++ b/src/blanktag.hpp @@ -20,7 +20,6 @@ #define a0d6827329788a87_BLANKTAG_H #include -#include #include #include #include diff --git a/src/cgspell.hpp b/src/cgspell.hpp index 428426e..949112d 100644 --- a/src/cgspell.hpp +++ b/src/cgspell.hpp @@ -20,7 +20,6 @@ #define a1e13de0fc0e1f37_CGSPELL_H #include -#include #include #include #include diff --git a/src/pipeline.hpp b/src/pipeline.hpp index a6f0930..21f9be5 100644 --- a/src/pipeline.hpp +++ b/src/pipeline.hpp @@ -207,7 +207,6 @@ class SuggestCmd: public PipeCmd { inline void parsePrefs(LocalisedPrefs& prefs, const pugi::xml_node& cmd) { - std::wstring_convert, char16_t> utf16conv; for (const pugi::xml_node& pref: cmd.children()) { const auto type = pref.attribute("type").value(); const auto name = pref.attribute("name").value(); diff --git a/src/pipespec.cpp b/src/pipespec.cpp index ae8d828..4b01d9a 100644 --- a/src/pipespec.cpp +++ b/src/pipespec.cpp @@ -23,7 +23,6 @@ namespace divvun { PipeSpec::PipeSpec(const string& file) { pugi::xml_parse_result result = doc.load_file(file.c_str()); - std::wstring_convert, char16_t> utf16conv; if (result) { language = doc.child("pipespec").attribute("language").value(); if(language == "") { @@ -44,7 +43,6 @@ PipeSpec::PipeSpec(const string& file) { PipeSpec::PipeSpec(pugi::char_t* buff, size_t size) { pugi::xml_parse_result result = doc.load_buffer(buff, size); - std::wstring_convert, char16_t> utf16conv; if (result) { language = doc.child("pipespec").attribute("language").value(); if(language == "") { @@ -171,7 +169,6 @@ string argprepare(const string& dir, string file) { } vector> toPipeSpecShVector(const string& dir, const PipeSpec& spec, const u16string& pipename, bool trace, bool json) { - std::wstring_convert, char16_t> utf16conv; vector> cmds = {}; for (const pugi::xml_node& cmd: spec.pnodes.at(pipename).children()) { const auto& name = string(cmd.name()); @@ -261,7 +258,6 @@ void chmod777(const string& path) { } void writePipeSpecShDirOne(const vector> cmds, const string& pipename, const string& modesdir, bool nodebug) { - std::wstring_convert, char16_t> utf16conv; // TODO: (modesdir / …) when we get size_t i = 0; if(nodebug) { @@ -295,7 +291,6 @@ void writePipeSpecShDirOne(const vector> cmds, const s } void writePipeSpecShDir(const string& specfile, bool json, const string& modesdir, bool nodebug) { - std::wstring_convert, char16_t> utf16conv; const std::unique_ptr spec(new PipeSpec(specfile)); const auto dir = dirname(abspath(specfile)); for(const auto& p : spec->pnodes) { diff --git a/src/pipespec.hpp b/src/pipespec.hpp index 97fd4df..5e84d8d 100644 --- a/src/pipespec.hpp +++ b/src/pipespec.hpp @@ -26,7 +26,6 @@ // #include // but need to support macos -#include #include #include #include