Skip to content

Commit

Permalink
🔥 remove rest of <codecvt> in favor of utfcpp
Browse files Browse the repository at this point in the history
  • Loading branch information
unhammer committed Feb 2, 2018
1 parent 5fc3012 commit 0cf934c
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 24 deletions.
5 changes: 0 additions & 5 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -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 <codecvt>
: ^
: compilation terminated.
then your C++ compiler is too old. See [[*Prerequisites][Prerequisites]].


Expand Down
32 changes: 22 additions & 10 deletions python/libdivvun.i
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
%{
#include "../src/checkertypes.hpp"
#include "../src/checker.hpp"
#include "../src/utf8.h"
%}

#ifdef _MSC_VER
Expand All @@ -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<std::string>;

Expand All @@ -66,7 +68,6 @@ wrap_unique_ptr(CheckerUniquePtr, divvun::Checker);
// on trying to access err.rep[0])
%inline %{
#include <locale>
#include <codecvt>
#include <sstream>
typedef std::vector<std::string> StringVector;
struct ErrBytes {
Expand All @@ -84,24 +85,35 @@ wrap_unique_ptr(CheckerUniquePtr, divvun::Checker);
%inline %{
typedef std::vector<ErrBytes> 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<divvun::Checker>& checker, const std::string& input) {
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, 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<std::string> 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;
};
Expand Down
1 change: 0 additions & 1 deletion src/blanktag.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#define a0d6827329788a87_BLANKTAG_H

#include <locale>
#include <codecvt>
#include <vector>
#include <string>
#include <regex>
Expand Down
1 change: 0 additions & 1 deletion src/cgspell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#define a1e13de0fc0e1f37_CGSPELL_H

#include <locale>
#include <codecvt>
#include <vector>
#include <string>
#include <regex>
Expand Down
1 change: 0 additions & 1 deletion src/pipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ class SuggestCmd: public PipeCmd {


inline void parsePrefs(LocalisedPrefs& prefs, const pugi::xml_node& cmd) {
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, 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();
Expand Down
5 changes: 0 additions & 5 deletions src/pipespec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::codecvt_utf8_utf16<char16_t>, char16_t> utf16conv;
if (result) {
language = doc.child("pipespec").attribute("language").value();
if(language == "") {
Expand All @@ -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<std::codecvt_utf8_utf16<char16_t>, char16_t> utf16conv;
if (result) {
language = doc.child("pipespec").attribute("language").value();
if(language == "") {
Expand Down Expand Up @@ -171,7 +169,6 @@ string argprepare(const string& dir, string file) {
}

vector<std::pair<string,string>> toPipeSpecShVector(const string& dir, const PipeSpec& spec, const u16string& pipename, bool trace, bool json) {
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> utf16conv;
vector<std::pair<string, string>> cmds = {};
for (const pugi::xml_node& cmd: spec.pnodes.at(pipename).children()) {
const auto& name = string(cmd.name());
Expand Down Expand Up @@ -261,7 +258,6 @@ void chmod777(const string& path) {
}

void writePipeSpecShDirOne(const vector<std::pair<string, string>> cmds, const string& pipename, const string& modesdir, bool nodebug) {
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> utf16conv;
// TODO: (modesdir / …) when we get <experimental/filesystem>
size_t i = 0;
if(nodebug) {
Expand Down Expand Up @@ -295,7 +291,6 @@ void writePipeSpecShDirOne(const vector<std::pair<string, string>> cmds, const s
}

void writePipeSpecShDir(const string& specfile, bool json, const string& modesdir, bool nodebug) {
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> utf16conv;
const std::unique_ptr<PipeSpec> spec(new PipeSpec(specfile));
const auto dir = dirname(abspath(specfile));
for(const auto& p : spec->pnodes) {
Expand Down
1 change: 0 additions & 1 deletion src/pipespec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
// #include <experimental/filesystem>
// but need to support macos

#include <codecvt>
#include <cstring>
#include <cerrno>
#include <functional>
Expand Down

0 comments on commit 0cf934c

Please sign in to comment.