📄 page.cpp
字号:
// Page.cpp: implementation of the CPage class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Page.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
BEGIN_TEST_DUMP(CPage)
TEST_DUMP(mPathName)
END_TEST_DUMP()
CPage::CPage(LPCTSTR iPathName)
:
mPathName(iPathName)
{
mLine = 1;
mColumn = 1;
}
CPage::~CPage()
{
POSITION pos = mCommentList.GetHeadPosition();
while(pos != NULL)
{
CToken* pToken = mCommentList.GetNext(pos);
delete pToken;
}
}
void CPage::AddIncludePage(CPage* ipIncludePage)
{
if(ipIncludePage == NULL)
{
ASSERT(FALSE);
return;
}
if(!IsIncludedPage(ipIncludePage))
mIncludeList.AddTail(ipIncludePage);
CPageList* pList = ipIncludePage->GetIncludeList();
ASSERT(pList != NULL);
POSITION pos = pList->GetHeadPosition();
while(pos != NULL)
{
CPage* pPage = pList->GetNext(pos);
if(!IsIncludedPage(pPage))
mIncludeList.AddTail(pPage);
}
}
BOOL CPage::IsIncludedPage(CPage* ipPage)
{
ASSERT(ipPage != NULL);
POSITION pos = mIncludeList.GetHeadPosition();
while(pos != NULL)
{
CPage* pExist = mIncludeList.GetNext(pos);
ASSERT(pExist != NULL);
if(ipPage == pExist)
return TRUE;
}
return FALSE;
}
void CPage::GetComment(CString& oComment, int iLine, int iEndLine/*=-1*/)
{
//是否有相应的注释,以下注释视为属于该标识符:
//同一行的注释
//前面行并位于其他标识符后的注释,但空行数为MAX_LINE或以上的则不算
BOOL found = FALSE;
const UINT MAX_LINE = 2;
POSITION pos = mCommentList.GetHeadPosition();
POSITION beginPos = pos;
POSITION endPos = pos;
while(pos != NULL)
{
CToken* pToken = mCommentList.GetNext(pos);
POSITION currPos = pos;
TEST_TRACE(pToken);
TEST_TRACE(pToken->GetLine());
//找到相应的分隔符
if(pToken->IsType(TT_UNDEFINED) && pToken->GetLine() == iLine)
{
endPos = currPos;
found = TRUE;
break;
}
if(pToken->IsType(TT_UNDEFINED))
beginPos = currPos;
}
if(found)
{
int line = 0;
pos = beginPos;
while(pos != NULL)
{
CToken* pToken = mCommentList.GetNext(pos);
TEST_TRACE(pToken);
if(pToken->IsType(TT_UNDEFINED))
{
if(pos != endPos)
continue;
else
break;
}
//间隔超过两行,删除前面读到的注释
if(line != 0 && pToken->GetLine() - line > MAX_LINE)
oComment.Empty();
line = pToken->GetLine();
pToken->CleanupComment(oComment);
if(pos == endPos)
break;
}
}
}
void CPage::AddComment(CToken* ipComment)
{
ASSERT(ipComment != NULL);
CToken* pTail = NULL;
if(!mCommentList.IsEmpty()) pTail = mCommentList.GetTail();
//最后一个token是分隔符
if(pTail != NULL && pTail->IsType(TT_UNDEFINED))
{
//与分隔符同一行
if(pTail->GetLine() == ipComment->GetLine())
{
//这种情况下只保留由//开始的注释
//并且插入到分隔符的前面,因为此注释属于
//分隔符所在行的标识符
if(ipComment->IsType(TT_SINCOMMENT))
{
POSITION pos = mCommentList.GetTailPosition();
mCommentList.InsertBefore(pos, ipComment);
}
else
{
delete ipComment; //忽略多行注释,删除之
}
return;
}
}
mCommentList.AddTail(ipComment);
}
void CPage::AddDividing(int iLine)
{
if(!mCommentList.IsEmpty())
{
CToken* pTail = mCommentList.GetTail();
if(pTail != NULL && pTail->IsType(TT_UNDEFINED) &&
pTail->GetLine() == iLine)
{
return;
}
}
CToken* pDivinding = new CToken(iLine, 1);
mCommentList.AddTail(pDivinding);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -