Skip to content

Commit

Permalink
Telex: replace ConStr with string_view
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhngtu committed Feb 13, 2024
1 parent 0f593cb commit 6fa09fd
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 137 deletions.
102 changes: 0 additions & 102 deletions Telex/ConStr.h

This file was deleted.

3 changes: 1 addition & 2 deletions Telex/Telex.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClInclude Include="ConStr.h" />
<ClInclude Include="Telex.h" />
<ClInclude Include="TelexData.h" />
<ClInclude Include="TelexEngine.h" />
Expand Down Expand Up @@ -101,4 +100,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
3 changes: 0 additions & 3 deletions Telex/Telex.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
<ClInclude Include="TelexMaps.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ConStr.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="TelexEngine.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down
51 changes: 25 additions & 26 deletions Telex/TelexData.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#pragma once

#include "ConStr.h"
#include "TelexMaps.h"
#include "TelexEngine.h"

Expand All @@ -19,9 +18,9 @@
#define MAKE_SORTED_SET(K, n, ...) \
static constexpr const ArraySet<K, std::initializer_list<K>{__VA_ARGS__}.size(), true> n = {__VA_ARGS__}; \
static_assert(std::is_sorted(n.begin(), n.end()))
#define P(a, b) std::make_pair(WConStr(a), WConStr(b))
#define P1(a, b) std::make_pair(WConStr(a), b)
#define P2(a, b) std::make_pair(a, WConStr(b))
#define P(a, b) std::make_pair(std::wstring_view(a), std::wstring_view(b))
#define P1(a, b) std::make_pair(std::wstring_view(a), b)
#define P2(a, b) std::make_pair(a, std::wstring_view(b))
#define VI(a, b) (VInfo{a, b})

