Skip to content

Commit

Permalink
Merge pull request #1655 from k-kagari/feature/tests-for-cdocline
Browse files Browse the repository at this point in the history
CDocLine のテストを追加する
  • Loading branch information
kengoide committed May 3, 2021
2 parents 00bc361 + f3e3953 commit 7e1668d
Show file tree
Hide file tree
Showing 8 changed files with 273 additions and 29 deletions.
30 changes: 16 additions & 14 deletions sakura_core/CSearchAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,8 @@ void CSearchAgent::ReplaceData( DocLineReplaceArg* pArg )
pArg->pcmemDeleted->reserve( pArg->sDelRange.GetTo().y + CLogicInt(1) - pArg->sDelRange.GetFrom().y );
}

const bool bEnableExtEol = GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol;

// 2012.01.10 行内の削除&挿入のときの操作を1つにする
bool bChangeOneLine = false; // 行内の挿入
bool bInsOneLine = false;
Expand All @@ -822,7 +824,7 @@ void CSearchAgent::ReplaceData( DocLineReplaceArg* pArg )
const CNativeW& cmemLine = pArg->pInsData->back().cmemLine;
int nLen = cmemLine.GetStringLength();
const wchar_t* pInsLine = cmemLine.GetStringPtr();
if( 0 < nLen && WCODE::IsLineDelimiter(pInsLine[nLen - 1], GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol) ){
if( 0 < nLen && WCODE::IsLineDelimiter(pInsLine[nLen - 1], bEnableExtEol) ){
// 行挿入
bLastEOLReplace = true; // 仮。後で修正
}else{
Expand Down Expand Up @@ -942,14 +944,14 @@ void CSearchAgent::ReplaceData( DocLineReplaceArg* pArg )
ref._SetStringLength(nWorkPos);
ref.AppendString(pInsData, nInsLen);
ref.AppendNativeData(pCDocLineNext->_GetDocLineDataWithEOL());
pCDocLine->SetEol();
pCDocLine->SetEol(bEnableExtEol);
}else{
CNativeW tmp;
tmp.AllocStringBuffer(nNewLen);
tmp.AppendString(pLine, nWorkPos);
tmp.AppendString(pInsData, nInsLen);
tmp.AppendNativeData(pCDocLineNext->_GetDocLineDataWithEOL());
pCDocLine->SetDocLineStringMove(&tmp);
pCDocLine->SetDocLineStringMove(&tmp, bEnableExtEol);
}
if( bChangeOneLine ){
pArg->nInsSeq = CModifyVisitor().GetLineModifiedSeq(pCDocLine);
Expand All @@ -975,7 +977,7 @@ void CSearchAgent::ReplaceData( DocLineReplaceArg* pArg )
/* 行内データ削除 */
CNativeW tmp;
tmp.SetString(pLine, nWorkPos);
pCDocLine->SetDocLineStringMove(&tmp);
pCDocLine->SetDocLineStringMove(&tmp, bEnableExtEol);
CModifyVisitor().SetLineModified(pCDocLine, pArg->nDelSeq); /* 変更フラグ */
}
}
Expand Down Expand Up @@ -1012,7 +1014,7 @@ void CSearchAgent::ReplaceData( DocLineReplaceArg* pArg )
tmp.AppendString(pLine, nWorkPos);
tmp.AppendString(pInsData, nInsLen);
tmp.AppendString(&pLine[nWorkPos + nWorkLen], nAfterLen);
pCDocLine->SetDocLineStringMove(&tmp);
pCDocLine->SetDocLineStringMove(&tmp, bEnableExtEol);
}
}
if( bChangeOneLine ){
Expand Down Expand Up @@ -1079,7 +1081,7 @@ prev_line:;
CNativeW& cmemLine = pArg->pInsData->back().cmemLine;
int nLen = cmemLine.GetStringLength();
const wchar_t* pInsLine = cmemLine.GetStringPtr();
if( 0 < nLen && WCODE::IsLineDelimiter(pInsLine[nLen - 1], GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol) ){
if( 0 < nLen && WCODE::IsLineDelimiter(pInsLine[nLen - 1], bEnableExtEol) ){
if( 0 == pArg->sDelRange.GetFrom().x ){
// 挿入データの最後が改行で行頭に挿入するとき、現在行を維持する
bInsertLineMode = true;
Expand Down Expand Up @@ -1121,7 +1123,7 @@ prev_line:;
#ifdef _DEBUG
int nLen = cmemLine.GetStringLength();
const wchar_t* pInsLine = cmemLine.GetStringPtr();
assert( 0 < nLen && WCODE::IsLineDelimiter(pInsLine[nLen - 1], GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol) );
assert( 0 < nLen && WCODE::IsLineDelimiter(pInsLine[nLen - 1], bEnableExtEol) );
#endif
{
if( NULL == pCDocLine ){
Expand All @@ -1133,10 +1135,10 @@ prev_line:;
tmp.AllocStringBuffer(cPrevLine.GetLength() + cmemLine.GetStringLength());
tmp.AppendString(cPrevLine.GetPtr(), cPrevLine.GetLength());
tmp.AppendNativeData(cmemLine);
pCDocLineNew->SetDocLineStringMove(&tmp);
pCDocLineNew->SetDocLineStringMove(&tmp, bEnableExtEol);
}
else{
pCDocLineNew->SetDocLineStringMove(&cmemLine);
pCDocLineNew->SetDocLineStringMove(&cmemLine, bEnableExtEol);
}
CModifyVisitor().SetLineModified(pCDocLineNew, (*pArg->pInsData)[nCount].nSeq);
}
Expand All @@ -1152,21 +1154,21 @@ prev_line:;
cmemCurLine.swap(tmp);
tmp._SetStringLength(cPrevLine.GetLength());
tmp.AppendNativeData(cmemLine);
pCDocLine->SetDocLineStringMove(&tmp);
pCDocLine->SetDocLineStringMove(&tmp, bEnableExtEol);
cNextLine = CStringRef(cmemCurLine.GetStringPtr(), cmemCurLine.GetStringLength());
}else{
CNativeW tmp;
tmp.AllocStringBuffer(cPrevLine.GetLength() + cmemLine.GetStringLength());
tmp.AppendString(cPrevLine.GetPtr(), cPrevLine.GetLength());
tmp.AppendNativeData(cmemLine);
pCDocLine->SetDocLineStringMove(&tmp);
pCDocLine->SetDocLineStringMove(&tmp, bEnableExtEol);
}
CModifyVisitor().SetLineModified(pCDocLine, (*pArg->pInsData)[nCount].nSeq);
pCDocLine = pCDocLine->GetNextLine();
}
else{
CDocLine* pCDocLineNew = m_pcDocLineMgr->InsertNewLine(pCDocLine); //pCDocLineの前に挿入
pCDocLineNew->SetDocLineStringMove(&cmemLine);
pCDocLineNew->SetDocLineStringMove(&cmemLine, bEnableExtEol);
CModifyVisitor().SetLineModified(pCDocLineNew, (*pArg->pInsData)[nCount].nSeq);
}
}
Expand Down Expand Up @@ -1199,7 +1201,7 @@ prev_line:;
tmp.AppendString(cNextLine.GetPtr(), cNextLine.GetLength());
if( NULL == pCDocLine ){
CDocLine* pCDocLineNew = m_pcDocLineMgr->AddNewLine(); //末尾に追加
pCDocLineNew->SetDocLineStringMove(&tmp);
pCDocLineNew->SetDocLineStringMove(&tmp, bEnableExtEol);
pCDocLineNew->m_sMark = markNext;
if( !bLastEOLReplace || !bSetMark ){
CModifyVisitor().SetLineModified(pCDocLineNew, nSeq);
Expand All @@ -1213,7 +1215,7 @@ prev_line:;
pCDocLine = m_pcDocLineMgr->InsertNewLine(pCDocLine); //pCDocLineの前に挿入
pCDocLine->m_sMark = markNext;
}
pCDocLine->SetDocLineStringMove(&tmp);
pCDocLine->SetDocLineStringMove(&tmp, bEnableExtEol);
if( !bLastEOLReplace || !bSetMark ){
CModifyVisitor().SetLineModified(pCDocLine, nSeq);
}
Expand Down
2 changes: 1 addition & 1 deletion sakura_core/doc/CDocEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,5 @@ void CDocEditAgent::AddLineStrX( const wchar_t* pData, int nDataLen )
CDocLine* pDocLine = m_pcDocLineMgr->AddNewLine();

//インスタンス設定
pDocLine->SetDocLineString(pData, nDataLen);
pDocLine->SetDocLineString(pData, nDataLen, GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol);
}
17 changes: 8 additions & 9 deletions sakura_core/doc/logic/CDocLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "StdAfx.h"
#include "CDocLine.h"
#include "mem/CMemory.h"
#include "env/DLLSHAREDATA.h"

CDocLine::CDocLine()
: m_pPrev( NULL ), m_pNext( NULL )
Expand Down Expand Up @@ -46,13 +45,13 @@ bool CDocLine::IsEmptyLine() const
return true; // すべてスペースかタブだけだったらtrue。
}

