MT Core (C++)
Core library for replacing C++ standard in project usage
Loading...
Searching...
No Matches
mtcore::RuneIterator< char16_t > Struct Reference

Iterates over runes of utf16 sequences Also handles flipping endianness to native endian. More...

#include <byte_endian.hpp>

Inheritance diagram for mtcore::RuneIterator< char16_t >:
Collaboration diagram for mtcore::RuneIterator< char16_t >:

Public Types

using IterElem = char32_t
 
using IterElem
 

Public Member Functions

Optional< char32_t > next ()
 
Optional< Runenext ()
 Gets the next Rune, if present.
 

Public Attributes

Slice< const char16_t > data
 
size_t strIndex = 0
 
bool reverseBom = false
 
Slice< const char16_t > data
 
size_t strIndex
 

Detailed Description

Iterates over runes of utf16 sequences Also handles flipping endianness to native endian.

Definition at line 939 of file byte_endian.hpp.

Member Typedef Documentation

◆ IterElem [1/2]

using mtcore::RuneIterator< char16_t >::IterElem

Definition at line 873 of file byte_endian.hpp.

◆ IterElem [2/2]

using mtcore::RuneIterator< char16_t >::IterElem = char32_t

Definition at line 940 of file byte_endian.hpp.

Member Function Documentation

◆ next() [1/2]

Optional< Rune > mtcore::RuneIterator< char16_t >::next ( )
inline

Gets the next Rune, if present.

Definition at line 878 of file byte_endian.hpp.

878 {
879 if (strIndex >= data.size()) {
880 return nullopt;
881 }
882 auto curIndex = strIndex;
883 char32_t currentRune = 0;
885
886 if (numBytes < 0) {
887 ++strIndex;
888 }
889 else if (curIndex + numBytes - 1 >= data.size()) {
890 strIndex = data.size();
891 }
892 else {
894 for (size_t index = curIndex; index < strIndex; ++index) {
897 strIndex = curIndex + index - 1;
898 currentRune = 0;
899 break;
900 }
902 currentRune <<= 6;
904 }
905 }
906 return currentRune;
907 }
Slice< const char16_t > data
Iterates over runes of utf8 sequences (char, char_t)

◆ next() [2/2]

Optional< char32_t > mtcore::RuneIterator< char16_t >::next ( )
inline

Definition at line 945 of file byte_endian.hpp.

945 {
946 if (strIndex >= data.size()) {
947 return nullopt;
948 }
949 size_t curIndex = strIndex;
950 char32_t currentRune = 0;
951
952 auto ch = data[curIndex];
953 if (reverseBom) {
955 }
956
957 if (is_high_surrogate(ch)) {
958 if (curIndex + 1 >= data.size()) {
959 strIndex = data.size();
960 return currentRune;
961 }
962 else {
963 auto chNext = data[curIndex + 1];
964 if (reverseBom) {
966 }
967
968 const auto high = (ch - impl::unicode::utf16HighOffset) * 0x400;
971 strIndex = curIndex + 2;
972 }
973 }
974 else {
975 if (!is_low_surrogate(ch)) {
976 currentRune = static_cast<char32_t>(ch);
977 if (reverseBom) {
979 }
980 }
981 ++strIndex;
982 }
983 return currentRune;
984 }
constexpr char16_t flip_endian_ch16(const char16_t ch)
Flips the endianness of a char16.
constexpr bool is_low_surrogate(char16_t ch)
Checks if UTF-16 character is a low surrogate *.
constexpr bool is_high_surrogate(char16_t ch)
Checks if UTF-16 character is a high surrogate *.
Here is the call graph for this function:

Member Data Documentation

◆ data [1/2]

Slice<const char16_t> mtcore::RuneIterator< char16_t >::data

Definition at line 874 of file byte_endian.hpp.

◆ data [2/2]

Slice<const char16_t> mtcore::RuneIterator< char16_t >::data

Definition at line 941 of file byte_endian.hpp.

◆ reverseBom

bool mtcore::RuneIterator< char16_t >::reverseBom = false

Definition at line 943 of file byte_endian.hpp.

◆ strIndex [1/2]

size_t mtcore::RuneIterator< char16_t >::strIndex

Definition at line 875 of file byte_endian.hpp.

◆ strIndex [2/2]

size_t mtcore::RuneIterator< char16_t >::strIndex = 0

Definition at line 942 of file byte_endian.hpp.


The documentation for this struct was generated from the following file: