/** @file RunStyles.cxx ** Data structure used to store sparse styles. **/ // Copyright 1998-2007 by Neil Hodgson // The License.txt file describes the conditions under which this software may be distributed. #include #include #include #include #include #include #include #include #include #include #include #include #include #include "Debugging.h" #include "Position.h" #include "SplitVector.h" #include "Partitioning.h" #include "RunStyles.h" using namespace Scintilla::Internal; // Find the first run at a position template DISTANCE RunStyles::RunFromPosition(DISTANCE position) const noexcept { DISTANCE run = starts.PartitionFromPosition(position); // Go to first element with this position while ((run > 0) && (position == starts.PositionFromPartition(run-1))) { run--; } return run; } // If there is no run boundary at position, insert one continuing style. template DISTANCE RunStyles::SplitRun(DISTANCE position) { DISTANCE run = RunFromPosition(position); const DISTANCE posRun = starts.PositionFromPartition(run); if (posRun < position) { STYLE runStyle = ValueAt(position); run++; starts.InsertPartition(run, position); styles.InsertValue(run, 1, runStyle); } return run; } template void RunStyles::RemoveRun(DISTANCE run) { starts.RemovePartition(run); styles.DeleteRange(run, 1); } template void RunStyles::RemoveRunIfEmpty(DISTANCE run) { if ((run < starts.Partitions()) && (starts.Partitions() > 1)) { if (starts.PositionFromPartition(run) == starts.PositionFromPartition(run+1)) { RemoveRun(run); } } } template void RunStyles::RemoveRunIfSameAsPrevious(DISTANCE run) { if ((run > 0) && (run < starts.Partitions())) { const DISTANCE runBefore = run - 1; if (styles.ValueAt(runBefore) == styles.ValueAt(run)) { RemoveRun(run); } } } template RunStyles::RunStyles() { starts = Partitioning(8); styles = SplitVector