metaforce/Runtime/GuiSys/CWordBreakTables.cpp

191 lines
3.3 KiB
C++
Raw Normal View History

2016-03-20 00:32:30 +00:00
#include "CWordBreakTables.hpp"
namespace urde
{
struct CCharacterIdentifier
{
wchar_t chr;
u32 rank;
};
static const CCharacterIdentifier gCantBeginChars[]=
{
2016-03-21 22:01:19 +00:00
{L'!', 1},
{L')', 1},
{L',', 1},
{L'-', 1},
{L'.', 1},
{L':', 1},
{L';', 1},
{L'?', 1},
{L']', 1},
{L'}', 1},
2016-03-20 00:32:30 +00:00
{0x92, 1},
{0x94, 1},
2016-03-21 22:01:19 +00:00
{L'»', 1},
{L'', 1},
{L'', 1},
{L'', 1},
{L'', 1},
{L'', 1},
{L'', 1},
{L'', 1},
{L'', 1},
{L'', 1},
{L'', 1},
{L'', 3},
{L'', 1},
{L'', 3},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 3},
{L'', 3},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 3},
{L'', 3},
{L'', 1},
{L'', 3},
{L'', 1},
{L'', 1},
{L'', 1},
{L'', 1},
{L'', 1},
{L'', 1},
{L'', 1},
{L'', 1}
2016-03-20 00:32:30 +00:00
};
static const CCharacterIdentifier gCantEndChars[] =
{
2016-03-21 22:01:19 +00:00
{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},
{L'd', 4},
{L'f', 4},
{L'g', 4},
{L'h', 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'Ñ', 4},
{L'ñ', 4},
{L'[', 1},
{L'{', 1},
2016-03-20 00:32:30 +00:00
{0x91, 1},
{0x93, 1},
{0x91, 1},
{0x93, 1},
2016-03-21 22:01:19 +00:00
{L'¢', 2},
{L'£', 2},
{L'¥', 2},
{L'§', 2},
{L'©', 2},
{L'«', 1},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 1},
{L'', 1},
{L'', 1},
{L'', 2},
{L'', 1},
{L'', 1},
{L'', 1},
{L'', 1},
{L'', 2},
{L'', 2},
{L'', 2},
{L'', 1},
{L'', 1},
{L'', 2},
{L'', 2},
2016-03-20 00:32:30 +00:00
{0xFFEF, 2},
};
int CWordBreakTables::GetBeginRank(wchar_t ch)
{
auto search = std::lower_bound(std::cbegin(gCantBeginChars), std::cend(gCantBeginChars), ch,
[](const CCharacterIdentifier& item, const wchar_t& test) -> bool {return item.chr < test;});
if (search == std::cend(gCantBeginChars))
return 5;
return search->rank;
}
int CWordBreakTables::GetEndRank(wchar_t ch)
{
auto search = std::lower_bound(std::cbegin(gCantEndChars), std::cend(gCantEndChars), ch,
[](const CCharacterIdentifier& item, const wchar_t& test) -> bool {return item.chr < test;});
if (search == std::cend(gCantEndChars))
return 5;
return search->rank;
}
}