Skip to content

Commit

Permalink
Format Code
Browse files Browse the repository at this point in the history
  • Loading branch information
graphemecluster committed Mar 18, 2024
1 parent 3f5926a commit 28bcd9e
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 55 deletions.
4 changes: 2 additions & 2 deletions src/rime/algo/syllabifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ int Syllabifier::BuildSyllableGraph(const string& input,
exact_match_syllables.end()) {
// Accept normal spellings only.
if (props.type != kNormalSpelling) {
accessor.Next();
continue;
accessor.Next();
continue;
}
props.is_correction = true;
props.credibility = kCorrectionCredibility;
Expand Down
16 changes: 12 additions & 4 deletions src/rime/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,19 @@ class path : public std::filesystem::path {
explicit path(const char* utf8_path) : fs_path(utf8_path) {}
#endif

path& operator/=(const path& p) { return *this = fs_path::operator/=(p); }
path& operator/=(const fs_path& p) { return *this = fs_path::operator/=(p); }
path& operator/=(const path& p) {
return *this = fs_path::operator/=(p);
}
path& operator/=(const fs_path& p) {
return *this = fs_path::operator/=(p);
}
// convert UTF-8 encoded string to native encoding, then append.
path& operator/=(const std::string& p) { return *this /= path(p); }
path& operator/=(const char* p) { return *this /= path(p); }
path& operator/=(const std::string& p) {
return *this /= path(p);
}
path& operator/=(const char* p) {
return *this /= path(p);
}

friend path operator/(const path& lhs, const path& rhs) {
return path(lhs) /= rhs;
Expand Down
4 changes: 2 additions & 2 deletions src/rime/dict/dictionary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace rime {

const double kPredictionThreshold = 4.605170185988092; // log(100)
const double kPredictionThreshold = 4.605170185988092; // log(100)

namespace dictionary {

Expand Down Expand Up @@ -253,7 +253,7 @@ static void lookup_table(Table* table,
auto entry = a.entry();
if (!predict.entries ||
cr + entry->weight > predict.credibility +
predict.entries[predict.cursor].weight) {
predict.entries[predict.cursor].weight) {
predict_pos = end_pos;
predict = {table, a.code(), entry, cr};
}
Expand Down
7 changes: 4 additions & 3 deletions src/rime/dict/table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,16 @@ TableAccessor TableQuery::Access(SyllableId syllable_id,
return TableAccessor();
}

void TableQuery::AccessAll(vector<TableAccessor>& accessors, double credibility) {
void TableQuery::AccessAll(vector<TableAccessor>& accessors,
double credibility) {
credibility += credibility_.back();
if (level_ == 0) {
if (!lv1_index_)
return;
for (size_t i = 0; i < lv1_index_->size; i++) {
auto node = &lv1_index_->at[i];
TableAccessor accessor(add_syllable(index_code_, i),
&node->entries, credibility);
TableAccessor accessor(add_syllable(index_code_, i), &node->entries,
credibility);
if (!accessor.exhausted())
accessors.push_back(accessor);
if (!node->next_level)
Expand Down
22 changes: 7 additions & 15 deletions src/rime/dict/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,13 @@
#include <rime/dict/vocabulary.h>
#include <rime/dict/string_table.h>

#define RIME_TABLE_UNION(U, V, A, a, B, b) \
struct U { \
V value; \
const A& a() const { \
return *reinterpret_cast<const A*>(this); \
} \
const B& b() const { \
return *reinterpret_cast<const B*>(this); \
} \
A& a() { \
return *reinterpret_cast<A*>(this); \
} \
B& b() { \
return *reinterpret_cast<B*>(this); \
} \
#define RIME_TABLE_UNION(U, V, A, a, B, b) \
struct U { \
V value; \
const A& a() const { return *reinterpret_cast<const A*>(this); } \
const B& b() const { return *reinterpret_cast<const B*>(this); } \
A& a() { return *reinterpret_cast<A*>(this); } \
B& b() { return *reinterpret_cast<B*>(this); } \
}

namespace rime {
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 @@ -36,7 +36,7 @@ string UserDbValue::Pack() const {
std::ostringstream packed;
packed << "c=" << commits << " d=" << dee << " t=" << tick;
if (elements.size() > 1) {
packed << " e=" << boost::join(elements, "/");
packed << " e=" << boost::join(elements, "/");
}
return packed.str();
}
Expand Down
27 changes: 15 additions & 12 deletions src/rime/gear/script_translator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,9 @@ string ScriptSyllabifier::GetPreeditString(const Phrase& cand) const {
}

string ScriptSyllabifier::GetOriginalSpelling(const Phrase& cand) const {
if (translator_ &&
(translator_->always_show_comments() || static_cast<int>(
cand.full_code().size()) <= translator_->spelling_hints())) {
if (translator_ && (translator_->always_show_comments() ||
static_cast<int>(cand.full_code().size()) <=
translator_->spelling_hints())) {
return translator_->Spell(cand.full_code());
}
return string();
Expand Down Expand Up @@ -345,9 +345,10 @@ bool ScriptTranslation::Evaluate(Dictionary* dict, UserDictionary* user_dict) {
return false;
if (phrase_ && !phrase_->empty() && phrase_->begin()->first < 0) {
const auto& entry = phrase_->begin()->second.Peek();
prediction_ = New<Phrase>(translator_->language(), "predicted_phrase", start_,
start_ + syllable_graph.interpreted_length, entry,
-phrase_->begin()->first);
prediction_ =
New<Phrase>(translator_->language(), "predicted_phrase", start_,
start_ + syllable_graph.interpreted_length, entry,
-phrase_->begin()->first);
prediction_->set_quality(std::exp(entry->weight) +
translator_->initial_quality());
phrase_->erase(phrase_->begin()->first);
Expand All @@ -361,11 +362,12 @@ bool ScriptTranslation::Evaluate(Dictionary* dict, UserDictionary* user_dict) {
// If the first candidate is a correction, make sentense.
bool is_first_candidate_a_correction = false;
if (enable_correction_) {
CheckEmpty();
PrepareCandidate();
if (candidate_) {
is_first_candidate_a_correction = syllabifier_->IsCandidateCorrection(*candidate_);
}
CheckEmpty();
PrepareCandidate();
if (candidate_) {
is_first_candidate_a_correction =
syllabifier_->IsCandidateCorrection(*candidate_);
}
}

// make sentences when there is no exact-matching phrase candidate
Expand Down Expand Up @@ -480,7 +482,8 @@ bool ScriptTranslation::PreferUserPhrase() {

return user_phrase_code_length > 0 &&
user_phrase_code_length >= phrase_code_length &&
(user_phrase_code_length > phrase_code_length || user_phrase_weight >= phrase_weight);
(user_phrase_code_length > phrase_code_length ||
user_phrase_weight >= phrase_weight);
}

void ScriptTranslation::PrepareCandidate() {
Expand Down
3 changes: 2 additions & 1 deletion src/rime/lever/deployment_tasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class RIME_API WorkspaceUpdate : public DeploymentTask {
// update a specific schema, build corresponding dictionary
class RIME_API SchemaUpdate : public DeploymentTask {
public:
explicit SchemaUpdate(const path& source_path, const bool& build_dictionary = true)
explicit SchemaUpdate(const path& source_path,
const bool& build_dictionary = true)
: source_path_(source_path), build_dictionary_(build_dictionary) {}
SchemaUpdate(TaskInitializer arg);
bool Run(Deployer* deployer);
Expand Down
6 changes: 4 additions & 2 deletions src/rime/translation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ bool DistinctTranslation::Next() {
continue;
}
if (cand->text() == phrase->text()) {
comment += (comment.empty() || cand->comment().empty() ? "" : "; ") + cand->comment();
comment += (comment.empty() || cand->comment().empty() ? "" : "; ") +
cand->comment();
translation_->Next();
candidate_set_.insert(pair);
} else {
Expand All @@ -246,7 +247,8 @@ bool DistinctTranslation::Next() {
return true;
}

bool DistinctTranslation::AlreadyHas(const pair<string, string>& candidate) const {
bool DistinctTranslation::AlreadyHas(
const pair<string, string>& candidate) const {
return candidate_set_.find(candidate) != candidate_set_.end();
}

Expand Down
5 changes: 3 additions & 2 deletions src/rime/translation.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ inline an<Translation> Cached(Args&&... args) {

class DistinctTranslation : public Translation {
public:
DistinctTranslation(an<Translation> translation, const bool combine_candidates);
DistinctTranslation(an<Translation> translation,
const bool combine_candidates);

virtual bool Next();
virtual an<Candidate> Peek();
Expand All @@ -129,7 +130,7 @@ class DistinctTranslation : public Translation {
bool AlreadyHas(const pair<string, string>& candidate) const;

const bool combine_candidates_;
set<pair<string, string> > candidate_set_;
set<pair<string, string>> candidate_set_;
an<Translation> translation_;
an<Candidate> cache_;
};
Expand Down
2 changes: 1 addition & 1 deletion src/rime_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ RIME_API Bool RimeStartMaintenance(Bool full_check) {

RIME_API Bool RimeStartQuick() {
LoadModules(kDeployerModules);
Deployer &deployer(Service::instance().deployer());
Deployer& deployer(Service::instance().deployer());
deployer.RunTask("clean_old_log_files");
if (!deployer.RunTask("installation_update")) {
return False;
Expand Down
2 changes: 1 addition & 1 deletion src/rime_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ RIME_API Bool RimeCandidateListBegin(RimeSessionId session_id,
RimeCandidateListIterator* iterator);
RIME_API Bool RimeConfigListAppendString(RimeConfig* config,
const char* key,
const char* value);
const char* value);
RIME_API Bool RimeCandidateListNext(RimeCandidateListIterator* iterator);
RIME_API void RimeCandidateListEnd(RimeCandidateListIterator* iterator);
RIME_API Bool RimeCandidateListFromIndex(RimeSessionId session_id,
Expand Down
13 changes: 4 additions & 9 deletions tools/rime_api_console.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,13 @@
#include "codepage.h"

const std::unordered_map<char, const char*> char_replacements = {
{'\0', "<\\0>"},
{'\a', "<\\a>"},
{'\b', "<\\b>"},
{'\t', "<\\t>"},
{'\n', "<\\n>"},
{'\v', "<\\v>"},
{'\f', "<\\f>"},
{'\r', "<\\r>"},
{'\0', "<\\0>"}, {'\a', "<\\a>"}, {'\b', "<\\b>"}, {'\t', "<\\t>"},
{'\n', "<\\n>"}, {'\v', "<\\v>"}, {'\f', "<\\f>"}, {'\r', "<\\r>"},
};

void print_comment(const char* str) {
if (!str) return;
if (!str)
return;
for (size_t i = 0; i < strlen(str); ++i) {
auto it = char_replacements.find(str[i]);
if (it == char_replacements.end()) {
Expand Down

0 comments on commit 28bcd9e

Please sign in to comment.