void CDocLine::SetEol()
void CDocLine::SetEol(bool bEnableExtEol)
{
const wchar_t* pData = m_cLine.GetStringPtr();
int nLength = m_cLine.GetStringLength();
//改行コード設定
const wchar_t* p = &pData[nLength] - 1;
while(p>=pData && WCODE::IsLineDelimiter(*p, GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol))p--;
while(p>=pData && WCODE::IsLineDelimiter(*p, bEnableExtEol))p--;
p++;
if(p>=pData){
m_cEol.SetTypeByString(p, &pData[nLength]-p);
Expand All @@ -62,21 +61,21 @@ void CDocLine::SetEol()
}
}

void CDocLine::SetDocLineString(const wchar_t* pData, int nLength)
void CDocLine::SetDocLineString(const wchar_t* pData, int nLength, bool bEnableExtEol)
{
m_cLine.SetString(pData, nLength);
SetEol();
SetEol(bEnableExtEol);
}

void CDocLine::SetDocLineString(const CNativeW& cData)
void CDocLine::SetDocLineString(const CNativeW& cData, bool bEnableExtEol)
{
SetDocLineString(cData.GetStringPtr(), cData.GetStringLength());
SetDocLineString(cData.GetStringPtr(), cData.GetStringLength(), bEnableExtEol);
}

