mirror of https://github.com/AxioDL/metaforce.git
CWordBreakTables: Make use of std::array where applicable
Same behavior, but allows directly querying iterators. We can also make these arrays constexpr.
This commit is contained in:
parent
fe32cea8fc
commit
db0091e9cd
|
@ -1,28 +1,28 @@
|
|||
#include "Runtime/GuiSys/CWordBreakTables.hpp"
|
||||
|
||||
#include <iterator>
|
||||
#include <array>
|
||||
|
||||
#include "Runtime/GCNTypes.hpp"
|
||||
#include "Runtime/rstl.hpp"
|
||||
|
||||
namespace urde {
|
||||
|
||||
namespace {
|
||||
struct CCharacterIdentifier {
|
||||
wchar_t chr;
|
||||
u32 rank;
|
||||
};
|
||||
|
||||
static const CCharacterIdentifier gCantBeginChars[] = {
|
||||
{L'!', 1}, {L')', 1}, {L',', 1}, {L'-', 1}, {L'.', 1}, {L':', 1}, {L';', 1}, {L'?', 1},
|
||||
{L']', 1}, {L'}', 1}, {0x92, 1}, {0x94, 1}, {0xBB, 1}, {0x3001, 1}, {0x3002, 1}, {0x3005, 1},
|
||||
{0x300D, 1}, {0x300F, 1}, {0x3011, 1}, {0x3015, 1}, {0x3017, 1}, {0x3019, 1}, {0x301B, 1}, {0x301C, 3},
|
||||
{0x301E, 1}, {0x302B, 3}, {0x3041, 2}, {0x3043, 2}, {0x3045, 2}, {0x3047, 2}, {0x3049, 2}, {0x3063, 2},
|
||||
{0x3083, 2}, {0x3085, 2}, {0x3087, 2}, {0x308E, 2}, {0x309D, 3}, {0x309E, 3}, {0x30A1, 2}, {0x30A3, 2},
|
||||
{0x30A5, 2}, {0x30A7, 2}, {0x30A9, 2}, {0x30C3, 2}, {0x30E3, 2}, {0x30E5, 2}, {0x30E7, 2}, {0x30EE, 2},
|
||||
{0x30F5, 2}, {0x30F6, 2}, {0x30FC, 2}, {0x30FD, 3}, {0x30FE, 3}, {0xFF01, 1}, {0xFF05, 3}, {0xFF09, 1},
|
||||
{0xFF0D, 1}, {0xFF3D, 1}, {0xFF5D, 1}, {0xFF61, 1}, {0xFF63, 1}, {0xFF64, 1}, {0xFF1F, 1}};
|
||||
constexpr std::array<CCharacterIdentifier, 63> sCantBeginChars{{
|
||||
{L'!', 1}, {L')', 1}, {L',', 1}, {L'-', 1}, {L'.', 1}, {L':', 1}, {L';', 1}, {L'?', 1}, {L']', 1},
|
||||
{L'}', 1}, {0x92, 1}, {0x94, 1}, {0xBB, 1}, {0x3001, 1}, {0x3002, 1}, {0x3005, 1}, {0x300D, 1}, {0x300F, 1},
|
||||
{0x3011, 1}, {0x3015, 1}, {0x3017, 1}, {0x3019, 1}, {0x301B, 1}, {0x301C, 3}, {0x301E, 1}, {0x302B, 3}, {0x3041, 2},
|
||||
{0x3043, 2}, {0x3045, 2}, {0x3047, 2}, {0x3049, 2}, {0x3063, 2}, {0x3083, 2}, {0x3085, 2}, {0x3087, 2}, {0x308E, 2},
|
||||
{0x309D, 3}, {0x309E, 3}, {0x30A1, 2}, {0x30A3, 2}, {0x30A5, 2}, {0x30A7, 2}, {0x30A9, 2}, {0x30C3, 2}, {0x30E3, 2},
|
||||
{0x30E5, 2}, {0x30E7, 2}, {0x30EE, 2}, {0x30F5, 2}, {0x30F6, 2}, {0x30FC, 2}, {0x30FD, 3}, {0x30FE, 3}, {0xFF01, 1},
|
||||
{0xFF05, 3}, {0xFF09, 1}, {0xFF0D, 1}, {0xFF3D, 1}, {0xFF5D, 1}, {0xFF61, 1}, {0xFF63, 1}, {0xFF64, 1}, {0xFF1F, 1},
|
||||
}};
|
||||
|
||||
static const CCharacterIdentifier gCantEndChars[] = {
|
||||
constexpr std::array<CCharacterIdentifier, 87> sCantEndChars{{
|
||||
{L'#', 2}, {L'$', 2}, {L'(', 1}, {L'@', 2}, {L'B', 4}, {L'C', 4}, {L'D', 4}, {L'E', 4}, {L'F', 4},
|
||||
{L'G', 4}, {L'J', 4}, {L'K', 4}, {L'L', 4}, {L'M', 4}, {L'N', 4}, {L'P', 4}, {L'Q', 4}, {L'R', 4},
|
||||
{L'S', 4}, {L'T', 4}, {L'V', 4}, {L'W', 4}, {L'X', 4}, {L'Y', 4}, {L'Z', 4}, {L'b', 4}, {L'c', 4},
|
||||
|
@ -33,21 +33,24 @@ static const CCharacterIdentifier gCantEndChars[] = {
|
|||
{0x20A5, 2}, {0x20A6, 2}, {0x20A7, 2}, {0x20A8, 2}, {0x20A9, 2}, {0x20AA, 2}, {0x20AB, 2}, {0x20AC, 2}, {0x300C, 1},
|
||||
{0x300E, 1}, {0x3010, 1}, {0x3012, 2}, {0x3014, 1}, {0x3016, 1}, {0x3018, 1}, {0x301A, 1}, {0xFF03, 2}, {0xFF04, 2},
|
||||
{0xFF20, 2}, {0xFF3C, 1}, {0xFF5C, 1}, {0xFFE0, 2}, {0xFFE1, 2}, {0xFFEF, 2},
|
||||
};
|
||||
}};
|
||||
} // Anonymous namespace
|
||||
|
||||
int CWordBreakTables::GetBeginRank(wchar_t ch) {
|
||||
auto search = rstl::binary_find(std::cbegin(gCantBeginChars), std::cend(gCantBeginChars), ch,
|
||||
[](const CCharacterIdentifier& item) { return item.chr; });
|
||||
if (search == std::cend(gCantBeginChars))
|
||||
const auto search = rstl::binary_find(sCantBeginChars.cbegin(), sCantBeginChars.cend(), ch,
|
||||
[](const CCharacterIdentifier& item) { return item.chr; });
|
||||
if (search == sCantBeginChars.cend()) {
|
||||
return 5;
|
||||
}
|
||||
return search->rank;
|
||||
}
|
||||
|
||||
int CWordBreakTables::GetEndRank(wchar_t ch) {
|
||||
auto search = rstl::binary_find(std::cbegin(gCantEndChars), std::cend(gCantEndChars), ch,
|
||||
[](const CCharacterIdentifier& item) { return item.chr; });
|
||||
if (search == std::cend(gCantEndChars))
|
||||
const auto search = rstl::binary_find(sCantEndChars.cbegin(), sCantEndChars.cend(), ch,
|
||||
[](const CCharacterIdentifier& item) { return item.chr; });
|
||||
if (search == sCantEndChars.cend()) {
|
||||
return 5;
|
||||
}
|
||||
return search->rank;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue