4#include "Stroika/Frameworks/StroikaPreComp.h"
6#include "LineBasedPartition.h"
10using namespace Stroika::Frameworks;
11using namespace Stroika::Frameworks::Led;
18LineBasedPartition::LineBasedPartition (TextStore& textStore)
19 : inherited{textStore}
24LineBasedPartition::LineBasedPartition (TextStore& textStore, SpecialHackToDisableInit )
25 : inherited{textStore}
29void LineBasedPartition::FinalConstruct ()
31 inherited::FinalConstruct ();
32 PartitionMarker* pm = GetFirstPartitionMarker ();
34 for (
size_t i = GetTextStore ().GetLength (); i > 0; --i) {
36 GetTextStore ().CopyOut (i - 1, 1, &c);
50void LineBasedPartition::UpdatePartitions (PartitionMarker* pm,
const UpdateInfo& updateInfo)
noexcept
54 if (updateInfo.fTextModified) {
64 size_t startOfInsert = max (updateInfo.fReplaceFrom, pm->GetStart ());
65 size_t endOfInsert = min (updateInfo.GetResultingRHS (), pm->GetEnd ());
66 for (
size_t i = endOfInsert; i > startOfInsert; --i) {
67 CheckForSplits (pm, updateInfo, i);
71 bool coalesce = NeedToCoalesce (pm);
85void LineBasedPartition::CheckForSplits (PartitionMarker* pm,
const UpdateInfo& updateInfo,
size_t i)
noexcept
87 Require (updateInfo.fTextModified);
88 if (updateInfo.fTextInserted[i - updateInfo.fReplaceFrom - 1] ==
'\n') {
99bool LineBasedPartition::NeedToCoalesce (PartitionMarker* pm)
noexcept
103 bool coalesce =
false;
104 if (pm->GetLength () == 0) {
108 if (pm->GetNext () !=
nullptr) {
109 size_t end = pm->GetEnd ();
110 Led_tChar endChar =
'\0';
112 CopyOut (end - 1, 1, &endChar);
113 if (endChar !=
'\n') {
121#if qStroika_Foundation_Debug_AssertionsChecked
127void LineBasedPartition::Invariant_ ()
const
129 inherited::Invariant_ ();
130 for (PartitionMarker* cur = GetFirstPartitionMarker (); cur !=
nullptr; cur = cur->GetNext ()) {
132 size_t start = cur->GetStart ();
133 size_t end = cur->GetEnd ();
134 size_t len = end - start;
136 if (end > GetEnd ()) {
140 CopyOut (start, len, buf.data ());
141 for (
size_t i = 1; i < len; ++i) {
142 Assert (buf[i - 1] !=
'\n');
144 if (cur->GetNext () !=
nullptr) {
145 Assert (buf[len - 1] ==
'\n');
#define RequireNotNull(p)
Logically halfway between std::array and std::vector; Smart 'direct memory array' - which when needed...