Skip to content

Commit

Permalink
インデックスの範囲チェック処理の重複を削減する為に、引数 nIndex の範囲チェックを行わない CStringRef::operator…
Browse files Browse the repository at this point in the history
… [] メソッドを追加 (#1964)

CStringRef::At メソッドの代わりに新規追加した CStringRef::operator [] メソッドを使用
  • Loading branch information
beru authored Jul 16, 2024
1 parent 199fd72 commit ea735b6
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 29 deletions.
2 changes: 1 addition & 1 deletion sakura_core/cmd/CViewCommander_Edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ void CViewCommander::DelCharForOverwrite( const wchar_t* pszInput, int nLen )
nPos += CNativeW::GetSizeOfChar(line.GetPtr(), line.GetLength(), nPos);
nDelLen = 1;
if( nKetaDiff < 0 && nPos < line.GetLength() ){
wchar_t c = line.At(nPos);
wchar_t c = line[nPos];
if( c != WCODE::TAB && !WCODE::IsLineDelimiter(c,
GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol) ){
nDelLen = 2;
Expand Down
10 changes: 5 additions & 5 deletions sakura_core/doc/layout/CLayoutMgr_DoLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static bool _GetKeywordLength(
CLogicInt nWordBgn = nPos;
CLogicInt nWordLen = CLogicInt(0);
CLayoutInt nWordKetas = CLayoutInt(0);
while(nPos<cLineStr.GetLength() && IS_KEYWORD_CHAR(cLineStr.At(nPos))){
while(nPos<cLineStr.GetLength() && IS_KEYWORD_CHAR(cLineStr[nPos])){
CLogicXInt nCharSize = CNativeW::GetSizeOfChar( cLineStr, nPos );
CLayoutInt k = cLayoutMgr.GetLayoutXOfChar(cLineStr, nPos);

Expand Down Expand Up @@ -209,8 +209,8 @@ void CLayoutMgr::_DoGyotoKinsoku(SLayoutWork* pWork, PF_OnLine pfOnLine)

if( _IsKinsokuPosHead( GetMaxLineLayout() - pWork->nPosX, nCharKetas1, nCharKetas2 )
&& IsKinsokuHead( pWork->cLineStr.At( pWork->nPos + nCharSize ) )
&& !IsKinsokuHead( pWork->cLineStr.At( pWork->nPos ) ) // 1字前が行頭禁則の対象でないこと
&& !IsKinsokuKuto( pWork->cLineStr.At( pWork->nPos ) ) ) // 1字前が句読点ぶら下げの対象でないこと
&& !IsKinsokuHead( pWork->cLineStr[ pWork->nPos ] ) // 1字前が行頭禁則の対象でないこと
&& !IsKinsokuKuto( pWork->cLineStr[ pWork->nPos ] ) ) // 1字前が句読点ぶら下げの対象でないこと
{
pWork->nWordBgn = pWork->nPos;
pWork->nWordLen = nCharSize + CNativeW::GetSizeOfChar( pWork->cLineStr, pWork->nPos + nCharSize );
Expand All @@ -233,7 +233,7 @@ void CLayoutMgr::_DoGyomatsuKinsoku(SLayoutWork* pWork, PF_OnLine pfOnLine)
CLayoutXInt nCharKetas1 = GetLayoutXOfChar( pWork->cLineStr, pWork->nPos );
CLayoutXInt nCharKetas2 = GetLayoutXOfChar( pWork->cLineStr, pWork->nPos + nCharSize );

if( _IsKinsokuPosTail( GetMaxLineLayout() - pWork->nPosX, nCharKetas1, nCharKetas2 ) && IsKinsokuTail( pWork->cLineStr.At( pWork->nPos ) ) )
if( _IsKinsokuPosTail( GetMaxLineLayout() - pWork->nPosX, nCharKetas1, nCharKetas2 ) && IsKinsokuTail( pWork->cLineStr[ pWork->nPos ] ) )
{
pWork->nWordBgn = pWork->nPos;
pWork->nWordLen = nCharSize;
Expand Down Expand Up @@ -305,7 +305,7 @@ void CLayoutMgr::_MakeOneLine(SLayoutWork* pWork, PF_OnLine pfOnLine)
//@@@ 2002.09.22 YAZAKI
color.CheckColorMODE( &pWork->pcColorStrategy, pWork->nPos, pWork->cLineStr );

if( pWork->cLineStr.At(pWork->nPos) == WCODE::TAB ){
if( pWork->cLineStr[pWork->nPos] == WCODE::TAB ){
if(_DoTab(pWork, pfOnLine)){
continue;
}
Expand Down
1 change: 1 addition & 0 deletions sakura_core/mem/CNativeW.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class CStringRef final{
[[nodiscard]] int GetLength() const noexcept { return static_cast<int>(m_nDataLen); }
[[nodiscard]] bool IsValid() const noexcept { return m_pData != nullptr; }
[[nodiscard]] wchar_t At( size_t nIndex ) const noexcept;
[[nodiscard]] wchar_t operator []( size_t nIndex ) const noexcept { return m_pData[nIndex]; }

private:
const wchar_t* m_pData = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion sakura_core/view/colors/CColor_Comment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ bool CColor_LineComment::EndColor(const CStringRef& cStr, int nPos)
}

//改行
if( WCODE::IsLineDelimiter(cStr.At(nPos), GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol) ){
if( WCODE::IsLineDelimiter(cStr[nPos], GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol) ){
return true;
}

Expand Down
16 changes: 8 additions & 8 deletions sakura_core/view/colors/CColor_Heredoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,21 @@ bool CColor_Heredoc::BeginColor(const CStringRef& cStr, int nPos)
const int length = cStr.GetLength();
int nPosIdStart = nPos + 3;
for(; nPosIdStart < length; nPosIdStart++ ){
if(cStr.At(nPosIdStart) != L'\t' && cStr.At(nPosIdStart) != L' '){
if(cStr[nPosIdStart] != L'\t' && cStr[nPosIdStart] != L' '){
break;
}
}
wchar_t quote = L'\0';
if( !(nPosIdStart < length) ){
return false;
}
if( cStr.At(nPosIdStart) == L'\'' || cStr.At(nPosIdStart) == L'"' ){
quote = cStr.At(nPosIdStart);
if (cStr[nPosIdStart] == L'\'' || cStr[nPosIdStart] == L'"') {
quote = cStr[nPosIdStart];
nPosIdStart++;
}
int i = nPosIdStart;
for(; i < length; i++ ){
if( !(WCODE::IsAZ(cStr.At(i)) || WCODE::Is09(cStr.At(i)) || cStr.At(i) == L'_') ){
if( !(WCODE::IsAZ(cStr[i]) || WCODE::Is09(cStr[i]) || cStr[i] == L'_') ){
break;
}
}
Expand All @@ -101,13 +101,13 @@ bool CColor_Heredoc::BeginColor(const CStringRef& cStr, int nPos)
}
const int k = i;
if( quote != L'\0' ){
if( i < length && cStr.At(i) == quote ){
if( i < length && cStr[i] == quote ){
i++;
}else{
return false;
}
}
if( i < length && WCODE::IsLineDelimiter(cStr.At(i), GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol) ){
if( i < length && WCODE::IsLineDelimiter(cStr[i], GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol) ){
m_id = std::wstring(cStr.GetPtr()+nPosIdStart, k - nPosIdStart);
m_pszId = m_id.c_str();
m_nSize = m_id.size();
Expand All @@ -129,11 +129,11 @@ bool CColor_Heredoc::EndColor(const CStringRef& cStr, int nPos)
return false;
}else{
int i = m_nSize;
if( i + 1 < cStr.GetLength() && cStr.At(i) == L';' && WCODE::IsLineDelimiter(cStr.At(i+1), GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol) ){
if( i + 1 < cStr.GetLength() && cStr[i] == L';' && WCODE::IsLineDelimiter(cStr[i+1], GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol) ){
// ID;
this->m_nCOMMENTEND = i;
return false;
}else if( m_nSize < cStr.GetLength() && WCODE::IsLineDelimiter(cStr.At(m_nSize), GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol) ){
}else if( m_nSize < cStr.GetLength() && WCODE::IsLineDelimiter(cStr[m_nSize], GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol) ){
// ID
this->m_nCOMMENTEND = m_nSize;
return false;
Expand Down
28 changes: 14 additions & 14 deletions sakura_core/view/colors/CColor_Quote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ bool CColor_Quote::IsCppRawString(const CStringRef& cStr, int nPos)
// \b = ^|[\s!"#$%&'()=@{};:<>?,.*/\-\+\[\]\]
wchar_t c1 = L' ';
if( 2 <= nPos ){
c1 = cStr.At(nPos-2);
c1 = cStr[nPos-2];
}
wchar_t c2 = L' ';
if( 3 <= nPos ){
c2 = cStr.At(nPos-3);
c2 = cStr[nPos-3];
}
const wchar_t* pszSep = L" \t!\"#$%&'()=@{};:<>?,.*/-+[]";
if( (c1 == 'u' || c1 == 'U' || c1 == 'L') ){
Expand All @@ -117,7 +117,7 @@ bool CColor_Quote::IsCppRawString(const CStringRef& cStr, int nPos)
}else if( c1 == '8' && c2 == 'u' ){
wchar_t c3 = L'\0';
if( 4 <= nPos ){
c3 = cStr.At(nPos-4);
c3 = cStr[nPos-4];
}
if( NULL != wcschr(pszSep, c3) ){
return true;
Expand All @@ -142,7 +142,7 @@ bool CColor_Quote::BeginColor(const CStringRef& cStr, int nPos)
case STRING_LITERAL_CPP:
if( IsCppRawString(cStr, nPos) ){
for( int i = nPos + 1; i < cStr.GetLength(); i++ ){
if( cStr.At(i) == '(' ){
if( cStr[i] == '(' ){
if( nPos + 1 < i ){
m_tag = L')';
m_tag.append( cStr.GetPtr()+nPos+1, i - (nPos + 1) );
Expand Down Expand Up @@ -179,7 +179,7 @@ bool CColor_Quote::BeginColor(const CStringRef& cStr, int nPos)
break;
case STRING_LITERAL_PYTHON:
if( nPos + 2 < cStr.GetLength()
&& cStr.At(nPos+1) == m_cQuote && cStr.At(nPos+2) == m_cQuote ){
&& cStr[nPos+1] == m_cQuote && cStr[nPos+2] == m_cQuote ){
m_nCOMMENTEND = Match_QuoteStr( m_szQuote, 3, nPos + 3, cStr, true );
m_nColorTypeIndex = 3;
return true;
Expand All @@ -198,9 +198,9 @@ bool CColor_Quote::BeginColor(const CStringRef& cStr, int nPos)
// 終了文字列がない場合は行末までを色分け
if( m_pTypeData->m_bStringEndLine ){
// 改行コードを除く
if( 0 < cStr.GetLength() && WCODE::IsLineDelimiter(cStr.At(cStr.GetLength()-1), GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol) ){
if( 1 < cStr.GetLength() && cStr.At(cStr.GetLength()-2) == WCODE::CR
&& cStr.At(cStr.GetLength()-1) == WCODE::LF ){
if( 0 < cStr.GetLength() && WCODE::IsLineDelimiter(cStr[cStr.GetLength()-1], GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol) ){
if( 1 < cStr.GetLength() && cStr[cStr.GetLength()-2] == WCODE::CR
&& cStr[cStr.GetLength()-1] == WCODE::LF ){
m_nCOMMENTEND = cStr.GetLength() - 2;
}else{
m_nCOMMENTEND = cStr.GetLength() - 1;
Expand Down Expand Up @@ -256,29 +256,29 @@ int CColor_Quote::Match_Quote( wchar_t wcQuote, int nPos, const CStringRef& cLin
nCharChars = (Int)t_max(CLogicInt(1), CNativeW::GetSizeOfChar( cLineStr.GetPtr(), cLineStr.GetLength(), i ));
if( escapeType == STRING_LITERAL_CPP ){
// エスケープ \"
if( 1 == nCharChars && cLineStr.At(i) == L'\\' ){
if( 1 == nCharChars && cLineStr[i] == L'\\' ){
++i;
if( i < cLineStr.GetLength() && WCODE::IsLineDelimiter(cLineStr.At(i), GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol) ){
if( i < cLineStr.GetLength() && WCODE::IsLineDelimiter(cLineStr[i], GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol) ){
if( pbEscapeEnd ){
*pbEscapeEnd = true;
}
}
}else
if( 1 == nCharChars && cLineStr.At(i) == wcQuote ){
if( 1 == nCharChars && cLineStr[i] == wcQuote ){
return i + 1;
}
}else if( escapeType == STRING_LITERAL_PLSQL ){
// エスケープ ""
if( 1 == nCharChars && cLineStr.At(i) == wcQuote ){
if( i + 1 < cLineStr.GetLength() && cLineStr.At(i + 1) == wcQuote ){
if( 1 == nCharChars && cLineStr[i] == wcQuote ){
if( i + 1 < cLineStr.GetLength() && cLineStr[i + 1] == wcQuote ){
++i;
}else{
return i + 1;
}
}
}else{
// エスケープなし
if( 1 == nCharChars && cLineStr.At(i) == wcQuote ){
if( 1 == nCharChars && cLineStr[i] == wcQuote ){
return i + 1;
}
}
Expand Down

0 comments on commit ea735b6

Please sign in to comment.