Skip to content

Commit

Permalink
IsVariationSelectorの引数をstd::wstring_view型に戻す
Browse files Browse the repository at this point in the history
  • Loading branch information
suconbu committed May 12, 2024
1 parent fe2e51b commit 8df88f1
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion sakura_core/charset/CCodeBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ std::wstring CCodeBase::CodeToHex(const CNativeW& cSrc, const CommonSetting_Stat
EConvertResult CCodeBase::UnicodeToHex(const wchar_t* cSrc, const int iSLen, WCHAR* pDst, const CommonSetting_Statusbar* psStatusbar)
{
// IVS
if (iSLen >= 3 && IsVariationSelector(cSrc + 1, iSLen - 1)) {
if (iSLen >= 3 && IsVariationSelector(cSrc + 1)) {
if (psStatusbar->m_bDispSPCodepoint) {
auto_sprintf(pDst, L"%04X, U+%05X", cSrc[0], ConvertToUtf32(cSrc + 1));
}
Expand Down
2 changes: 1 addition & 1 deletion sakura_core/charset/CUtf8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ EConvertResult CUtf8::_UnicodeToHex(const wchar_t* cSrc, const int iSLen, WCHAR*
if (IsUTF16High(cSrc[0]) && iSLen >= 2 && IsUTF16Low(cSrc[1])) {
cBuff._GetMemory()->SetRawDataHoldBuffer(cSrc, 4);
}
else if (iSLen >= 3 && IsVariationSelector(cSrc + 1, iSLen - 1)) {
else if (iSLen >= 3 && IsVariationSelector(cSrc + 1)) {
cBuff._GetMemory()->SetRawDataHoldBuffer(cSrc, sizeof(wchar_t) * 3);
}
else {
Expand Down
4 changes: 2 additions & 2 deletions sakura_core/charset/codechecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,8 @@ char32_t ConvertToUtf32(std::wstring_view text) {
/*!
* 文字列がIVSの異体字セレクタで始まっているか判定する
*/
inline bool IsVariationSelector(const wchar_t* pStr, size_t nLen) {
return (2 <= nLen) && (pStr[0] == 0xDB40) && (0xDD00 <= pStr[1]) && (pStr[1] <= 0xDDEF);
inline bool IsVariationSelector(std::wstring_view text) {
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, nDataLen - (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, pDataLen - (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, nLength - (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
32 changes: 15 additions & 17 deletions tests/unittests/test-codechecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,21 @@ TEST(ConvertToUtf32, BinaryOnSurrogate)

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

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

// 長さ不足
EXPECT_FALSE(IsVariationSelector(ivs1, 0));
EXPECT_FALSE(IsVariationSelector(ivs1, 1));

// IVS開始-1
const auto& notivs1 = L"\U000E00FF";
EXPECT_FALSE(IsVariationSelector(notivs1, 2));

// IVS終了+1
const auto& notivs2 = L"\U000E01F0";
EXPECT_FALSE(IsVariationSelector(notivs2, 2));
// 非該当文字列
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));
}

0 comments on commit 8df88f1

Please sign in to comment.