44#include < string>
55#include < string_view>
66#include < set>
7- #include < regex>
87#include < string>
98#include < vector>
109#include < array>
1110#include < span>
1211#include < type_traits>
13- #include < iterator>
1412
1513#include < oryx/chron/time_types.hpp>
1614#include < oryx/chron/details/string_split.hpp>
1715#include < oryx/chron/details/ctre.hpp>
1816#include < oryx/chron/details/string_cast.hpp>
1917#include < oryx/chron/details/to_underlying.hpp>
18+ #include < oryx/chron/details/time_types_transform.hpp>
2019
2120namespace oryx ::chron {
2221
@@ -28,11 +27,6 @@ class Data {
2827 static constexpr std::array<Months, kNumberOfLongMonths > kMonthsWith31 {
2928 Months::January, Months::March, Months::May, Months::July, Months::August, Months::October, Months::December};
3029
31- static constexpr std::array<std::string_view, 12 > kMonthNames {" JAN" , " FEB" , " MAR" , " APR" , " MAY" , " JUN" ,
32- " JUL" , " AUG" , " SEP" , " OCT" , " NOV" , " DEC" };
33-
34- static constexpr std::array<std::string_view, 7 > kDayNames {" SUN" , " MON" , " TUE" , " WED" , " THU" , " FRI" , " SAT" };
35-
3630 Data () = default ;
3731
3832 auto IsValid () const -> bool { return valid_; }
@@ -103,26 +97,15 @@ template <typename T>
10397auto Data::ValidateLiteral (const std::string& s, std::set<T>& numbers, std::span<const std::string_view> names)
10498 -> bool {
10599 auto parts = details::StringSplit (s, ' ,' );
106- auto value_of_first_name = details::to_underlying (T::First);
107-
108- for (auto & name : names) {
109- std::regex regex_pattern (name.data (), std::regex_constants::ECMAScript | std::regex_constants::icase);
110-
111- for (auto & part : parts) {
112- std::string replaced;
113- std::regex_replace (std::back_inserter (replaced), part.begin (), part.end (), regex_pattern,
114- std::to_string (value_of_first_name));
115- part = replaced;
116- }
117- ++value_of_first_name;
100+ for (auto & part : parts) {
101+ details::ReplaceWithNumeric<T>(part, names);
118102 }
119-
120103 return ProcessParts (parts, numbers);
121104}
122105
123106template <typename T>
124107auto Data::ProcessParts (const std::vector<std::string>& parts, std::set<T>& numbers) -> bool {
125- bool result = true ;
108+ bool result{ true } ;
126109 for (auto & part : parts) {
127110 result &= ConvertFromStringRangeToNumberRange (part, numbers);
128111 }
@@ -215,28 +198,4 @@ auto Data::ConvertFromStringRangeToNumberRange(std::string_view range, std::set<
215198 return result;
216199}
217200
218- template <typename T>
219- requires (std::is_same_v<T, Months> || std::is_same_v<T, DayOfWeek>)
220- auto Data::ReplaceStringNameWithNumeric (std::string& s) -> std::string& {
221- auto value = details::to_underlying (T::First);
222-
223- if constexpr (std::is_same_v<T, Months>) {
224- for (auto name : kMonthNames ) {
225- std::regex regex_pattern (name.data (), std::regex_constants::ECMAScript | std::regex_constants::icase);
226- std::string replaced;
227- std::regex_replace (std::back_inserter (replaced), s.begin (), s.end (), regex_pattern, std::to_string (value));
228- s = replaced;
229- ++value;
230- }
231- } else {
232- for (auto name : kDayNames ) {
233- std::regex regex_pattern (name.data (), std::regex_constants::ECMAScript | std::regex_constants::icase);
234- std::string replaced;
235- std::regex_replace (std::back_inserter (replaced), s.begin (), s.end (), regex_pattern, std::to_string (value));
236- s = replaced;
237- ++value;
238- }
239- }
240- return s;
241- }
242201} // namespace oryx::chron
0 commit comments