⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cdoclinemgr_new.cpp

📁 日本的开源编辑器源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		}else{
			++nPos;
		}
	}
	if( 0 < nPos - nBgn || 0 < cmemNextLine.GetLength() ){
		cmemCurLine.SetData( &(pArg->pInsData[nBgn]), nPos - nBgn );
		cmemCurLine += cmemNextLine;
		if( NULL == pCDocLine){
			pCDocLineNew = new CDocLine;
			pCDocLineNew->m_pLine = new CMemory;
			/* 挿入データを行終端で区切った行数カウンタ */
			if( 0 == nCount ){
				if( NULL == m_pDocLineTop ){
					m_pDocLineTop = pCDocLineNew;
				}
				pCDocLineNew->m_pPrev = m_pDocLineBot;
				if( NULL != m_pDocLineBot ){
					m_pDocLineBot->m_pNext = pCDocLineNew;
				}
				m_pDocLineBot = pCDocLineNew;
				pCDocLineNew->m_pNext = NULL;
				pCDocLineNew->m_pLine->SetData( &cmemPrevLine );
				*(pCDocLineNew->m_pLine) += cmemCurLine;

				pCDocLineNew->m_cEol = cEOLTypeNext;	/* 改行コードの種類 */

			}else{
				if( NULL != m_pDocLineBot ){
					m_pDocLineBot->m_pNext = pCDocLineNew;
				}
				pCDocLineNew->m_pPrev = m_pDocLineBot;
				m_pDocLineBot = pCDocLineNew;
				pCDocLineNew->m_pNext = NULL;
				pCDocLineNew->m_pLine->SetData( &cmemCurLine );

				pCDocLineNew->m_cEol = cEOLTypeNext;	/* 改行コードの種類 */
			}
			pCDocLine = NULL;
			++m_nLines;
			pArg->nNewPos = nPos - nBgn;	/* 挿入された部分の次の位置のデータ位置 */
		}else{
			/* 挿入データを行終端で区切った行数カウンタ */
			if( 0 == nCount ){
				pCDocLine->m_pLine->SetData( &cmemPrevLine );
				*(pCDocLine->m_pLine) += cmemCurLine;

				pCDocLine->m_cEol = cEOLTypeNext;	/* 改行コードの種類 */

				pCDocLine = pCDocLine->m_pNext;
				pArg->nNewPos = cmemPrevLine.GetLength() + nPos - nBgn;	/* 挿入された部分の次の位置のデータ位置 */
			}else{
				pCDocLineNew = new CDocLine;
				pCDocLineNew->m_pLine = new CMemory;
				pCDocLineNew->m_pPrev = pCDocLine->m_pPrev;
				pCDocLineNew->m_pNext = pCDocLine;
				pCDocLine->m_pPrev->m_pNext = pCDocLineNew;
				pCDocLine->m_pPrev = pCDocLineNew;
				pCDocLineNew->m_pLine->SetData( &cmemCurLine );

				pCDocLineNew->m_cEol = cEOLTypeNext;	/* 改行コードの種類 */

				++m_nLines;
				pArg->nNewPos = nPos - nBgn;	/* 挿入された部分の次の位置のデータ位置 */
			}
		}
	}
	pArg->nInsLineNum = m_nLines - nAllLinesOld;
end_of_func:;
	if( NULL != pCDlgCancel ){
		delete pCDlgCancel;
	}
	return;
}


//!ブックマークの全解除
/*
	@date 2001.12.03 hor
*/
void CDocLineMgr::ResetAllBookMark( void )
{
	CDocLine* pDocLine;
	pDocLine = m_pDocLineTop;
	while( NULL != pDocLine ){
		pDocLine->SetBookMark(false);
		pDocLine = pDocLine->m_pNext;
	}
	return;
}


