MCPcopy Create free account
hub / github.com/comaps/comaps / RemoveInversion

Function RemoveInversion

libs/editor/ui2oh.cpp:92–109  ·  view source on GitHub ↗

Returns a vector of Weekdays with no gaps and with Sunday as the last day. Exampls: su, mo, we -> mo, we, su; su, mo, fr, sa -> fr, sa, su, mo.

Source from the content-addressed store, hash-verified

90// su, mo, we -> mo, we, su;
91// su, mo, fr, sa -> fr, sa, su, mo.
92std::vector<osmoh::Weekday> RemoveInversion(editor::ui::OpeningDays const & days)
93{
94 std::vector<osmoh::Weekday> result(begin(days), end(days));
95 if ((NextWeekdayNumber(result.back()) != WeekdayNumber(result.front()) && result.back() != osmoh::Weekday::Sunday) ||
96 result.size() < 2)
97 return result;
98
99 auto inversion = adjacent_find(begin(result), end(result), [](osmoh::Weekday const a, osmoh::Weekday const b)
100 { return NextWeekdayNumber(a) != WeekdayNumber(b); });
101
102 if (inversion != end(result))
103 rotate(begin(result), ++inversion, end(result));
104
105 if (result.front() == osmoh::Weekday::Sunday)
106 rotate(begin(result), begin(result) + 1, end(result));
107
108 return result;
109}
110
111using Weekdays = std::vector<osmoh::Weekday>;
112

Callers 1

SplitIntoIntervalsFunction · 0.85

Calls 7

NextWeekdayNumberFunction · 0.85
WeekdayNumberFunction · 0.85
backMethod · 0.80
frontMethod · 0.80
beginFunction · 0.50
endFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected