From e93a47975d317f59df0fdcca7cee95b6ab4ff33f Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 27 Mar 2018 19:35:55 +1100 Subject: Return a FillResult struct from RunStyles::FillRange instead of modifying arguments as that is clumsy when converting types. --- src/RunStyles.cxx | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/RunStyles.cxx') diff --git a/src/RunStyles.cxx b/src/RunStyles.cxx index fa8844bfe..03692f673 100644 --- a/src/RunStyles.cxx +++ b/src/RunStyles.cxx @@ -126,13 +126,14 @@ DISTANCE RunStyles::EndRun(DISTANCE position) const { } template -bool RunStyles::FillRange(DISTANCE &position, STYLE value, DISTANCE &fillLength) { +FillResult RunStyles::FillRange(DISTANCE position, STYLE value, DISTANCE fillLength) { + const FillResult resultNoChange{false, position, fillLength}; if (fillLength <= 0) { - return false; + return resultNoChange; } DISTANCE end = position + fillLength; if (end > Length()) { - return false; + return resultNoChange; } DISTANCE runEnd = RunFromPosition(end); if (styles->ValueAt(runEnd) == value) { @@ -140,7 +141,7 @@ bool RunStyles::FillRange(DISTANCE &position, STYLE value, DIST end = starts->PositionFromPartition(runEnd); if (position >= end) { // Whole range is already same as value so no action - return false; + return resultNoChange; } fillLength = end - position; } else { @@ -159,6 +160,7 @@ bool RunStyles::FillRange(DISTANCE &position, STYLE value, DIST } } if (runStart < runEnd) { + const FillResult result{ true, position, fillLength }; styles->SetValueAt(runStart, value); // Remove each old run over the range for (DISTANCE run=runStart+1; run::FillRange(DISTANCE &position, STYLE value, DIST RemoveRunIfSameAsPrevious(runStart); runEnd = RunFromPosition(end); RemoveRunIfEmpty(runEnd); - return true; + return result; } else { - return false; + return resultNoChange; } } template void RunStyles::SetValueAt(DISTANCE position, STYLE value) { - DISTANCE len = 1; - FillRange(position, value, len); + FillRange(position, value, 1); } template -- cgit v1.2.3