MCPcopy Create free account
hub / github.com/cxasm/notepad-- / loadFilePreNextPage

Method loadFilePreNextPage

src/cceditor/filemanager.cpp:699–754  ·  view source on GitHub ↗

加载下一页或者上一页。(二进制模式)

Source from the content-addressed store, hash-verified

697
698//加载下一页或者上一页。(二进制模式)
699int FileManager::loadFilePreNextPage(int dir, QString& filePath, HexFileMgr* & hexFileOut)
700{
701 if (m_hexFileMgr.contains(filePath))
702 {
703 hexFileOut = m_hexFileMgr.value(filePath);
704
705 //小于LITTLE_FILE_MAX的已经一次性全部在内存,没有上下页可以翻到
706 if (hexFileOut->onetimeRead)
707 {
708 return 1;
709 }
710 qint64 pos = hexFileOut->fileOffset;
711
712 if (dir == 1 && (pos >= 0))
713 {
714 //上一页
715 pos = pos - hexFileOut->contentRealSize - ONE_PAGE_BYTES;
716 if (pos < 0)
717 {
718 pos = 0;
719 }
720 }
721 else if(dir == 2 && (pos < hexFileOut->fileSize))
722 {
723
724 }
725 else
726 {
727 return 1;//没有上下页,已经是最后一页或最前一页
728 }
729
730 char* buf = new char[ONE_PAGE_BYTES+1];
731
732 hexFileOut->file->seek(pos);
733 qint64 ret = hexFileOut->file->read(buf, ONE_PAGE_BYTES);
734 if (ret <= 0)
735 {
736 return -1;
737 }
738 else
739 {
740 //读取成功
741 hexFileOut->fileOffset = hexFileOut->file->pos();
742
743 if (hexFileOut->contentBuf != nullptr)
744 {
745 delete[]hexFileOut->contentBuf;
746 }
747
748 hexFileOut->contentBuf = buf;
749 hexFileOut->contentRealSize = ret;
750 }
751 return 0;
752 }
753 return -1;
754}
755
756const int ONE_PAGE_TEXT_SIZE = 1000 * 1024;

Callers 2

slot_preHexPageMethod · 0.80
slot_nextHexPageMethod · 0.80

Calls 6

findLineEndPosFunction · 0.85
findLineStartPosFunction · 0.85
readMethod · 0.80
containsMethod · 0.45
valueMethod · 0.45
posMethod · 0.45

Tested by

no test coverage detected