Skip to content

Commit

Permalink
Merge 8df88f1 into 47d5dc1
Browse files Browse the repository at this point in the history
  • Loading branch information
suconbu committed May 12, 2024
2 parents 47d5dc1 + 8df88f1 commit 0a84f52
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 6 deletions.
3 changes: 1 addition & 2 deletions sakura_core/charset/codechecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,7 @@ char32_t ConvertToUtf32(std::wstring_view text) {
* 文字列がIVSの異体字セレクタで始まっているか判定する
*/
inline bool IsVariationSelector(std::wstring_view text) {
const auto cp = ConvertToUtf32(text);
return 0xe0100 <= cp && cp <= 0xe01ef;
return (2 <= text.size()) && (text[0] == 0xDB40) && (0xDD00 <= text[1]) && (text[1] <= 0xDDEF);
}

//! 上位バイトと下位バイトを交換 (主に UTF-16 LE/BE 向け)
Expand Down
2 changes: 1 addition & 1 deletion sakura_core/mem/CNativeW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ CLogicInt CNativeW::GetSizeOfChar( const wchar_t* pData, int nDataLen, int nIdx
}

// IVSの異体字セレクタチェック
if (IsVariationSelector(pData + nIdx + 1)) {
if (IsVariationSelector(std::wstring_view(pData + nIdx + 1, nDataLen - (nIdx + 1)))) {
// 正字 + 異体字セレクタで3個分
return CLogicInt(3);
}
Expand Down
2 changes: 1 addition & 1 deletion sakura_core/parse/CWordParse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ ECharKind CWordParse::WhatKindOfChar(
}
// IVS(正字 + 異体字セレクタ)
else if (nCharChars == 3 &&
IsVariationSelector(pData + nIdx + 1))
IsVariationSelector(std::wstring_view(pData + nIdx + 1, pDataLen - (nIdx + 1))))
{
ret = CK_ZEN_ETC; // 全角のその他(漢字など)
}
Expand Down
2 changes: 1 addition & 1 deletion sakura_core/view/CTextMetrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const int* CTextMetrics::GenerateDxArray(
vResultArray.push_back(cache.CalcPxWidthByFont(pText[i]) + spacing);
nIndent += vResultArray.back();

if (IsVariationSelector(pText + i + 1)) {
if (IsVariationSelector(std::wstring_view(pText + i + 1, nLength - (i + 1)))) {
vResultArray.push_back(0);
vResultArray.push_back(0);
i += 2;
Expand Down
21 changes: 21 additions & 0 deletions tests/unittests/test-codechecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,24 @@ TEST(ConvertToUtf32, BinaryOnSurrogate)
const auto& s = L"\xdcff";
EXPECT_EQ(0, ConvertToUtf32(s));
}

TEST(IsVariationSelector, VariationSelectorCheck)
{
// 異体字セレクタ開始
const auto& vs1 = L"\U000E0100";
EXPECT_TRUE(IsVariationSelector(vs1));

// 異体字セレクタ終了
const auto& vs2 = L"\U000E01EF";
EXPECT_TRUE(IsVariationSelector(vs2));

// 非該当文字列
const auto& notvs1 = L"";
EXPECT_FALSE(IsVariationSelector(notvs1));
const auto& notvs2 = L"\xDB40";
EXPECT_FALSE(IsVariationSelector(notvs2));
const auto& notvs3 = L"\U000E00FF";
EXPECT_FALSE(IsVariationSelector(notvs3));
const auto& notvs4 = L"\U000E01F0";
EXPECT_FALSE(IsVariationSelector(notvs4));
}
2 changes: 1 addition & 1 deletion tests/unittests/test-ctextmetrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ TEST(CTextMetrics, GenerateDxArray8)
// IVSのVariantSelectorが続く文字列は先頭1文字 + 幅0×2で生成する
std::vector<int> v;
FakeCache1 cache;
CTextMetrics::GenerateDxArray(&v, L"葛󠄀", 2, 0, 0, 0, 10, cache);
CTextMetrics::GenerateDxArray(&v, L"葛󠄀", 3, 0, 0, 0, 10, cache);
EXPECT_TRUE(v[0]);
EXPECT_FALSE(v[1]);
EXPECT_FALSE(v[2]);
Expand Down

0 comments on commit 0a84f52

Please sign in to comment.