namespace VietType {
Expand All @@ -30,8 +29,8 @@ namespace Telex {
// maps that are too short are kept as generic

MAKE_SORTED_MAP(
WConStr,
WConStr,
std::wstring_view,
std::wstring_view,
transitions,
P(L"aa", L"\xe2"), //
P(L"aua", L"\xe2u"), // relaxed transformations
Expand Down Expand Up @@ -61,7 +60,7 @@ static_assert(std::all_of(transitions.begin(), transitions.end(), [](const auto&
}));

MAKE_SORTED_MAP(
WConStr,
std::wstring_view,
int,
respos,
P1(L"i\xea", 1), //
Expand All @@ -88,8 +87,8 @@ MAKE_SORTED_MAP(
static_assert(std::all_of(respos.begin(), respos.end(), [](const auto& x) { return x.second <= x.first.length(); }));

MAKE_SORTED_MAP(
WConStr,
WConStr,
std::wstring_view,
std::wstring_view,
transitions_w,
P(L"a", L"\x103"),
P(L"o", L"\x1a1"),
Expand All @@ -111,8 +110,8 @@ static_assert(std::all_of(transitions_w.begin(), transitions_w.end(), [](const a
}));

MAKE_MAP(
WConStr,
WConStr,
std::wstring_view,
std::wstring_view,
transitions_w_q,
P(L"u", L"\x1b0"),
P(L"ua", L"u\x103"),
Expand All @@ -125,7 +124,7 @@ static_assert(std::all_of(transitions_w_q.begin(), transitions_w_q.end(), [](con
}));

MAKE_SORTED_MAP(
WConStr,
std::wstring_view,
int,
respos_w,
P1(L"o\x103", 1), //
Expand All @@ -144,8 +143,8 @@ static_assert(std::all_of(respos_w.begin(), respos_w.end(), [](const auto& x) {
}));

MAKE_MAP(
WConStr,
WConStr,
std::wstring_view,
std::wstring_view,
transitions_v_c2,
P(L"u\x1a1", L"\x1b0\x1a1"), //
P(L"\x1b0"
Expand All @@ -157,14 +156,14 @@ static_assert(std::all_of(transitions_v_c2.begin(), transitions_v_c2.end(), [](c
return x.second.length() == x.first.length();
}));

MAKE_MAP(WConStr, WConStr, transitions_v_c2_q, P(L"\x1b0o", L"\x1b0\x1a1"));
MAKE_MAP(std::wstring_view, std::wstring_view, transitions_v_c2_q, P(L"\x1b0o", L"\x1b0\x1a1"));
static_assert(std::all_of(transitions_v_c2_q.begin(), transitions_v_c2_q.end(), [](const auto& x) {
return x.second.length() == x.first.length();
}));

MAKE_SORTED_MAP(
wchar_t,
WConStr,
std::wstring_view,
transitions_tones,
P2(L'a', L"a\xe0\x1ea1\x1ea3\xe1\xe3"), //
P2(L'e', L"e\xe8\x1eb9\x1ebb\xe9\x1ebd"), //
Expand All @@ -184,7 +183,7 @@ static_assert(std::all_of(transitions_tones.begin(), transitions_tones.end(), []
}));

MAKE_SORTED_SET(
WConStr,
std::wstring_view,
valid_c1,
L"", //
L"b", //
Expand Down Expand Up @@ -218,7 +217,7 @@ MAKE_SORTED_SET(
);

MAKE_SORTED_MAP(
WConStr,
std::wstring_view,
VInfo,
valid_v,
// oa_uy must be 1 as default since 0 can only be used if there is no c2
Expand Down Expand Up @@ -286,7 +285,7 @@ static_assert(std::all_of(valid_v.begin(), valid_v.end(), [](const auto& x) {
}));

MAKE_SORTED_MAP(
WConStr,
std::wstring_view,
VInfo,
valid_v_q,
P1(L"ua", VI(1, C2Mode::Either)), // c2 either with qu
Expand Down Expand Up @@ -315,7 +314,7 @@ static_assert(std::all_of(valid_v_q.begin(), valid_v_q.end(), [](const auto& x)
}));

MAKE_SORTED_MAP(
WConStr,
std::wstring_view,
VInfo,
valid_v_gi,
P1(L"", VI(-1, C2Mode::Either)), //
Expand Down Expand Up @@ -353,7 +352,7 @@ static_assert(std::all_of(valid_v_gi.begin(), valid_v_gi.end(), [](const auto& x

// bool is whether tones are restricted to s/j or not
MAKE_SORTED_MAP(
WConStr,
std::wstring_view,
bool,
valid_c2,
P1(L"", false), //
Expand All @@ -369,7 +368,7 @@ MAKE_SORTED_MAP(
);

MAKE_MAP(
WConStr,
std::wstring_view,
VInfo,
valid_v_oa_uy,
P1(L"oa", VI(0, C2Mode::Either)), //
Expand All @@ -382,7 +381,7 @@ static_assert(std::all_of(valid_v_oa_uy.begin(), valid_v_oa_uy.end(), [](const a

MAKE_SORTED_MAP(
wchar_t,
WConStr,
std::wstring_view,
backconversions,
P2(L'\xe0', L"af"), //
P2(L'\xe1', L"as"), //
Expand Down Expand Up @@ -455,7 +454,7 @@ MAKE_SORTED_MAP(

// generated from engscan (optimize=0) doubletone words
MAKE_SORTED_SET(
WConStr,
std::wstring_view,
wlist_en,
L"airs", //
L"arms", //
Expand Down Expand Up @@ -588,7 +587,7 @@ MAKE_SORTED_SET(

// generated from dualscan mode 0 (optimize=1)
MAKE_SORTED_SET(
WConStr,
std::wstring_view,
wlist_en_2,
L"ask", //
L"bask", //
Expand Down Expand Up @@ -828,7 +827,7 @@ MAKE_SORTED_SET(

// generated from dualscan mode 1 (optimize=0, autocorrect=1)
MAKE_SORTED_SET(
WConStr,
std::wstring_view,
wlist_en_ac,
L"ah", //
L"ash", //
Expand Down
4 changes: 2 additions & 2 deletions Telex/TelexEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ struct TelexEngineImpl {
auto it = source.find(e._v);
if (it != source.end() &&
(!w_mode || ((e._v != it->second || e._c2.empty()) && !(e._respos.back() & ResposTransitionW)))) {
e._v = it->second.str();
e._v = it->second;
return true;
} else {
return false;
Expand All @@ -143,7 +143,7 @@ struct TelexEngineImpl {
e._state = TelexStates::Invalid;
}

static std::optional<std::pair<WConStr, VInfo>> FindTable(const TelexEngine& e) {
static std::optional<std::pair<std::wstring_view, VInfo>> FindTable(const TelexEngine& e) {
if (e._c1 == L"q") {
return valid_v_q.find_opt(e._v);
} else if (e._c1 == L"gi") {
Expand Down
4 changes: 2 additions & 2 deletions Telex/TelexMaps.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct ArrayMap : public std::array<std::pair<K, V>, N> {
if (it != this->cend()) {
return *it;
} else {
return {};
return std::nullopt;
}
}
};
Expand Down Expand Up @@ -74,7 +74,7 @@ struct ArraySet : public std::array<K, N> {
if (it != this->cend()) {
return *it;
} else {
return {};
return std::nullopt;
}
}
};
Expand Down

0 comments on commit 6fa09fd

Please sign in to comment.