Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ if(MSVC)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
add_definitions("/wd4244 /wd4996")
add_compile_options("/Zc:__cplusplus")

# large address aware
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
Expand Down
6 changes: 3 additions & 3 deletions include/darts.h
Original file line number Diff line number Diff line change
Expand Up @@ -1429,9 +1429,9 @@ class DoubleArrayBuilder {
void clear();

private:
enum { BLOCK_SIZE = 256 };
enum { NUM_EXTRA_BLOCKS = 16 };
enum { NUM_EXTRAS = BLOCK_SIZE * NUM_EXTRA_BLOCKS };
static const std::size_t BLOCK_SIZE = 256;
static const std::size_t NUM_EXTRA_BLOCKS = 16;
static const std::size_t NUM_EXTRAS = BLOCK_SIZE * NUM_EXTRA_BLOCKS;

enum { UPPER_MASK = 0xFF << 21 };
enum { LOWER_MASK = 0xFF };
Expand Down
23 changes: 22 additions & 1 deletion src/rime/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,27 @@ class path : public std::filesystem::path {
path& operator/=(const std::string& p) { return *this /= path(p); }
path& operator/=(const char* p) { return *this /= path(p); }

path stem() const { return path(fs_path::stem()); }
path filename() const { return path(fs_path::filename()); }
path extension() const { return path(fs_path::extension()); }
// return UTF-8 encoded std::string
std::string string_utf8() const {
#if __cplusplus >= 202002L
const auto u8s = this->u8string();
return std::string(u8s.begin(), u8s.end());
#else
return this->u8string();
#endif
}
// return UTF-8 encoded std::string of generic format
std::string generic_string_utf8() const {
#if __cplusplus >= 202002L
const auto u8s = this->generic_u8string();
return std::string(u8s.begin(), u8s.end());
#else
return this->generic_u8string();
#endif
}
friend path operator/(const path& lhs, const path& rhs) {
return path(lhs) /= rhs;
}
Expand All @@ -128,7 +149,7 @@ class path : public std::filesystem::path {
}
#ifdef RIME_ENABLE_LOGGING
friend std::ostream& operator<<(std::ostream& os, const path& p) {
return os << p.u8string();
return os << p.string_utf8();
}
#endif
};
Expand Down
2 changes: 1 addition & 1 deletion src/rime/config/config_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ bool ConfigData::LoadFromFile(const path& file_path, ConfigCompiler* compiler) {
modified_ = false;
root.reset();
if (!std::filesystem::exists(file_path)) {
if (!boost::ends_with(file_path.u8string(), ".custom.yaml"))
if (!boost::ends_with(file_path.string_utf8(), ".custom.yaml"))
LOG(WARNING) << "nonexistent config file '" << file_path << "'.";
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/rime/dict/dict_compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ bool DictCompiler::Compile(const path& schema_file) {

static path relocate_target(const path& source_path,
ResourceResolver* target_resolver) {
auto resource_id = source_path.filename().u8string();
auto resource_id = source_path.filename().string_utf8();
return target_resolver->ResolvePath(resource_id);
}

Expand Down
2 changes: 1 addition & 1 deletion src/rime/dict/entry_collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void EntryCollector::LoadPresetVocabulary(DictSettings* settings) {

void EntryCollector::Collect(const path& dict_file) {
LOG(INFO) << "collecting entries from " << dict_file;
current_dict_file = dict_file.u8string();
current_dict_file = dict_file.string_utf8();
line_number = 0;
// read table
std::ifstream fin(dict_file.c_str());
Expand Down
2 changes: 1 addition & 1 deletion src/rime/dict/user_db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ bool UserDbHelper::UpdateUserInfo() {
}

bool UserDbHelper::IsUniformFormat(const path& file_path) {
return boost::ends_with(file_path.filename().u8string(),
return boost::ends_with(file_path.filename().string_utf8(),
plain_userdb_extension);
}

Expand Down
2 changes: 2 additions & 0 deletions src/rime/dict/vocabulary.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ struct ShortDictEntry {
double weight = 0.0;

ShortDictEntry() = default;
ShortDictEntry(const string& t, const Code& c, double w)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this change for?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c++20

: text(t), code(c), weight(w) {}
bool operator<(const ShortDictEntry& other) const;
};

Expand Down
4 changes: 2 additions & 2 deletions src/rime/gear/simplifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Opencc {
opencc::Config config;
try {
// opencc accepts file path encoded in UTF-8.
converter_ = config.NewFromFile(config_path_.u8string());
converter_ = config.NewFromFile(config_path_.string_utf8());

const list<opencc::ConversionPtr> conversions =
converter_->GetConversionChain()->GetConversions();
Expand Down Expand Up @@ -315,7 +315,7 @@ Simplifier* SimplifierComponent::Create(const Ticket& ticket) {
return new Simplifier(ticket, opencc);
}
path opencc_config_path = path(opencc_config);
if (opencc_config_path.extension().u8string() == ".ini") {
if (opencc_config_path.extension().string_utf8() == ".ini") {
LOG(ERROR) << "please upgrade opencc_config to an opencc 1.0 config file.";
return nullptr;
}
Expand Down
16 changes: 8 additions & 8 deletions src/rime/lever/deployment_tasks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ bool DetectModifications::Run(Deployer* deployer) {
for (fs::directory_iterator iter(p), end; iter != end; ++iter) {
path entry(iter->path());
if (fs::is_regular_file(fs::canonical(entry)) &&
entry.extension().u8string() == ".yaml" &&
entry.filename().u8string() != "user.yaml") {
entry.extension().string_utf8() == ".yaml" &&
entry.filename().string_utf8() != "user.yaml") {
last_modified =
(std::max)(last_modified,
filesystem::to_time_t(fs::last_write_time(entry)));
Expand Down Expand Up @@ -460,7 +460,7 @@ bool PrebuildAllSchemas::Run(Deployer* deployer) {
for (fs::directory_iterator iter(shared_data_path), end; iter != end;
++iter) {
path entry(iter->path());
if (boost::ends_with(entry.filename().u8string(), ".schema.yaml")) {
if (boost::ends_with(entry.filename().string_utf8(), ".schema.yaml")) {
the<DeploymentTask> t(new SchemaUpdate(entry));
if (!t->Run(deployer))
success = false;
Expand Down Expand Up @@ -525,7 +525,7 @@ bool UserDictSync::Run(Deployer* deployer) {
}

static bool IsCustomizedCopy(const path& file_path) {
auto file_name = file_path.filename().u8string();
auto file_name = file_path.filename().string_utf8();
if (boost::ends_with(file_name, ".yaml") &&
!boost::ends_with(file_name, ".custom.yaml")) {
Config config;
Expand Down Expand Up @@ -556,7 +556,7 @@ bool BackupConfigFiles::Run(Deployer* deployer) {
path entry(iter->path());
if (!fs::is_regular_file(entry))
continue;
auto file_extension = entry.extension().u8string();
auto file_extension = entry.extension().string_utf8();
bool is_yaml_file = file_extension == ".yaml";
bool is_text_file = file_extension == ".txt";
if (!is_yaml_file && !is_text_file)
Expand Down Expand Up @@ -596,7 +596,7 @@ bool CleanupTrash::Run(Deployer* deployer) {
path entry(iter->path());
if (!fs::is_regular_file(entry))
continue;
auto file_name = entry.filename().u8string();
auto file_name = entry.filename().string_utf8();
if (file_name == "rime.log" || boost::ends_with(file_name, ".bin") ||
boost::ends_with(file_name, ".reverse.kct") ||
boost::ends_with(file_name, ".userdb.kct.old") ||
Expand Down Expand Up @@ -650,15 +650,15 @@ bool CleanOldLogFiles::Run(Deployer* deployer) {
try {
// preparing files
for (const auto& entry : fs::directory_iterator(dir)) {
const string& file_name(entry.path().filename().u8string());
const string& file_name(path(entry.path().filename()).string_utf8());
if (entry.is_regular_file() && !entry.is_symlink() &&
boost::starts_with(file_name, app_name) &&
boost::ends_with(file_name, ".log") &&
!boost::contains(file_name, today)) {
files_to_remove.push_back(entry.path());
} else if (entry.is_symlink()) {
auto target = fs::read_symlink(entry.path());
const string& target_file_name(target.filename().u8string());
const string& target_file_name(path(target.filename()).string_utf8());
if (boost::starts_with(target_file_name, app_name) &&
boost::ends_with(target_file_name, ".log")) {
files_in_use.insert(target);
Expand Down
2 changes: 1 addition & 1 deletion src/rime/lever/switcher_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void SwitcherSettings::GetAvailableSchemasFromDirectory(const path& dir) {
}
for (fs::directory_iterator it(dir), end; it != end; ++it) {
path file_path(it->path());
if (boost::ends_with(file_path.u8string(), ".schema.yaml")) {
if (boost::ends_with(file_path.string_utf8(), ".schema.yaml")) {
Config config;
if (config.LoadFromFile(file_path)) {
SchemaInfo info;
Expand Down
2 changes: 1 addition & 1 deletion src/rime/lever/user_dict_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void UserDictManager::GetUserDictList(UserDictList* user_dict_list,
return;
}
for (fs::directory_iterator it(path_), end; it != end; ++it) {
string name = it->path().filename().u8string();
string name = path(it->path().filename()).string_utf8();
if (boost::ends_with(name, component->extension())) {
boost::erase_last(name, component->extension());
user_dict_list->push_back(name);
Expand Down
2 changes: 1 addition & 1 deletion src/rime/resource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace rime {

string ResourceResolver::ToResourceId(const string& file_path) const {
string string_path = path(file_path).generic_u8string();
string string_path = path(file_path).generic_string_utf8();
bool has_prefix = boost::starts_with(string_path, type_.prefix);
bool has_suffix = boost::ends_with(string_path, type_.suffix);
size_t start = (has_prefix ? type_.prefix.length() : 0);
Expand Down
2 changes: 1 addition & 1 deletion tools/rime_table_decompiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ int main(int argc, char* argv[]) {
fout << "# Rime dictionary\n\n";
fout << "---\n"
"name: "
<< file_path.stem().u8string()
<< rime::path(file_path).stem().string_utf8()
<< "\n"
"version: \"1.0\"\n"
"...\n\n";
Expand Down
Loading