3#include "terminalpp/element.hpp"
5#include <boost/container_hash/hash.hpp>
9#include <initializer_list>
23 using elements_storage = std::vector<element>;
34 using iterator = elements_storage::iterator;
35 using const_iterator = elements_storage::const_iterator;
36 using reverse_iterator = elements_storage::reverse_iterator;
37 using const_reverse_iterator = elements_storage::const_reverse_iterator;
38 using difference_type = std::ptrdiff_t;
39 using size_type = std::size_t;
49 template <std::forward_iterator ForwardIterator>
51 : elements_{begin, end}
105 std::ranges::for_each(
115 : elements_(size,
elem)
124 return elements_.size();
132 return elements_.begin();
140 return elements_.begin();
149 return elements_.rbegin();
158 return elements_.rbegin();
166 return elements_.end();
174 return elements_.end();
182 return elements_.rend();
190 return elements_.rend();
198 return elements_.cbegin();
206 return elements_.cend();
214 std::swap(elements_,
other.elements_);
222 return std::numeric_limits<size_type>::max();
230 return elements_.empty();
238 return elements_[index];
245 size_type index)
const noexcept
247 return elements_[index];
255 elements_.insert(elements_.end(),
elem);
272 elements_.insert(elements_.end(),
rhs.begin(),
rhs.end());
295 template <
class InputIterator>
330 string const &
lhs,
string const &
rhs)
noexcept =
default;
337 string const &
lhs,
string const &
rhs)
noexcept =
default;
344 return boost::hash_range(
str.elements_.begin(),
str.elements_.end());
348 elements_storage elements_;
357std::ostream &operator<<(std::ostream &out,
string const &text);
368 for (
auto const &elem : tstr)
370 if (elem.glyph_.charset_ == charset::utf8)
372 for (
auto const &ch : elem.glyph_.ucharacter_)
379 result +=
static_cast<char>(ch);
384 result +=
static_cast<char>(elem.glyph_.character_);
399 element prev_element;
401 while (!text.empty())
403 result += detail::parse_element(text, prev_element);
404 prev_element = *result.rbegin();
410inline namespace literals {
411inline namespace string_literals {
417[[nodiscard]] constexpr ::terminalpp::string
operator""_ts(
418 char const *text, ::terminalpp::string::size_type length)
420 return {text, length};
427[[nodiscard]] constexpr ::terminalpp::string
operator""_ets(
428 char const *text, ::terminalpp::string::size_type length)
430 return encode(std::span{text, length});
440struct hash<terminalpp::string>
443 using result_type = std::size_t;
445 [[nodiscard]] result_type operator()(
446 argument_type
const &str)
const noexcept
448 return hash_value(str);
A class that represents strings of elements.
Definition string.hpp:22
constexpr iterator begin() noexcept
Returns an iterator to the beginning of the string.
Definition string.hpp:130
constexpr friend auto operator<=>(string const &lhs, string const &rhs) noexcept=default
Relational operators for strings.
constexpr const_iterator cbegin() noexcept
Returns an iterator to the beginning of the string.
Definition string.hpp:196
constexpr reverse_iterator rend() noexcept
Returns a reverse iterator to the reverse end of the string.
Definition string.hpp:180
constexpr const_iterator end() const noexcept
Returns an iterator to the end of the string.
Definition string.hpp:172
constexpr string(std::string const &text)
Constructor.
Definition string.hpp:92
friend string operator+(string lhs, element const &rhs)
Append operator.
Definition string.hpp:262
constexpr size_type max_size() const noexcept
Returns the maximum size of the string allowed.
Definition string.hpp:220
constexpr string & operator+=(string const &rhs)
Append operator.
Definition string.hpp:270
constexpr string()=default
Constructor.
constexpr const_reverse_iterator rend() const noexcept
Returns a reverse iterator to the reverse end of the string.
Definition string.hpp:188
constexpr void erase()
Erase.
Definition string.hpp:305
constexpr string & operator+=(element const &elem)
Append operator.
Definition string.hpp:253
constexpr string(std::initializer_list< element > const &ilist)
Initializer List Constructor.
Definition string.hpp:58
constexpr void erase(iterator range_begin)
Erase.
Definition string.hpp:313
constexpr void insert(iterator pos, element const &elem)
Inserts an element at the iterator position.
Definition string.hpp:287
constexpr const_iterator cend() noexcept
Returns an iterator to the end of the string.
Definition string.hpp:204
constexpr size_type size() const noexcept
Returns the number of elements in the string.
Definition string.hpp:122
constexpr string(ForwardIterator &&begin, ForwardIterator &&end)
Range Constructor.
Definition string.hpp:50
constexpr reverse_iterator rbegin() noexcept
Returns a reverse iterator to the reverse beginning of the string.
Definition string.hpp:147
constexpr void swap(string &other) noexcept
Swaps the contents of this and another string.
Definition string.hpp:212
constexpr void erase(iterator range_begin, iterator range_end)
Erase.
Definition string.hpp:321
constexpr const_iterator begin() const noexcept
Returns an iterator to the beginning of the string.
Definition string.hpp:138
constexpr string(std::string const &text, terminalpp::attribute const &attr)
Constructor.
Definition string.hpp:102
constexpr iterator end() noexcept
Returns an iterator to the end of the string.
Definition string.hpp:164
constexpr reference operator[](size_type index) noexcept
Array access operator.
Definition string.hpp:236
constexpr string(char const *text)
Constructor.
Definition string.hpp:69
constexpr const_reverse_iterator rbegin() const noexcept
Returns a reverse iterator to the reverse beginning of the string.
Definition string.hpp:156
constexpr const_reference operator[](size_type index) const noexcept
Array access operator.
Definition string.hpp:244
TERMINALPP_EXPORT constexpr friend bool operator==(string const &lhs, string const &rhs) noexcept=default
Equality operator.
friend string operator+(string lhs, string const &rhs)
Append operator.
Definition string.hpp:279
friend std::size_t hash_value(string const &str) noexcept
Hash function.
Definition string.hpp:342
constexpr void insert(iterator pos, InputIterator range_begin, InputIterator range_end)
Inserts a range of elements at the iterator position.
Definition string.hpp:296
constexpr string(size_type size, terminalpp::element const &elem)
Construct a string of a number of identical elements.
Definition string.hpp:114
constexpr bool empty() const noexcept
Returns whether the string is empty or not.
Definition string.hpp:228
constexpr string(char const *text, size_type len)
Constructor.
Definition string.hpp:81
A structure that carries around the presentation attributes of an ANSI element.
Definition attribute.hpp:17
A structure representing an ANSI graphics effect (e.g. intensity, underlining)
Definition effect.hpp:27
constexpr effect() noexcept
Initialises the intensity to the default (normal) value.
Definition effect.hpp:31
A structure that represents the fundamental printable element of a terminal screen,...
Definition element.hpp:20