blob: 4813ae85b2e0c649cb8096d5451eb8565b22eb0d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
/*
* This source code is released into the public domain.
*/
module;
#include <algorithm>
#include <locale>
#include <ranges>
#include <string>
export module nihil.util:skipws;
import :ctype;
namespace nihil {
/*
* Remove leading whitespace from a string.
*/
export template<typename Char> [[nodiscard]]
auto skipws(std::basic_string_view<Char> text,
std::locale const &locale = std::locale())
-> std::basic_string_view<Char>
{
auto is_space = ctype_is(std::ctype_base::space, locale);
auto nonws = std::ranges::find_if_not(text, is_space);
return {nonws, std::ranges::end(text)};
}
export template<typename Char>
auto skipws(std::basic_string_view<Char> *text,
std::locale const &locale = std::locale())
-> void
{
*text = skipws(*text, locale);
}
} // namespace nihil
|