Cleanup parameter parser code
This commit is contained in:
parent
f2b8b1ae2b
commit
c57e76ee41
|
@ -80,25 +80,4 @@ const String& ParametersParser::option_value(const String& name) const
|
||||||
return empty;
|
return empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ParametersParser::positional_count() const
|
|
||||||
{
|
|
||||||
return m_positional_indices.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
const String& ParametersParser::operator[] (size_t index) const
|
|
||||||
{
|
|
||||||
kak_assert(index < positional_count());
|
|
||||||
return m_params[m_positional_indices[index]];
|
|
||||||
}
|
|
||||||
|
|
||||||
ParametersParser::iterator ParametersParser::begin() const
|
|
||||||
{
|
|
||||||
return iterator(*this, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
ParametersParser::iterator ParametersParser::end() const
|
|
||||||
{
|
|
||||||
return iterator(*this, m_positional_indices.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,30 +86,13 @@ struct ParametersParser
|
||||||
// is not defined
|
// is not defined
|
||||||
const String& option_value(const String& name) const;
|
const String& option_value(const String& name) const;
|
||||||
|
|
||||||
// positional parameters count
|
struct iterator : std::iterator<std::forward_iterator_tag, String>
|
||||||
size_t positional_count() const;
|
|
||||||
|
|
||||||
struct iterator
|
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
using value_type = String;
|
|
||||||
using pointer = const value_type*;
|
|
||||||
using reference = const value_type&;
|
|
||||||
using difference_type = size_t;
|
|
||||||
using iterator_category = std::forward_iterator_tag;
|
|
||||||
|
|
||||||
iterator(const ParametersParser& parser, size_t index)
|
iterator(const ParametersParser& parser, size_t index)
|
||||||
: m_parser(parser), m_index(index) {}
|
: m_parser(parser), m_index(index) {}
|
||||||
|
|
||||||
const String& operator*() const
|
const String& operator*() const { return m_parser[m_index]; }
|
||||||
{
|
const String* operator->() const { return &m_parser[m_index]; }
|
||||||
return m_parser.m_params[m_parser.m_positional_indices[m_index]];
|
|
||||||
}
|
|
||||||
|
|
||||||
const String* operator->() const
|
|
||||||
{
|
|
||||||
return &m_parser.m_params[m_parser.m_positional_indices[m_index]];
|
|
||||||
}
|
|
||||||
|
|
||||||
iterator& operator++() { ++m_index; return *this; }
|
iterator& operator++() { ++m_index; return *this; }
|
||||||
iterator operator++(int) { auto copy = *this; ++m_index; return copy; }
|
iterator operator++(int) { auto copy = *this; ++m_index; return copy; }
|
||||||
|
@ -122,14 +105,7 @@ struct ParametersParser
|
||||||
|
|
||||||
bool operator!=(const iterator& other) const
|
bool operator!=(const iterator& other) const
|
||||||
{
|
{
|
||||||
kak_assert(&m_parser == &other.m_parser);
|
return not (*this == other);
|
||||||
return m_index != other.m_index;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator<(const iterator& other) const
|
|
||||||
{
|
|
||||||
kak_assert(&m_parser == &other.m_parser);
|
|
||||||
return m_index < other.m_index;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -137,12 +113,18 @@ struct ParametersParser
|
||||||
size_t m_index;
|
size_t m_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// positional parameters count
|
||||||
|
size_t positional_count() const { return m_positional_indices.size(); }
|
||||||
|
|
||||||
// access positional parameter by index
|
// access positional parameter by index
|
||||||
const String& operator[] (size_t index) const;
|
const String& operator[] (size_t index) const
|
||||||
// positional parameter begin
|
{
|
||||||
iterator begin() const;
|
kak_assert(index < positional_count());
|
||||||
// positional parameter end
|
return m_params[m_positional_indices[index]];
|
||||||
iterator end() const;
|
}
|
||||||
|
|
||||||
|
iterator begin() const { return iterator(*this, 0); }
|
||||||
|
iterator end() const { return iterator(*this, m_positional_indices.size()); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ParameterList m_params;
|
ParameterList m_params;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user