MCPcopy Create free account
hub / github.com/Rezonality/zep / SetText

Method SetText

src/buffer.cpp:714–797  ·  view source on GitHub ↗

Replace the buffer with the text

Source from the content-addressed store, hash-verified

712
713// Replace the buffer with the text
714void ZepBuffer::SetText(const std::string& text, bool initFromFile)
715{
716 // First, clear it
717 Clear();
718
719 bool lastWasSpace = false;
720 if (!text.empty())
721 {
722 // Since incremental insertion of a big file into a gap buffer gives us worst case performance,
723 // We build the buffer in a separate array and assign it. Much faster.
724 std::vector<uint8_t> input;
725
726 m_lineEnds.clear();
727
728 // Update the gap buffer with the text
729 // We remove \r, we only care about \n
730 for (auto& ch : text)
731 {
732 if (ch == '\r')
733 {
734 m_fileFlags |= FileFlags::StrippedCR;
735 }
736 else
737 {
738 input.push_back(ch);
739 if (ch == '\n')
740 {
741 m_lineEnds.push_back(ByteIndex(input.size()));
742 lastWasSpace = false;
743 }
744 else if (ch == '\t')
745 {
746 m_fileFlags |= FileFlags::HasTabs;
747 lastWasSpace = false;
748 }
749 else if (ch == ' ')
750 {
751 if (lastWasSpace)
752 {
753 m_fileFlags |= FileFlags::HasSpaceTabs;
754 }
755 lastWasSpace = true;
756 }
757 else
758 {
759 lastWasSpace = false;
760 }
761 }
762 }
763 m_workingBuffer.assign(input.begin(), input.end());
764 }
765
766 // If file is only tabs, then force tab mode
767 if (HasFileFlags(FileFlags::HasTabs) && !HasFileFlags(FileFlags::HasSpaceTabs))
768 {
769 m_fileFlags = ZSetFlags(m_fileFlags, FileFlags::InsertTabs);
770 }
771

Callers 7

InitWithTextMethod · 0.80
InitDataGridMethod · 0.80
BeginMethod · 0.80
ShowTreeResultMethod · 0.80
HandleExCommandMethod · 0.80
TEST_FFunction · 0.80
TEST_FFunction · 0.80

Calls 11

ZSetFlagsFunction · 0.85
ZClearFlagsFunction · 0.85
assignMethod · 0.80
IndexMethod · 0.80
BroadcastMethod · 0.80
emptyMethod · 0.45
clearMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by 2

TEST_FFunction · 0.64
TEST_FFunction · 0.64