Skip to content

Commit

Permalink
fixed: opencc does not work under Windows, when opencc files in a pat…
Browse files Browse the repository at this point in the history
…h code page incompatible with UTF-8. (rime#689)

example path with Chinese characters.
  • Loading branch information
fxliang authored and graphemecluster committed Aug 12, 2023
1 parent 32c79ff commit ebd3a05
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/rime/gear/simplifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
#include <opencc/Dict.hpp>
#include <opencc/DictEntry.hpp>

#ifdef WIN32
#include <opencc/UTF8Util.hpp>
namespace fs = boost::filesystem;
#endif

static const char* quote_left = "\xe3\x80\x94"; //"\xef\xbc\x88";
static const char* quote_right = "\xe3\x80\x95"; //"\xef\xbc\x89";

Expand All @@ -36,7 +41,14 @@ class Opencc {
LOG(INFO) << "initializing opencc: " << config_path;
opencc::Config config;
try {
// windows config_path in CP_ACP, convert it to UTF-8
#ifdef WIN32
fs::path path{config_path};
converter_ =
config.NewFromFile(opencc::UTF8Util::U16ToU8(path.wstring()));
#else
converter_ = config.NewFromFile(config_path);
#endif /* WIN32 */
const list<opencc::ConversionPtr> conversions =
converter_->GetConversionChain()->GetConversions();
dict_ = conversions.front()->GetDict();
Expand Down

0 comments on commit ebd3a05

Please sign in to comment.