31template <
typename DISTANCE,
typename STYLE>
33 DISTANCE run = starts->PartitionFromPosition(
position);
35 while ((run > 0) && (
position == starts->PositionFromPartition(run-1))) {
42template <
typename DISTANCE,
typename STYLE>
44 DISTANCE run = RunFromPosition(
position);
45 const DISTANCE posRun = starts->PositionFromPartition(run);
49 starts->InsertPartition(run,
position);
50 styles->InsertValue(run, 1, runStyle);
55template <
typename DISTANCE,
typename STYLE>
57 starts->RemovePartition(run);
61template <
typename DISTANCE,
typename STYLE>
63 if ((run < starts->Partitions()) && (starts->Partitions() > 1)) {
64 if (starts->PositionFromPartition(run) == starts->PositionFromPartition(run+1)) {
70template <
typename DISTANCE,
typename STYLE>
72 if ((run > 0) && (run < starts->Partitions())) {
73 if (styles->ValueAt(run-1) == styles->ValueAt(run)) {
79template <
typename DISTANCE,
typename STYLE>
81 starts = Sci::make_unique<Partitioning<DISTANCE>>(8);
82 styles = Sci::make_unique<SplitVector<STYLE>>();
83 styles->InsertValue(0, 2, 0);
86template <
typename DISTANCE,
typename STYLE>
90template <
typename DISTANCE,
typename STYLE>
92 return starts->PositionFromPartition(starts->Partitions());
95template <
typename DISTANCE,
typename STYLE>
100template <
typename DISTANCE,
typename STYLE>
102 const DISTANCE run = starts->PartitionFromPosition(
position);
103 if (run < starts->Partitions()) {
104 const DISTANCE runChange = starts->PositionFromPartition(run);
107 const DISTANCE nextChange = starts->PositionFromPartition(run + 1);
120template <
typename DISTANCE,
typename STYLE>
122 return starts->PositionFromPartition(starts->PartitionFromPosition(
position));
125template <
typename DISTANCE,
typename STYLE>
127 return starts->PositionFromPartition(starts->PartitionFromPosition(
position) + 1);
130template <
typename DISTANCE,
typename STYLE>
133 if (fillLength <= 0) {
134 return resultNoChange;
136 DISTANCE end =
position + fillLength;
137 if (end > Length()) {
138 return resultNoChange;
140 DISTANCE runEnd = RunFromPosition(end);
141 if (styles->ValueAt(runEnd) == value) {
143 end = starts->PositionFromPartition(runEnd);
146 return resultNoChange;
150 runEnd = SplitRun(end);
152 DISTANCE runStart = RunFromPosition(
position);
153 if (styles->ValueAt(runStart) == value) {
156 position = starts->PositionFromPartition(runStart);
159 if (starts->PositionFromPartition(runStart) <
position) {
164 if (runStart < runEnd) {
166 styles->SetValueAt(runStart, value);
168 for (DISTANCE run=runStart+1; run<runEnd; run++) {
169 RemoveRun(runStart+1);
171 runEnd = RunFromPosition(end);
172 RemoveRunIfSameAsPrevious(runEnd);
173 RemoveRunIfSameAsPrevious(runStart);
174 runEnd = RunFromPosition(end);
175 RemoveRunIfEmpty(runEnd);
178 return resultNoChange;
182template <
typename DISTANCE,
typename STYLE>
187template <
typename DISTANCE,
typename STYLE>
189 DISTANCE runStart = RunFromPosition(
position);
190 if (starts->PositionFromPartition(runStart) ==
position) {
196 styles->SetValueAt(0, STYLE());
197 starts->InsertPartition(1, 0);
198 styles->InsertValue(1, 1, runStyle);
199 starts->InsertText(0, insertLength);
201 starts->InsertText(runStart, insertLength);
205 starts->InsertText(runStart-1, insertLength);
208 starts->InsertText(runStart, insertLength);
212 starts->InsertText(runStart, insertLength);
216template <
typename DISTANCE,
typename STYLE>
218 starts = Sci::make_unique<Partitioning<DISTANCE>>(8);
219 styles = Sci::make_unique<SplitVector<STYLE>>();
220 styles->InsertValue(0, 2, 0);
223template <
typename DISTANCE,
typename STYLE>
225 DISTANCE end =
position + deleteLength;
226 DISTANCE runStart = RunFromPosition(
position);
227 DISTANCE runEnd = RunFromPosition(end);
228 if (runStart == runEnd) {
230 starts->InsertText(runStart, -deleteLength);
231 RemoveRunIfEmpty(runStart);
234 runEnd = SplitRun(end);
235 starts->InsertText(runStart, -deleteLength);
237 for (DISTANCE run=runStart; run<runEnd; run++) {
240 RemoveRunIfEmpty(runStart);
241 RemoveRunIfSameAsPrevious(runStart);
245template <
typename DISTANCE,
typename STYLE>
247 return starts->Partitions();
250template <
typename DISTANCE,
typename STYLE>
252 for (DISTANCE run = 1; run < starts->Partitions(); run++) {
253 if (styles->ValueAt(run) != styles->ValueAt(run - 1))
259template <
typename DISTANCE,
typename STYLE>
261 return AllSame() && (styles->ValueAt(0) == value);
264template <
typename DISTANCE,
typename STYLE>
266 if (start < Length()) {
267 DISTANCE run = start ? RunFromPosition(start) : 0;
268 if (styles->ValueAt(run) == value)
271 while (run < starts->Partitions()) {
272 if (styles->ValueAt(run) == value)
273 return starts->PositionFromPartition(run);
280template <
typename DISTANCE,
typename STYLE>
283 throw std::runtime_error(
"RunStyles: Length can not be negative.");
285 if (starts->Partitions() < 1) {
286 throw std::runtime_error(
"RunStyles: Must always have 1 or more partitions.");
288 if (starts->Partitions() != styles->Length()-1) {
289 throw std::runtime_error(
"RunStyles: Partitions and styles different lengths.");
292 while (start < Length()) {
293 const DISTANCE end = EndRun(start);
295 throw std::runtime_error(
"RunStyles: Partition is 0 length.");
299 if (styles->ValueAt(styles->Length()-1) != 0) {
300 throw std::runtime_error(
"RunStyles: Unused style at end changed.");
302 for (ptrdiff_t j=1; j<styles->Length()-1; j++) {
303 if (styles->ValueAt(j) == styles->ValueAt(j-1)) {
304 throw std::runtime_error(
"RunStyles: Style of a partition same as previous.");
311#if (PTRDIFF_MAX != INT_MAX) || PLAT_HAIKU
Data structure used to partition an interval.
Defines global type name Position in the Sci internal namespace.
Data structure used to store sparse styles.
Interface to the edit control.
Main data structure for holding arrays that handle insertions and deletions efficiently.
STYLE ValueAt(DISTANCE position) const noexcept
void DeleteRange(DISTANCE position, DISTANCE deleteLength)
Styling buffer using one element for each run rather than using a filled buffer.