...
This commit is contained in:
@@ -27,6 +27,49 @@ static auto AdcTrimSpaces(R&& r)
|
||||
}
|
||||
|
||||
|
||||
enum class AdcTrimType { TRIM_LEFT, TRIM_RIGHT, TRIM_BOTH };
|
||||
|
||||
template <traits::adc_char_view VR, traits::adc_char_range R>
|
||||
requires std::ranges::contiguous_range<R>
|
||||
static auto AdcTrimSpacesView(R&& r, AdcTrimType type = AdcTrimType::TRIM_BOTH)
|
||||
{
|
||||
auto is_space = [](const auto& ch) { return ch == ' '; };
|
||||
|
||||
auto end = std::forward<R>(r).end();
|
||||
|
||||
auto f1 = std::forward<R>(r).begin();
|
||||
|
||||
if (type != AdcTrimType::TRIM_RIGHT) {
|
||||
// look for the first non-space symbol
|
||||
f1 = std::ranges::find_if_not(std::forward<R>(r), is_space);
|
||||
if (f1 == end) { // all are spaces!
|
||||
return VR();
|
||||
}
|
||||
}
|
||||
|
||||
auto f2 = end;
|
||||
|
||||
if (type != AdcTrimType::TRIM_LEFT) {
|
||||
auto f3 = f1;
|
||||
|
||||
do {
|
||||
f2 = std::ranges::find_if(++f3, end, is_space);
|
||||
if (f2 == end)
|
||||
break;
|
||||
f3 = std::ranges::find_if_not(f2 + 1, end, is_space);
|
||||
} while (f3 != end);
|
||||
}
|
||||
|
||||
return VR(f1, f2);
|
||||
}
|
||||
|
||||
template <traits::adc_char_range R>
|
||||
static auto AdcTrimSpacesView(R&& r, AdcTrimType type = AdcTrimType::TRIM_BOTH)
|
||||
{
|
||||
return AdcTrimSpacesView<std::string_view>(std::forward<R>(r), type);
|
||||
}
|
||||
|
||||
|
||||
template <typename ValueT, traits::adc_char_range R>
|
||||
static ValueT AdcFromChars(R&& range)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user