33 inline std::pair<int,int> range( std::string_view spec_part )
35 if( spec_part.empty() )
39 else if( spec_part.find(
'-') == std::string::npos )
41 int value =
static_cast<int>(
Str::toUInt( spec_part ) ) ;
42 return { value , value } ;
52 inline std::pair<int,int> range(
int a ,
int b ) {
return { a , b } ; }
53 inline std::pair<int,int> from(
int n ) {
return { n , -1 } ; }
54 inline std::pair<int,int> none() {
return { -1 , -1 } ; }
55 inline std::pair<int,int> all() {
return { 0 , -1 } ; }
56 inline std::string str( std::pair<int,int> range ,
int big = 9999 )
60 inline bool within( std::pair<int,int> range ,
int n )
62 return n >= 0 && n >= range.first && ( range.second < 0 || n <= range.second ) ;
64 inline void check( std::string_view spec )
68 auto r = range( spec ) ;
69 if( r.first != -1 && r.second < r.first )
70 throw Exception(
"not a valid numeric range" ) ;
A general-purpose exception class derived from std::exception and containing an error message.
static std::string fromInt(int i)
Converts int 'i' to a string.
static std::string_view tailView(std::string_view in, std::size_t pos, std::string_view default_={}) noexcept
Like tail() but returning a view into the input string.
static unsigned int toUInt(std::string_view s)
Converts string 's' to an unsigned int.
static std::string_view headView(std::string_view in, std::size_t pos, std::string_view default_={}) noexcept
Like head() but returning a view into the input string.