//! ブックマーク検索
/*
	@date 2001.12.03 hor
*/
int CDocLineMgr::SearchBookMark(
	int			nLineNum,		/* 検索開始行 */
	int			bPrevOrNext,	/* 0==前方検索 1==後方検索 */
	int*		pnLineNum 		/* マッチ行 */
)
{
	CDocLine*	pDocLine;
	int			nLinePos=nLineNum;

	/* 0==前方検索 1==後方検索 */
	if( 0 == bPrevOrNext ){
		nLinePos--;
		pDocLine = GetLineInfo( nLinePos );
		while( NULL != pDocLine ){
			if(pDocLine->IsBookMarked()){
				*pnLineNum = nLinePos;				/* マッチ行 */
				return TRUE;
			}
			nLinePos--;
			pDocLine = pDocLine->m_pPrev;
		}
	}else{
		nLinePos++;
		pDocLine = GetLineInfo( nLinePos );
		while( NULL != pDocLine ){
			if(pDocLine->IsBookMarked()){
				*pnLineNum = nLinePos;				/* マッチ行 */
				return TRUE;
			}
			nLinePos++;
			pDocLine = pDocLine->m_pNext;
		}
	}
	return FALSE;
}


//! 検索条件に該当する行にブックマークをセットする
/*
	@date 2002.01.16 hor
*/
void CDocLineMgr::MarkSearchWord(
	const char*	pszPattern,		/* 検索条件 */
	int			bRegularExp,	/* 1==正規表現 */
	int			bLoHiCase,		/* 1==英大文字小文字の区別 */
	int			bWordOnly,		/* 1==単語のみ検索 */
	CBregexp*	pRegexp			/*!< [in] 正規表現コンパイルデータ。既にコンパイルされている必要がある */
)
{
	CDocLine*	pDocLine;
	const char*	pLine;
	int			nLineLen;
	char*		pszRes;
	int*		pnKey_CharCharsArr;
	//	Jun. 10, 2003 Moca
	//	lstrlenを毎回呼ばずにnPatternLenを使うようにする
	const int	nPatternLen = lstrlen( pszPattern );

	/* 1==正規表現 */
	if( bRegularExp ){
		pDocLine = GetLineInfo( 0 );
		while( NULL != pDocLine ){
			if(!pDocLine->IsBookMarked()){
				pLine = pDocLine->m_pLine->GetPtr( &nLineLen );
				// 2005.03.19 かろと 前方一致サポートのためのメソッド変更
				if( pRegexp->Match( pLine, nLineLen, 0 ) ){
					pDocLine->SetBookMark(true);
				}
			}
			pDocLine = pDocLine->m_pNext;
		}
	}else
	/* 1==単語のみ検索 */
	if( bWordOnly ){
		pDocLine = GetLineInfo( 0 );
		int nLinePos = 0;
		int nNextWordFrom = 0;
		int nNextWordFrom2;
		int nNextWordTo2;
		while( NULL != pDocLine ){
			if(!pDocLine->IsBookMarked() &&
				WhereCurrentWord( nLinePos, nNextWordFrom, &nNextWordFrom2, &nNextWordTo2 , NULL, NULL )) {
				const char* pData = pDocLine->m_pLine->GetPtr(); // 2002/2/10 aroka CMemory変更
				
				if(( nPatternLen == nNextWordTo2 - nNextWordFrom2 ) &&
				   (( FALSE == bLoHiCase && 0 == _memicmp( &(pData[nNextWordFrom2]) , pszPattern, nPatternLen )) ||
					( TRUE  == bLoHiCase && 0 ==   memcmp( &(pData[nNextWordFrom2]) , pszPattern, nPatternLen )))){
					pDocLine->SetBookMark(true);
				}else
				if( PrevOrNextWord( nLinePos, nNextWordFrom, &nNextWordFrom, FALSE, FALSE) ){
					continue;
				}
			}
			/* 次の行を見に行く */
			nLinePos++;
			pDocLine = pDocLine->m_pNext;
			nNextWordFrom = 0;
		}
	}else{
		/* 検索条件の情報 */
		pnKey_CharCharsArr = NULL;
		CDocLineMgr::CreateCharCharsArr(
			(const unsigned char *)pszPattern,
			nPatternLen,
			&pnKey_CharCharsArr
		);
		pDocLine = GetLineInfo( 0 );
		while( NULL != pDocLine ){
			if(!pDocLine->IsBookMarked()){
				pLine = pDocLine->m_pLine->GetPtr( &nLineLen );
				pszRes = SearchString(
					(const unsigned char *)pLine,
					nLineLen,
					0,
					(const unsigned char *)pszPattern,
					nPatternLen,
					pnKey_CharCharsArr,
					bLoHiCase
				);
				if( NULL != pszRes ){
					pDocLine->SetBookMark(true);
				}
			}
			pDocLine = pDocLine->m_pNext;
		}
		if( NULL != pnKey_CharCharsArr ){
			delete [] pnKey_CharCharsArr;
			pnKey_CharCharsArr = NULL;
		}
	}
	return;

}

