Thoth
A functional, expressive, asynchronous C++26 webdev library
Loading...
Searching...
No Matches
UnicodeViewer.hpp
Go to the documentation of this file.
1#pragma once
3#include <string>
4
5namespace Thoth::String {
6 using Rune = char32_t;
7
8 constexpr Rune UnknownChar{ U'\uFFFD' };
9
10
14 template<UnicodeCharConcept CharT>
16 using StringViewType = std::basic_string_view<CharT>;
17
18 constexpr explicit UnicodeViewer(StringViewType str) : _ref{ str } { }
19
20
21 struct Iterator {
22 using iterator_category = std::output_iterator_tag;
24 using difference_type = std::ptrdiff_t;
25
26 constexpr Iterator() = default;
27 constexpr explicit Iterator(StringViewType::const_iterator it, StringViewType::const_iterator end);
28
29 [[nodiscard]] constexpr value_type operator*() const;
30 [[nodiscard]] constexpr bool operator==(std::default_sentinel_t) const;
31 constexpr Iterator& operator++();
32 constexpr Iterator operator++(int);
33
34 private:
35 StringViewType::const_iterator _curIt{};
36 StringViewType::const_iterator _end{};
37 size_t _accInvalid{};
38 value_type _currValue{};
39 };
40
41 [[nodiscard]] constexpr Iterator begin() noexcept{ return Iterator{ _ref.begin(), _ref.end() }; }
42 [[nodiscard]] constexpr Iterator cbegin() const noexcept{ return Iterator{ _ref.begin(), _ref.end() }; }
43 [[nodiscard]] constexpr std::default_sentinel_t end() noexcept{ return std::default_sentinel_t{}; }
44 [[nodiscard]] constexpr std::default_sentinel_t cend() const noexcept{ return std::default_sentinel_t{}; }
45
47 [[nodiscard]] static constexpr bool IsValid(StringViewType str);
48
50 template<UnicodeCharConcept NewCharT>
51 static constexpr std::basic_string<NewCharT> ConvertTo(StringViewType str);
52 private:
53 StringViewType _ref{};
54 };
55
59}
60
61
62#include <Thoth/String/UnicodeViewer.tpp>
Definition _base.hpp:4
char32_t Rune
Definition UnicodeViewer.hpp:6
constexpr Rune UnknownChar
Definition UnicodeViewer.hpp:8
Definition UnicodeViewer.hpp:21
constexpr value_type operator*() const
constexpr bool operator==(std::default_sentinel_t) const
std::ptrdiff_t difference_type
Definition UnicodeViewer.hpp:24
Rune value_type
Definition UnicodeViewer.hpp:23
std::output_iterator_tag iterator_category
Definition UnicodeViewer.hpp:22
constexpr Iterator operator++(int)
constexpr Iterator(StringViewType::const_iterator it, StringViewType::const_iterator end)
Non owning viewer that represents Unicode encodings.
Definition UnicodeViewer.hpp:15
constexpr Iterator begin() noexcept
Definition UnicodeViewer.hpp:41
constexpr std::default_sentinel_t cend() const noexcept
Definition UnicodeViewer.hpp:44
std::basic_string_view< CharT > StringViewType
Definition UnicodeViewer.hpp:16
constexpr Iterator cbegin() const noexcept
Definition UnicodeViewer.hpp:42
constexpr std::default_sentinel_t end() noexcept
Definition UnicodeViewer.hpp:43
static constexpr bool IsValid(StringViewType str)
Check if a string does not has invalid chars.
constexpr UnicodeViewer(StringViewType str)
Definition UnicodeViewer.hpp:18
static constexpr std::basic_string< NewCharT > ConvertTo(StringViewType str)
Converts from one Unicode Encoding to another.