Skip to content

Commit

Permalink
reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhngtu committed Jul 29, 2022
1 parent 3f76d74 commit 42197da
Show file tree
Hide file tree
Showing 56 changed files with 549 additions and 565 deletions.
12 changes: 12 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
BasedOnStyle: Microsoft
BreakBeforeBraces: Attach
NamespaceIndentation: None
BinPackArguments: false
BinPackParameters: false
ColumnLimit: 120
PointerAlignment: Left
SortIncludes: false
AlignAfterOpenBracket: AlwaysBreak
Cpp11BracedListStyle: true
AccessModifierOffset: -4
AlwaysBreakTemplateDeclarations: Yes
95 changes: 22 additions & 73 deletions Telex/TelexData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ const generic_map_type<std::wstring, std::wstring> transitions_w = {
{L"oa", L"o\x103"},
{L"oi", L"\x1a1i"},
{L"u", L"\x1b0"},
{L"ua", L"\x1b0""a"},
{L"ua",
L"\x1b0"
"a"},
{L"ui", L"\x1b0i"},
{L"uo", L"u\x1a1"},
{L"uu", L"\x1b0u"},
Expand Down Expand Up @@ -199,7 +201,7 @@ const generic_map_type<std::wstring, VInfo> valid_v = {
{L"u\xf4i", {1, C2Mode::NoC2}}, // uôi
{L"u\x1a1", {1, C2Mode::NoC2}}, //
// "uya" cannot be accented
{L"\x1b0\x61", {0, C2Mode::NoC2}}, // ưa
{L"\x1b0\x61", {0, C2Mode::NoC2}}, // ưa
{L"\x1b0i", {0, C2Mode::NoC2}}, // ưi
{L"\x1b0\x1a1i", {1, C2Mode::NoC2}}, // ươi
{L"\x1b0\x1a1u", {1, C2Mode::NoC2}}, // ươu
Expand All @@ -221,7 +223,7 @@ const generic_map_type<std::wstring, VInfo> valid_v_q = {
{L"uay", {1, C2Mode::NoC2}},
{L"ue", {1, C2Mode::Either}},
{L"ui", {1, C2Mode::NoC2}},
{L"u\xf4", {1, C2Mode::MustC2}}, //
{L"u\xf4", {1, C2Mode::MustC2}}, //
{L"u\x1a1", {1, C2Mode::NoC2}}, //
{L"u\x103", {1, C2Mode::MustC2}}, //
};
Expand Down Expand Up @@ -251,7 +253,7 @@ const generic_map_type<std::wstring, VInfo> valid_v_gi = {
{L"e", {0, C2Mode::NoC2}},
{L"\xea", {0, C2Mode::MustC2}}, // ê
{L"o", {0, C2Mode::Either}},
{L"\xf4", {0, C2Mode::Either}}, // ô
{L"\xf4", {0, C2Mode::Either}}, // ô
{L"\x1a1", {0, C2Mode::Either}}, // ơ
{L"u", {0, C2Mode::MustC2}},
{L"\x1b0", {0, C2Mode::Either}}, // ư
Expand Down Expand Up @@ -297,74 +299,21 @@ const generic_map_type<std::wstring, VInfo> valid_v_oa_uy = {
};

const generic_map_type<wchar_t, std::wstring> backconversions = {
{ L'\xe0', L"af" },
{ L'\xe1', L"as" },
{ L'\xe2', L"aa" },
{ L'\xe3', L"ax" },
{ L'\xe8', L"ef" },
{ L'\xe9', L"es" },
{ L'\xea', L"ee" },
{ L'\xec', L"if" },
{ L'\xed', L"is" },
{ L'\xf2', L"of" },
{ L'\xf3', L"os" },
{ L'\xf4', L"oo" },
{ L'\xf5', L"ox" },
{ L'\xf9', L"uf" },
{ L'\xfa', L"us" },
{ L'\xfd', L"ys" },
{ L'\x103', L"aw" },
{ L'\x111', L"dd" },
{ L'\x129', L"ix" },
{ L'\x169', L"ux" },
{ L'\x1a1', L"ow" },
{ L'\x1b0', L"uw" },
{ L'\x1ea1', L"aj" },
{ L'\x1ea3', L"ar" },
{ L'\x1ea5', L"aas" },
{ L'\x1ea7', L"aaf" },
{ L'\x1ea9', L"aar" },
{ L'\x1eab', L"aax" },
{ L'\x1ead', L"aaj" },
{ L'\x1eaf', L"aws" },
{ L'\x1eb1', L"awf" },
{ L'\x1eb3', L"awr" },
{ L'\x1eb5', L"awx" },
{ L'\x1eb7', L"awj" },
{ L'\x1eb9', L"ej" },
{ L'\x1ebb', L"er" },
{ L'\x1ebd', L"ex" },
{ L'\x1ebf', L"ees" },
{ L'\x1ec1', L"eef" },
{ L'\x1ec3', L"eer" },
{ L'\x1ec5', L"eex" },
{ L'\x1ec7', L"eej" },
{ L'\x1ec9', L"ir" },
{ L'\x1ecb', L"ij" },
{ L'\x1ecd', L"oj" },
{ L'\x1ecf', L"or" },
{ L'\x1ed1', L"oos" },
{ L'\x1ed3', L"oof" },
{ L'\x1ed5', L"oor" },
{ L'\x1ed7', L"oox" },
{ L'\x1ed9', L"ooj" },
{ L'\x1edb', L"ows" },
{ L'\x1edd', L"owf" },
{ L'\x1edf', L"owr" },
{ L'\x1ee1', L"owx" },
{ L'\x1ee3', L"owj" },
{ L'\x1ee5', L"uj" },
{ L'\x1ee7', L"ur" },
{ L'\x1ee9', L"uws" },
{ L'\x1eeb', L"uwf" },
{ L'\x1eed', L"uwr" },
{ L'\x1eef', L"uwx" },
{ L'\x1ef1', L"uwj" },
{ L'\x1ef3', L"yf" },
{ L'\x1ef5', L"yj" },
{ L'\x1ef7', L"yr" },
{ L'\x1ef9', L"yx" },
{L'\xe0', L"af"}, {L'\xe1', L"as"}, {L'\xe2', L"aa"}, {L'\xe3', L"ax"}, {L'\xe8', L"ef"},
{L'\xe9', L"es"}, {L'\xea', L"ee"}, {L'\xec', L"if"}, {L'\xed', L"is"}, {L'\xf2', L"of"},
{L'\xf3', L"os"}, {L'\xf4', L"oo"}, {L'\xf5', L"ox"}, {L'\xf9', L"uf"}, {L'\xfa', L"us"},
{L'\xfd', L"ys"}, {L'\x103', L"aw"}, {L'\x111', L"dd"}, {L'\x129', L"ix"}, {L'\x169', L"ux"},
{L'\x1a1', L"ow"}, {L'\x1b0', L"uw"}, {L'\x1ea1', L"aj"}, {L'\x1ea3', L"ar"}, {L'\x1ea5', L"aas"},
{L'\x1ea7', L"aaf"}, {L'\x1ea9', L"aar"}, {L'\x1eab', L"aax"}, {L'\x1ead', L"aaj"}, {L'\x1eaf', L"aws"},
{L'\x1eb1', L"awf"}, {L'\x1eb3', L"awr"}, {L'\x1eb5', L"awx"}, {L'\x1eb7', L"awj"}, {L'\x1eb9', L"ej"},
{L'\x1ebb', L"er"}, {L'\x1ebd', L"ex"}, {L'\x1ebf', L"ees"}, {L'\x1ec1', L"eef"}, {L'\x1ec3', L"eer"},
{L'\x1ec5', L"eex"}, {L'\x1ec7', L"eej"}, {L'\x1ec9', L"ir"}, {L'\x1ecb', L"ij"}, {L'\x1ecd', L"oj"},
{L'\x1ecf', L"or"}, {L'\x1ed1', L"oos"}, {L'\x1ed3', L"oof"}, {L'\x1ed5', L"oor"}, {L'\x1ed7', L"oox"},
{L'\x1ed9', L"ooj"}, {L'\x1edb', L"ows"}, {L'\x1edd', L"owf"}, {L'\x1edf', L"owr"}, {L'\x1ee1', L"owx"},
{L'\x1ee3', L"owj"}, {L'\x1ee5', L"uj"}, {L'\x1ee7', L"ur"}, {L'\x1ee9', L"uws"}, {L'\x1eeb', L"uwf"},
{L'\x1eed', L"uwr"}, {L'\x1eef', L"uwx"}, {L'\x1ef1', L"uwj"}, {L'\x1ef3', L"yf"}, {L'\x1ef5', L"yj"},
{L'\x1ef7', L"yr"}, {L'\x1ef9', L"yx"},
};

}
}
} // namespace Telex
} // namespace VietType
11 changes: 6 additions & 5 deletions Telex/TelexData.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace Telex {
/// ensure that c1 or v only shrinks by 1 character or stays a constant length with this transition.
/// </summary>
extern const generic_map_type<std::wstring, std::wstring> transitions;
// which character in _v that is responsible for ResposTransitionV; deleting this character will remove the ResposTransitionV key
// which character in _v that is responsible for ResposTransitionV; deleting this character will remove the
// ResposTransitionV key
extern const generic_map_type<std::wstring, int> respos;

extern const generic_map_type<std::wstring, std::wstring> transitions_w;
Expand All @@ -24,13 +25,13 @@ extern const generic_map_type<std::wstring, std::wstring> transitions_v_c2;
extern const generic_map_type<wchar_t, std::wstring> transitions_tones;

extern const generic_set_type<std::wstring> valid_c1;
extern const generic_map_type<std::wstring, VInfo> valid_v; // value: accent position
extern const generic_map_type<std::wstring, VInfo> valid_v_q; // value: accent position
extern const generic_map_type<std::wstring, VInfo> valid_v; // value: accent position
extern const generic_map_type<std::wstring, VInfo> valid_v_q; // value: accent position
extern const generic_map_type<std::wstring, VInfo> valid_v_qu; // value: accent position
extern const generic_map_type<std::wstring, VInfo> valid_v_gi; // value: accent position
extern const generic_map_type<std::wstring, bool> valid_c2;
extern const generic_map_type<std::wstring, VInfo> valid_v_oa_uy;
extern const generic_map_type<wchar_t, std::wstring> backconversions;

}
}
} // namespace Telex
} // namespace VietType
12 changes: 7 additions & 5 deletions Telex/TelexEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
namespace VietType {
namespace Telex {

enum ResposTransitions {
enum ResposTransitions
{
ResposExpunged = -1,
ResposTransitionC1 = -2,
ResposTransitionV = -3,
Expand Down Expand Up @@ -164,7 +165,8 @@ TelexStates TelexEngine::PushChar(_In_ wchar_t corig) {
_cases.push_back(ccase);
_respos.push_back(_respos_current++);

} else if (_c1 == L"d" && c == L'd' && ((_config.accept_separate_dd && _c1 == L"d") || (!_v.size() && !_c2.size()))) {
} else if (
_c1 == L"d" && c == L'd' && ((_config.accept_separate_dd && _c1 == L"d") || (!_v.size() && !_c2.size()))) {
// only used for 'dd'
// relaxed constraint: !_v.size()
_c1 = L"\x111";
Expand Down Expand Up @@ -625,7 +627,7 @@ bool TelexEngine::FindTable(_Out_ map_iterator* it) const {
bool TelexEngine::GetTonePos(_In_ bool predict, _Out_ VInfo* vinfo) const {
map_iterator it;
auto found = FindTable(&it);
VInfo retinfo = { 0 };
VInfo retinfo = {0};
if (found) {
retinfo = it->second;
} else if (predict) {
Expand Down Expand Up @@ -676,5 +678,5 @@ bool TelexEngine::CheckInvariants() const {
return true;
}

}
}
} // namespace Telex
} // namespace VietType
19 changes: 10 additions & 9 deletions Telex/TelexEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ namespace Telex {

// Committed|CommittedInvalid -> Valid (Reset)

enum class TelexStates {
Valid, // valid word, can accept more chars but cannot get result
Invalid, // invalid word but can still accept more chars
Committed, // valid, tones have been applied, cannot accept any more chars (must get result or Reset)
enum class TelexStates
{
Valid, // valid word, can accept more chars but cannot get result
Invalid, // invalid word but can still accept more chars
Committed, // valid, tones have been applied, cannot accept any more chars (must get result or Reset)
CommittedInvalid, // invalid, cannot accept any more chars
TxError = -1, // can never be a state, returned when PushChar encounters an error
TxError = -1, // can never be a state, returned when PushChar encounters an error
};

struct TelexConfig {
Expand Down Expand Up @@ -87,12 +88,12 @@ class TelexEngine {

private:
using map_iterator = generic_map_type<std::wstring, VInfo>::const_iterator;
bool FindTable(_Out_ map_iterator *it) const;
bool GetTonePos(_In_ bool predict, _Out_ VInfo *vinfo) const;
bool FindTable(_Out_ map_iterator* it) const;
bool GetTonePos(_In_ bool predict, _Out_ VInfo* vinfo) const;

private:
bool CheckInvariants() const;
};

}
}
} // namespace Telex
} // namespace VietType
16 changes: 8 additions & 8 deletions Telex/TelexInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
namespace VietType {
namespace Telex {

enum class Tones {
enum class Tones
{
Z,
F,
J,
Expand All @@ -20,7 +21,8 @@ enum class Tones {
X,
};

enum class C2Mode {
enum class C2Mode
{
Either,
MustC2,
NoC2,
Expand All @@ -31,10 +33,8 @@ struct VInfo {
C2Mode c2mode;
};

template<typename K, typename V>
using generic_map_type = std::unordered_map<K, V>;
template<typename T>
using generic_set_type = std::unordered_set<T>;
template <typename K, typename V> using generic_map_type = std::unordered_map<K, V>;
template <typename T> using generic_set_type = std::unordered_set<T>;

}
}
} // namespace Telex
} // namespace VietType
12 changes: 9 additions & 3 deletions Telex/TelexKeyTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ bool VietType::Telex::IsEditKey(_In_ WPARAM wParam, _In_ LPARAM lParam, _In_read
return false;
}

bool VietType::Telex::IsKeyEaten(_In_ bool isComposing, _In_ WPARAM wParam, _In_ LPARAM lParam, _In_reads_(256) const BYTE* keyState) {
if ((keyState[VK_CONTROL] & 0x80) || (keyState[VK_MENU] & 0x80) || (keyState[VK_LWIN] & 0x80) || (keyState[VK_RWIN] & 0x80)) {
bool VietType::Telex::IsKeyEaten(
_In_ bool isComposing, _In_ WPARAM wParam, _In_ LPARAM lParam, _In_reads_(256) const BYTE* keyState) {
if ((keyState[VK_CONTROL] & 0x80) || (keyState[VK_MENU] & 0x80) || (keyState[VK_LWIN] & 0x80) ||
(keyState[VK_RWIN] & 0x80)) {
// engine doesn't want modifiers
return false;
}
Expand All @@ -40,7 +42,11 @@ bool VietType::Telex::IsKeyEaten(_In_ bool isComposing, _In_ WPARAM wParam, _In_
return false;
}

VietType::Telex::TelexStates VietType::Telex::PushKey(_In_ VietType::Telex::TelexEngine& engine, _In_ WPARAM wParam, _In_ LPARAM lParam, _In_reads_(256) const BYTE* keyState) {
VietType::Telex::TelexStates VietType::Telex::PushKey(
_In_ VietType::Telex::TelexEngine& engine,
_In_ WPARAM wParam,
_In_ LPARAM lParam,
_In_reads_(256) const BYTE* keyState) {
if (IsTranslatableKey(wParam, lParam)) {
WCHAR c = 0;
if (ToUnicode((UINT)wParam, (lParam >> 16) & 0xff, keyState, &c, 1, 0) != 1) {
Expand Down
7 changes: 4 additions & 3 deletions Telex/TelexKeyTranslator.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ namespace Telex {

bool IsEditKey(_In_ WPARAM wParam, _In_ LPARAM lParam, _In_reads_(256) const BYTE* keyState);
bool IsKeyEaten(_In_ bool isComposing, _In_ WPARAM wParam, _In_ LPARAM lParam, _In_reads_(256) const BYTE* keyState);
TelexStates PushKey(_In_ TelexEngine& engine, _In_ WPARAM wParam, _In_ LPARAM lParam, _In_reads_(256) const BYTE* keyState);
TelexStates PushKey(
_In_ TelexEngine& engine, _In_ WPARAM wParam, _In_ LPARAM lParam, _In_reads_(256) const BYTE* keyState);

}
}
} // namespace Telex
} // namespace VietType
52 changes: 26 additions & 26 deletions Telex/TelexUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@ namespace VietType {
namespace Telex {

static const CharTypes letterClasses[26] = {
CharTypes::Vowel, // a
CharTypes::ConsoC1, // b
CharTypes::ConsoC1 | CharTypes::ConsoC2, // c
CharTypes::ConsoC1 | CharTypes::ConsoContinue, // d
CharTypes::Vowel, // e
CharTypes::Tone, // f
CharTypes::ConsoC1 | CharTypes::ConsoContinue, // g
CharTypes::ConsoC1 | CharTypes::ConsoContinue, // h
CharTypes::Vowel, // i
CharTypes::Tone, // j
CharTypes::ConsoC1, // k
CharTypes::ConsoC1, // l
CharTypes::ConsoC1 | CharTypes::ConsoC2, // m
CharTypes::ConsoC1 | CharTypes::ConsoC2, // n
CharTypes::Vowel, // o
CharTypes::ConsoC1 | CharTypes::ConsoC2, // p
CharTypes::ConsoC1, // q
CharTypes::Vowel, // a
CharTypes::ConsoC1, // b
CharTypes::ConsoC1 | CharTypes::ConsoC2, // c
CharTypes::ConsoC1 | CharTypes::ConsoContinue, // d
CharTypes::Vowel, // e
CharTypes::Tone, // f
CharTypes::ConsoC1 | CharTypes::ConsoContinue, // g
CharTypes::ConsoC1 | CharTypes::ConsoContinue, // h
CharTypes::Vowel, // i
CharTypes::Tone, // j
CharTypes::ConsoC1, // k
CharTypes::ConsoC1, // l
CharTypes::ConsoC1 | CharTypes::ConsoC2, // m
CharTypes::ConsoC1 | CharTypes::ConsoC2, // n
CharTypes::Vowel, // o
CharTypes::ConsoC1 | CharTypes::ConsoC2, // p
CharTypes::ConsoC1, // q
CharTypes::Tone | CharTypes::ConsoC1 | CharTypes::ConsoContinue, // r
CharTypes::Tone | CharTypes::ConsoC1 | CharTypes::ConsoContinue, // s
CharTypes::ConsoC1 | CharTypes::ConsoC2, // t
CharTypes::Vowel, // u
CharTypes::ConsoC1, // v
CharTypes::VowelW, // w
CharTypes::Tone | CharTypes::ConsoC1, // x
CharTypes::Vowel, // y
CharTypes::Tone, // z
CharTypes::ConsoC1 | CharTypes::ConsoC2, // t
CharTypes::Vowel, // u
CharTypes::ConsoC1, // v
CharTypes::VowelW, // w
CharTypes::Tone | CharTypes::ConsoC1, // x
CharTypes::Vowel, // y
CharTypes::Tone, // z
};

CharTypes ClassifyCharacter(_In_ wchar_t c) {
Expand Down Expand Up @@ -87,5 +87,5 @@ Tones GetTone(_In_ wchar_t c) {
}
}

}
}
} // namespace Telex
} // namespace VietType
7 changes: 4 additions & 3 deletions Telex/TelexUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
namespace VietType {
namespace Telex {

enum class CharTypes : int {
enum class CharTypes : int
{
Uncategorized = 0,
Commit = 1 << 0,
ForceCommit = 1 << 1,
Expand Down Expand Up @@ -47,5 +48,5 @@ constexpr inline CharTypes& operator&=(CharTypes lhs, CharTypes rhs) {
CharTypes ClassifyCharacter(_In_ wchar_t c);
Tones GetTone(_In_ wchar_t c);

}
}
} // namespace Telex
} // namespace VietType
Loading

0 comments on commit 42197da

Please sign in to comment.