void CDocLine::SetDocLineStringMove(CNativeW* pcDataFrom)
void CDocLine::SetDocLineStringMove(CNativeW* pcDataFrom, bool bEnableExtEol)
{
m_cLine.swap(*pcDataFrom);
SetEol();
SetEol(bEnableExtEol);
}

void CDocLine::SetEol(const CEol& cEol, COpeBlk* pcOpeBlk)
Expand Down
8 changes: 4 additions & 4 deletions sakura_core/doc/logic/CDocLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ class CDocLine{
}
const CEol& GetEol() const{ return m_cEol; }
void SetEol(const CEol& cEol, COpeBlk* pcOpeBlk);
void SetEol(); // 現在のバッファから設定
void SetEol(bool bEnableExtEol); // 現在のバッファから設定

const CNativeW& _GetDocLineDataWithEOL() const { return m_cLine; } //###仮
CNativeW& _GetDocLineData() { return m_cLine; }

//データ設定
void SetDocLineString(const wchar_t* pData, int nLength);
void SetDocLineString(const CNativeW& cData);
void SetDocLineStringMove(CNativeW* pcData);
void SetDocLineString(const wchar_t* pData, int nLength, bool bEnableExtEol);
void SetDocLineString(const CNativeW& cData, bool bEnableExtEol);
void SetDocLineStringMove(CNativeW* pcData, bool bEnableExtEol);

//チェーン属性
CDocLine* GetPrevLine(){ return m_pPrev; }
Expand Down
2 changes: 1 addition & 1 deletion sakura_core/macro/CMacro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2192,7 +2192,7 @@ bool CMacro::HandleFunction(CEditView *View, EFunctionCode ID, const VARIANT *Ar
varCopy2.Data.lVal = 1;
}
CDocLine tmpDocLine;
tmpDocLine.SetDocLineString(varCopy.Data.bstrVal, ::SysStringLen(varCopy.Data.bstrVal));
tmpDocLine.SetDocLineString(varCopy.Data.bstrVal, ::SysStringLen(varCopy.Data.bstrVal), GetDllShareData().m_Common.m_sEdit.m_bEnableExtEol);
const int tmpLenWithEol1 = tmpDocLine.GetLengthWithoutEOL() + (0 < tmpDocLine.GetEol().GetLen() ? 1: 0);
const CLayoutXInt offset(varCopy2.Data.lVal - 1);
const CLayout tmpLayout(
Expand Down

0 comments on commit 7e1668d

Please sign in to comment.