//! 物理行番号のリストからまとめて行マーク
/*
	@date 2002.01.16 hor
*/
void CDocLineMgr::SetBookMarks( char* pMarkLines )
{
	CDocLine*	pCDocLine;
	char *p;
	char delim[] = ", ";
	p = pMarkLines;
	while(strtok(p, delim) != NULL) {
		while(strchr(delim, *p) != NULL)p++;
		pCDocLine=GetLineInfo( atol(p) );
		if(NULL!=pCDocLine)pCDocLine->SetBookMark(true);
		p += strlen(p) + 1;
	}
	return;
}


//! 行マークされてる物理行番号のリストを作る
/*
	@date 2002.01.16 hor
*/
char* CDocLineMgr::GetBookMarks( void )
{
	CDocLine*	pCDocLine;
	static char szText[MAX_MARKLINES_LEN + 1];	//2002.01.17 // Feb. 17, 2003 genta staticに
	char szBuff[10];
	int	nLinePos=0;
	pCDocLine = GetLineInfo( nLinePos );
	strcpy( szText, "" );
	while( NULL != pCDocLine ){
		if(pCDocLine->IsBookMarked()){
			wsprintf( szBuff, "%d,",nLinePos );
			if(lstrlen(szBuff)+lstrlen(szText)>MAX_MARKLINES_LEN)break;	//2002.01.17
			strcat( szText, szBuff);
		}
		nLinePos++;
		pCDocLine = pCDocLine->m_pNext;
	}
	return szText; // Feb. 17, 2003 genta
}

/*!	差分表示の全解除
	@author	MIK
	@date	2002.05.25
*/
void CDocLineMgr::ResetAllDiffMark( void )
{
	CDocLine* pDocLine;

	pDocLine = m_pDocLineTop;
	while( NULL != pDocLine )
	{
		pDocLine->SetDiffMark( 0 );
		pDocLine = pDocLine->m_pNext;
	}

	m_bIsDiffUse = false;

	return;
}

/*! 差分検索
	@author	MIK
	@date	2002.05.25
*/
int CDocLineMgr::SearchDiffMark(
	int			nLineNum,		/* 検索開始行 */
	int			bPrevOrNext,	/* 0==前方検索 1==後方検索 */
	int*		pnLineNum 		/* マッチ行 */
)
{
	CDocLine*	pDocLine;
	int			nLinePos = nLineNum;

	/* 0==前方検索 1==後方検索 */
	if( 0 == bPrevOrNext )
	{
		nLinePos--;
		pDocLine = GetLineInfo( nLinePos );
		while( NULL != pDocLine )
		{
			if( pDocLine->IsDiffMarked() )
			{
				*pnLineNum = nLinePos;				/* マッチ行 */
				return TRUE;
			}
			nLinePos--;
			pDocLine = pDocLine->m_pPrev;
		}
	}
	else
	{
		nLinePos++;
		pDocLine = GetLineInfo( nLinePos );
		while( NULL != pDocLine )
		{
			if( pDocLine->IsDiffMarked() )
			{
				*pnLineNum = nLinePos;				/* マッチ行 */
				return TRUE;
			}
			nLinePos++;
			pDocLine = pDocLine->m_pNext;
		}
	}
	return FALSE;
}

/*!	差分情報を行範囲指定で登録する。
	@author	MIK
	@date	2002/05/25
*/
void CDocLineMgr::SetDiffMarkRange( int nMode, int nStartLine, int nEndLine )
{
	int	i;
	int	nLines;
	CDocLine	*pCDocLine;

	m_bIsDiffUse = true;

	if( nStartLine < 0 ) nStartLine = 0;

	//最終行より後に削除行あり
	nLines = GetLineCount();
	if( nLines <= nEndLine )
	{
		nEndLine = nLines - 1;
		pCDocLine = GetLineInfo( nEndLine );
		if( NULL != pCDocLine ) pCDocLine->SetDiffMark( MARK_DIFF_DEL_EX );
	}

	//行範囲にマークをつける
	for( i = nStartLine; i <= nEndLine; i++ )
	{
		pCDocLine = GetLineInfo( i );
		if( NULL != pCDocLine ) pCDocLine->SetDiffMark( nMode );
	}

	return;
}

/*[EOF]*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -