...
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <numbers>
|
||||
#include <ranges>
|
||||
#include <regex>
|
||||
#include "mcc_traits.h"
|
||||
|
||||
namespace mcc::utils
|
||||
{
|
||||
@@ -313,4 +314,45 @@ static std::string AZZD_rad2sxg(double az, double zd, std::string_view delim = "
|
||||
}
|
||||
|
||||
|
||||
// string to pair of angles
|
||||
// " 12.3453467,102.4345346"
|
||||
// "12:43:23.423, 102:43:12.124"
|
||||
// " 12.3453467, 102:43:12.124 "
|
||||
template <mcc::traits::mcc_input_char_range R>
|
||||
std::pair<double, double> parseAnglePair(R&& str, bool hms1 = false, bool hms2 = false, std::string_view delim = ",")
|
||||
{
|
||||
std::pair<double, double> res{std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN()};
|
||||
auto found1 = std::ranges::search(std::forward<R>(str), delim);
|
||||
|
||||
if (found1.empty()) {
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string s1, s2;
|
||||
std::ranges::copy(str.begin(), found1.begin(), std::back_inserter(s1));
|
||||
|
||||
auto rem_len = std::distance(found1.end(), str.end());
|
||||
if (!rem_len) {
|
||||
return res;
|
||||
}
|
||||
|
||||
auto found2 = std::ranges::search(found1.end(), str.end(), delim.begin(), delim.end());
|
||||
if (found2.empty()) {
|
||||
std::ranges::copy(found1.end(), str.end(), std::back_inserter(s2));
|
||||
} else {
|
||||
std::ranges::copy(found1.end(), found2.end(), std::back_inserter(s2));
|
||||
}
|
||||
|
||||
auto vo1 = parsAngleString(s1, hms1);
|
||||
if (vo1) {
|
||||
auto vo2 = parsAngleString(s2, hms2);
|
||||
if (vo2) {
|
||||
res = {vo1.value(), vo2.value()};
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
} // namespace mcc::utils
|
||||
|
||||
Reference in New Issue
Block a user