MT Core (C++)
Core library for replacing C++ standard in project usage
Loading...
Searching...
No Matches
Unicode Encodings

Group related to unicode encodings (including UTF8, UTF16, UTF32 ane endianness) More...

Classes

struct  mtcore::EndianSlice< T, Endian >
 A Slice with Endian-aware data which is just a pointer + length + endian direction Accessing elements through the array operator will do bounds checks and will convert to native endian by default (this can be overridden with access methods) Accessing out of bounds will terminate the program instead of throw Can also get sub slices. More...
 
struct  mtcore::RuneIterator< char16_t >
 Iterates over runes of utf16 sequences Also handles flipping endianness to native endian. More...
 

Typedefs

using mtcore::SliceU16Native = EndianSlice<char16_t, std::endian::native>
 Slice type representing native UTF-16 string *.
 
using mtcore::SliceU16Le = EndianSlice<char16_t, std::endian::little>
 Slice type representing little endian UTF-16 string *.
 
using mtcore::SliceU16Be = EndianSlice<char16_t, std::endian::big>
 Slice type representing big endian UTF-16 string *.
 
using mtcore::SliceConstU16Native = EndianSlice<const char16_t, std::endian::native>
 Slice type representing const native UTF-16 string *.
 
using mtcore::SliceConstU16Le = EndianSlice<const char16_t, std::endian::little>
 Slice type representing const little endian UTF-16 string *.
 
using mtcore::SliceConstU16Be = EndianSlice<const char16_t, std::endian::big>
 Slice type representing const big endian UTF-16 string *.
 
using mtcore::SliceU32Native = EndianSlice<char32_t, std::endian::native>
 Slice type representing native UTF-32 string *.
 
using mtcore::SliceU32Le = EndianSlice<char32_t, std::endian::little>
 Slice type representing little endian UTF-32 string *.
 
using mtcore::SliceU32Be = EndianSlice<char32_t, std::endian::big>
 Slice type representing big endian UTF-32 string.
 
using mtcore::SliceConstU32Native = EndianSlice<const char32_t, std::endian::native>
 Slice type representing const native UTF-32 string.
 
using mtcore::SliceConstU32Le = EndianSlice<const char32_t, std::endian::little>
 Slice type representing const little endian UTF-32 string.
 
using mtcore::SliceConstU32Be = EndianSlice<const char32_t, std::endian::big>
 Slice type representing const big endian UTF-32 string.
 

Functions

constexpr auto mtcore::is_bom (const char32_t ch)
 Checks if a character is a BOM in native ordering.
 
constexpr auto mtcore::is_bom_rev_16_bit (const char16_t ch)
 Checks if a 16-bit character is a BOM in reverse ordering.
 
constexpr auto mtcore::is_bom_rev_32_bit (const char32_t ch)
 Checks if a 32-bit character is a BOM in reverse ordering.
 
Optional< std::endian > mtcore::u16_detect_endian (const char16_t ch)
 Tries to detect the endian encoding based on a possible BOM mark.
 
Optional< std::endian > mtcore::u32_detect_endian (const char32_t ch)
 Tries to detect the endian encoding based on a possible BOM mark.
 
constexpr bool mtcore::is_surrogate (char16_t ch)
 Checks if UTF-16 character is a surrogate.
 
constexpr bool mtcore::is_high_surrogate (char16_t ch)
 Checks if UTF-16 character is a high surrogate *.
 
constexpr bool mtcore::is_low_surrogate (char16_t ch)
 Checks if UTF-16 character is a low surrogate *.
 
SliceU16Native mtcore::endian_from_native_slice (Slice< char16_t > s)
 Gets a UTF-16 endian slice from a slice which is assumed ot be native endian.
 
SliceU32Native mtcore::endian_from_native_slice (Slice< char32_t > s)
 Gets a UTF-32 endian slice from a slice which is assumed ot be native endian.
 
SliceU16Le mtcore::endian_from_le_slice (Slice< char16_t > s)
 Gets a UTF-16 endian slice from a slice which is assumed ot be little endian.
 
SliceU32Le mtcore::endian_from_le_slice (Slice< char32_t > s)
 Gets a UTF-32 endian slice from a slice which is assumed ot be little endian.
 
SliceU16Be mtcore::endian_from_be_slice (Slice< char16_t > s)
 Gets a UTF-16 endian slice from a slice which is assumed ot be big endian.
 
SliceU32Be mtcore::endian_from_be_slice (Slice< char32_t > s)
 Gets a UTF-32 endian slice from a slice which is assumed ot be big endian.
 
std::variant< SliceU16Le, SliceU16Bemtcore::endian_from_slice (Slice< char16_t > s)
 Gets a UTF-16 endian slice from an input slice Will try to use the first character of the slice as a BOM to detect endianness If endian detection fails, will assume native endian Since endian slices are distinct types, this will return a variant (typed union) If there is a BOM, will drop it.
 
std::variant< SliceU32Le, SliceU32Bemtcore::endian_from_slice (Slice< char32_t > s)
 Gets a UTF-32 endian slice from an input slice Will try to use the first character of the slice as a BOM to detect endianness If endian detection fails, will assume native endian Since endian slices are distinct types, this will return a variant (typed union) If there is a BOM, will drop it.
 
Slice< char16_t > mtcore::slice_from_native_endian (SliceU16Native s)
 Gets a normal slice from a native endian slice.
 
Slice< const char16_t > mtcore::slice_from_native_endian (SliceConstU16Native s)
 Gets a normal slice from a native endian slice.
 
Slice< char32_t > mtcore::slice_from_native_endian (SliceU32Native s)
 Gets a normal slice from a native endian slice.
 
Slice< const char32_t > mtcore::slice_from_native_endian (SliceConstU32Native s)
 Gets a normal slice from a native endian slice.
 
Slice< char16_t > mtcore::slice_from_le_endian (SliceU16Native s)
 Gets a normal slice from a little endian slice.
 
Slice< const char16_t > mtcore::slice_from_le_endian (SliceConstU16Native s)
 Gets a normal slice from a little endian slice.
 
Slice< char32_t > mtcore::slice_from_le_endian (SliceU32Native s)
 Gets a normal slice from a little endian slice.
 
Slice< const char32_t > mtcore::slice_from_le_endian (SliceConstU32Native s)
 Gets a normal slice from a little endian slice.
 
Slice< char16_t > mtcore::slice_from_be_endian (SliceU16Native s)
 Gets a normal slice from a big endian slice.
 
Slice< const char16_t > mtcore::slice_from_be_endian (SliceConstU16Native s)
 Gets a normal slice from a big endian slice.
 
Slice< char32_t > mtcore::slice_from_be_endian (SliceU32Native s)
 Gets a normal slice from a big endian slice.
 
Slice< const char32_t > mtcore::slice_from_be_endian (SliceConstU32Native s)
 Gets a normal slice from a big endian slice.
 
CharSeq mtcore::rune_to_str (Rune rune)
 Converts a UTF-32 Rune to a sequence of char.
 
U8Seq mtcore::rune_to_utf8 (Rune rune)
 Converts a UTF-32 Rune to a utf-8 sequence.
 
U16Seq mtcore::rune_to_utf16 (Rune rune)
 Converts a UTF-32 Rune to a utf-16 sequence.
 
RuneIterator< char > mtcore::str_rune_iterator (const Slice< const char > &s)
 Rune iterator for a slice of characters.
 
RuneIterator< char8_t > mtcore::utf8_rune_iterator (const Slice< const char8_t > &s)
 Rune iterator for a UTF8 sequence.
 
RuneIterator< char16_t > mtcore::utf16_rune_iterator (const Slice< const char16_t > &s)
 Rune iterator for a UTF16 sequence.
 
RuneIterator< char16_t > mtcore::utf16_rune_iterator (const SliceConstU16Le &s)
 Rune iterator for a little endian UTF16 sequence.
 
RuneIterator< char16_t > mtcore::utf16_rune_iterator (const SliceConstU16Be &s)
 Rune iterator for a big endian UTF16 sequence.
 
RuneIterator< char16_t > mtcore::utf16_rune_iterator (const SliceU16Le &s)
 Rune iterator for a little endian UTF16 sequence.
 
RuneIterator< char16_t > mtcore::utf16_rune_iterator (const SliceU16Be &s)
 Rune iterator for a big endian UTF16 sequence.
 
RuneIterator< char32_t > mtcore::utf32_rune_iterator (const Slice< const char32_t > &s)
 Rune iterator for a UTF32 sequence.
 
RuneIterator< char32_t > mtcore::utf32_rune_iterator (const SliceConstU32Le &s)
 Rune iterator for a little endian UTF32 sequence.
 
RuneIterator< char32_t > mtcore::utf32_rune_iterator (const SliceConstU32Be &s)
 Rune iterator for a big endian UTF32 sequence.
 
RuneIterator< char32_t > mtcore::utf32_rune_iterator (const SliceU32Le &s)
 Rune iterator for a little endian UTF32 sequence.
 
RuneIterator< char32_t > mtcore::utf32_rune_iterator (const SliceU32Be &s)
 Rune iterator for a big endian UTF32 sequence.
 
template<WriterImpl WI>
auto mtcore::utf32_to_utf16 (io::Writer< WI > &writer, const SliceConstU32Be &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-32 string to UTF-16 string Can optionally write a BOM to the prefix.
 
template<WriterImpl WI>
auto mtcore::utf32_to_utf16 (io::Writer< WI > &writer, const SliceConstU32Le &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-32 string to UTF-16 string Can optionally write a BOM to the prefix.
 
template<WriterImpl WI>
auto mtcore::utf32_to_utf16 (io::Writer< WI > &writer, const Slice< const char32_t > &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-32 string to UTF-16 string Can optionally write a BOM to the prefix.
 
template<WriterImpl WI>
auto mtcore::utf32_to_utf8 (io::Writer< WI > &writer, const SliceConstU32Be &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-32 string to UTF-8 string.
 
template<WriterImpl WI>
auto mtcore::utf32_to_utf8 (io::Writer< WI > &writer, const SliceConstU32Le &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-32 string to UTF-8 string.
 
template<WriterImpl WI>
auto mtcore::utf32_to_utf8 (io::Writer< WI > &writer, const Slice< const char32_t > &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-32 string to UTF-8 string.
 
template<WriterImpl WI>
auto mtcore::utf32_to_str (io::Writer< WI > &writer, const SliceConstU32Be &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-32 string to character sequence (UTF-8 encoded chars)
 
template<WriterImpl WI>
auto mtcore::utf32_to_str (io::Writer< WI > &writer, const SliceConstU32Le &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-32 string to character sequence (UTF-8 encoded chars)
 
template<WriterImpl WI>
auto mtcore::utf32_to_str (io::Writer< WI > &writer, const Slice< const char32_t > &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-32 string to character sequence (UTF-8 encoded chars)
 
template<WriterImpl WI>
auto mtcore::utf8_to_utf32 (io::Writer< WI > &writer, const Slice< const char8_t > &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-8 string to UTF-32.
 
template<WriterImpl WI>
auto mtcore::str_to_utf32 (io::Writer< WI > &writer, const Slice< const char > &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-8 string to UTF-32.
 
template<WriterImpl WI>
auto mtcore::utf16_to_utf8 (io::Writer< WI > &writer, const SliceConstU16Be &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-16 string to UTF-8.
 
template<WriterImpl WI>
auto mtcore::utf16_to_utf32 (io::Writer< WI > &writer, const SliceConstU16Le &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-16 string to UTF-32.
 
template<WriterImpl WI>
auto mtcore::utf16_to_utf32 (io::Writer< WI > &writer, const SliceConstU16Be &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-16 string to UTF-32.
 
template<WriterImpl WI>
auto mtcore::utf16_to_utf32 (io::Writer< WI > &writer, const Slice< const char16_t > &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-16 string to UTF-32.
 
template<WriterImpl WI>
auto mtcore::utf16_to_utf8 (io::Writer< WI > &writer, const SliceConstU16Le &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-16 string to UTF-8.
 
template<WriterImpl WI>
auto mtcore::utf16_to_str (io::Writer< WI > &writer, const SliceConstU16Be &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-16 string to UTF-8.
 
template<WriterImpl WI>
auto mtcore::utf16_to_str (io::Writer< WI > &writer, const SliceConstU16Le &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-16 string to UTF-8.
 
template<WriterImpl WI>
auto mtcore::utf16_to_utf8 (io::Writer< WI > &writer, const Slice< const char16_t > &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-16 string to UTF-8.
 
template<WriterImpl WI>
auto mtcore::utf16_to_str (io::Writer< WI > &writer, const Slice< const char16_t > &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-16 string to UTF-8.
 
template<WriterImpl WI>
auto mtcore::utf8_to_utf16 (io::Writer< WI > &writer, const Slice< const char8_t > &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-8 string to UTF-16.
 
template<WriterImpl WI>
auto mtcore::str_to_utf16 (io::Writer< WI > &writer, const Slice< const char > &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-8 string to UTF-16.
 
template<WriterImpl WI>
auto mtcore::utf8_to_str (io::Writer< WI > &writer, const Slice< const char8_t > &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a UTF-8 string to character sequence.
 
template<WriterImpl WI>
auto mtcore::str_to_utf8 (io::Writer< WI > &writer, const Slice< const char > &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Will convert a character sequence to UTF-8 string.
 
template<WriterImpl WI>
auto mtcore::utf16_to_utf16le (io::Writer< WI > &writer, const SliceConstU16Native &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts native UTF-16 to UTF-16 Little Endian.
 
template<WriterImpl WI>
auto mtcore::utf16_to_utf16le (io::Writer< WI > &writer, const Slice< const char16_t > &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts native UTF-16 to UTF-16 Little Endian.
 
template<WriterImpl WI>
auto mtcore::utf16_to_utf16be (io::Writer< WI > &writer, const SliceConstU16Native &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts native UTF-16 to UTF-16 Big Endian.
 
template<WriterImpl WI>
auto mtcore::utf16_to_utf16be (io::Writer< WI > &writer, const Slice< const char16_t > &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts native UTF-16 to UTF-16 Big Endian.
 
template<WriterImpl WI>
auto mtcore::utf16le_to_utf16be (io::Writer< WI > &writer, const SliceConstU16Le &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts UTF-16 Little Endian to UTF-16 Big Endian.
 
template<WriterImpl WI>
auto mtcore::utf16be_to_utf16le (io::Writer< WI > &writer, const SliceConstU16Be &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts UTF-16 Big Endian to UTF-16 Little Endian.
 
template<WriterImpl WI>
auto mtcore::utf16le_to_utf16 (io::Writer< WI > &writer, const SliceConstU16Le &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts UTF-16 Little Endian to Native UTF-16.
 
template<WriterImpl WI>
auto mtcore::utf16be_to_utf16 (io::Writer< WI > &writer, const SliceConstU16Be &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts UTF-16 Big Endian to Native UTF-16.
 
template<WriterImpl WI>
auto mtcore::utf32_to_utf32le (io::Writer< WI > &writer, const SliceConstU32Native &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts UTF-32 Native Endian to UTF-32 Little Endian.
 
template<WriterImpl WI>
auto mtcore::utf32_to_utf32le (io::Writer< WI > &writer, const Slice< const char32_t > &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts UTF-32 Native Endian to UTF-32 Little Endian.
 
template<WriterImpl WI>
auto mtcore::utf32_to_utf32be (io::Writer< WI > &writer, const SliceConstU32Native &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts UTF-32 Native Endian to UTF-32 Big Endian.
 
template<WriterImpl WI>
auto mtcore::utf32_to_utf32be (io::Writer< WI > &writer, const Slice< const char32_t > &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts UTF-32 Native Endian to UTF-32 Big Endian.
 
template<WriterImpl WI>
auto mtcore::utf32le_to_utf32be (io::Writer< WI > &writer, const SliceConstU32Le &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts UTF-32 Little Endian to UTF-32 Big Endian.
 
template<WriterImpl WI>
auto mtcore::utf32be_to_utf32le (io::Writer< WI > &writer, const SliceConstU32Be &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts UTF-32 Big Endian to UTF-32 Little Endian.
 
template<WriterImpl WI>
auto mtcore::utf32le_to_utf32 (io::Writer< WI > &writer, const SliceConstU32Le &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts UTF-32 Little Endian to UTF-32 Native Endian.
 
template<WriterImpl WI>
auto mtcore::utf32be_to_utf32 (io::Writer< WI > &writer, const SliceConstU32Be &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
 Converts UTF-32 Big Endian to UTF-32 Native Endian.
 

Variables

constexpr char32_t mtcore::bom = 0xFEFF
 Native representation of Byte Order Mark (BOM)
 
template<std::endian E = std::endian::native>
constexpr auto mtcore::oppositeEndian = E == std::endian::big ? std::endian::little : std::endian::big
 Returns the opposite endianness of a given endian (default is opposite of the native endian)
 

Detailed Description

Group related to unicode encodings (including UTF8, UTF16, UTF32 ane endianness)

Typedef Documentation

◆ SliceConstU16Be

using mtcore::SliceConstU16Be = EndianSlice<const char16_t, std::endian::big>

Slice type representing const big endian UTF-16 string *.

Definition at line 523 of file byte_endian.hpp.

◆ SliceConstU16Le

using mtcore::SliceConstU16Le = EndianSlice<const char16_t, std::endian::little>

Slice type representing const little endian UTF-16 string *.

Definition at line 519 of file byte_endian.hpp.

◆ SliceConstU16Native

using mtcore::SliceConstU16Native = EndianSlice<const char16_t, std::endian::native>

Slice type representing const native UTF-16 string *.

Definition at line 515 of file byte_endian.hpp.

◆ SliceConstU32Be

using mtcore::SliceConstU32Be = EndianSlice<const char32_t, std::endian::big>

Slice type representing const big endian UTF-32 string.

Definition at line 552 of file byte_endian.hpp.

◆ SliceConstU32Le

using mtcore::SliceConstU32Le = EndianSlice<const char32_t, std::endian::little>

Slice type representing const little endian UTF-32 string.

Definition at line 547 of file byte_endian.hpp.

◆ SliceConstU32Native

using mtcore::SliceConstU32Native = EndianSlice<const char32_t, std::endian::native>

Slice type representing const native UTF-32 string.

Definition at line 542 of file byte_endian.hpp.

◆ SliceU16Be

using mtcore::SliceU16Be = EndianSlice<char16_t, std::endian::big>

Slice type representing big endian UTF-16 string *.

Definition at line 511 of file byte_endian.hpp.

◆ SliceU16Le

using mtcore::SliceU16Le = EndianSlice<char16_t, std::endian::little>

Slice type representing little endian UTF-16 string *.

Definition at line 507 of file byte_endian.hpp.

◆ SliceU16Native

using mtcore::SliceU16Native = EndianSlice<char16_t, std::endian::native>

Slice type representing native UTF-16 string *.

Definition at line 503 of file byte_endian.hpp.

◆ SliceU32Be

using mtcore::SliceU32Be = EndianSlice<char32_t, std::endian::big>

Slice type representing big endian UTF-32 string.

Definition at line 537 of file byte_endian.hpp.

◆ SliceU32Le

using mtcore::SliceU32Le = EndianSlice<char32_t, std::endian::little>

Slice type representing little endian UTF-32 string *.

Definition at line 532 of file byte_endian.hpp.

◆ SliceU32Native

using mtcore::SliceU32Native = EndianSlice<char32_t, std::endian::native>

Slice type representing native UTF-32 string *.

Definition at line 528 of file byte_endian.hpp.

Function Documentation

◆ endian_from_be_slice() [1/2]

SliceConstU16Be mtcore::endian_from_be_slice ( Slice< char16_t > s)
inline

Gets a UTF-16 endian slice from a slice which is assumed ot be big endian.

Gets a const UTF-16 endian slice from a slice which is assumed ot be big endian ingroup unicode_enc.

Definition at line 580 of file byte_endian.hpp.

580{ return {.head = s.head, .len = s.len}; }

◆ endian_from_be_slice() [2/2]

SliceConstU32Be mtcore::endian_from_be_slice ( Slice< char32_t > s)
inline

Gets a UTF-32 endian slice from a slice which is assumed ot be big endian.

Gets a const UTF-32 endian slice from a slice which is assumed ot be big endian ingroup unicode_enc.

Definition at line 585 of file byte_endian.hpp.

585{ return {.head = s.head, .len = s.len}; }

◆ endian_from_le_slice() [1/2]

SliceConstU16Le mtcore::endian_from_le_slice ( Slice< char16_t > s)
inline

Gets a UTF-16 endian slice from a slice which is assumed ot be little endian.

Gets a const UTF-16 endian slice from a slice which is assumed ot be little endian.

Definition at line 569 of file byte_endian.hpp.

569{ return {.head = s.head, .len = s.len}; }

◆ endian_from_le_slice() [2/2]

SliceConstU32Le mtcore::endian_from_le_slice ( Slice< char32_t > s)
inline

Gets a UTF-32 endian slice from a slice which is assumed ot be little endian.

Gets a const UTF-32 endian slice from a slice which is assumed ot be little endian.

Definition at line 574 of file byte_endian.hpp.

574{ return {.head = s.head, .len = s.len}; }

◆ endian_from_native_slice() [1/2]

SliceConstU16Native mtcore::endian_from_native_slice ( Slice< char16_t > s)
inline

Gets a UTF-16 endian slice from a slice which is assumed ot be native endian.

Gets a const UTF-16 endian slice from a slice which is assumed ot be native endian.

Definition at line 558 of file byte_endian.hpp.

558{ return {.head = s.head, .len = s.len}; }
Here is the caller graph for this function:

◆ endian_from_native_slice() [2/2]

SliceConstU32Native mtcore::endian_from_native_slice ( Slice< char32_t > s)
inline

Gets a UTF-32 endian slice from a slice which is assumed ot be native endian.

Definition at line 563 of file byte_endian.hpp.

563{ return {.head = s.head, .len = s.len}; }

◆ endian_from_slice() [1/2]

std::variant< SliceConstU16Le, SliceConstU16Be > mtcore::endian_from_slice ( Slice< char16_t > s)
inline

Gets a UTF-16 endian slice from an input slice Will try to use the first character of the slice as a BOM to detect endianness If endian detection fails, will assume native endian Since endian slices are distinct types, this will return a variant (typed union) If there is a BOM, will drop it.

Gets a const UTF-16 endian slice from an input slice Will try to use the first character of the slice as a BOM to detect endianness If endian detection fails, will assume native endian Since endian slices are distinct types, this will return a variant (typed union) If there is a BOM, will drop it.

Definition at line 632 of file byte_endian.hpp.

632 {
633 if (s.size() > 0) {
634 if (auto detect = u16_detect_endian(s[0]); detect.has_value()) {
635 auto subbed = s.sub(1);
636 if (detect.value() == std::endian::little) {
637 return SliceU16Le{.head = subbed.head, .len = subbed.len};
638 }
639 else {
640 return SliceU16Be{.head = subbed.head, .len = subbed.len};
641 }
642 }
643 }
644 return SliceU16Native{.head = s.head, .len = s.len};
645 }
Optional< std::endian > u16_detect_endian(const char16_t ch)
Tries to detect the endian encoding based on a possible BOM mark.
EndianSlice< char16_t, std::endian::native > SliceU16Native
Slice type representing native UTF-16 string *.
EndianSlice< char16_t, std::endian::little > SliceU16Le
Slice type representing little endian UTF-16 string *.
EndianSlice< char16_t, std::endian::big > SliceU16Be
Slice type representing big endian UTF-16 string *.
constexpr Slice sub(size_t start) const noexcept
Gets a sub Slice from start.
constexpr size_t size() const noexcept
Gets the size of a Slice.
Here is the call graph for this function:

◆ endian_from_slice() [2/2]

std::variant< SliceConstU32Le, SliceConstU32Be > mtcore::endian_from_slice ( Slice< char32_t > s)
inline

Gets a UTF-32 endian slice from an input slice Will try to use the first character of the slice as a BOM to detect endianness If endian detection fails, will assume native endian Since endian slices are distinct types, this will return a variant (typed union) If there is a BOM, will drop it.

Gets a const UTF-32 endian slice from an input slice Will try to use the first character of the slice as a BOM to detect endianness If endian detection fails, will assume native endian Since endian slices are distinct types, this will return a variant (typed union) If there is a BOM, will drop it.

Definition at line 655 of file byte_endian.hpp.

655 {
656 if (s.size() > 0) {
657 if (auto detect = u16_detect_endian(s[0]); detect.has_value()) {
658 auto subbed = s.sub(1);
659 if (detect.value() == std::endian::little) {
660 return SliceU32Le{.head = subbed.head, .len = subbed.len};
661 }
662 else {
663 return SliceU32Be{.head = subbed.head, .len = subbed.len};
664 }
665 }
666 }
667 return SliceU32Native{.head = s.head, .len = s.len};
668 }
EndianSlice< char32_t, std::endian::little > SliceU32Le
Slice type representing little endian UTF-32 string *.
EndianSlice< char32_t, std::endian::native > SliceU32Native
Slice type representing native UTF-32 string *.
EndianSlice< char32_t, std::endian::big > SliceU32Be
Slice type representing big endian UTF-32 string.
Here is the call graph for this function:

◆ is_bom()

auto mtcore::is_bom ( const char32_t ch)
constexpr

Checks if a character is a BOM in native ordering.

Definition at line 45 of file byte_endian.hpp.

45{ return ch == bom; }
constexpr char32_t bom
Native representation of Byte Order Mark (BOM)
Here is the caller graph for this function:

◆ is_bom_rev_16_bit()

auto mtcore::is_bom_rev_16_bit ( const char16_t ch)
constexpr

Checks if a 16-bit character is a BOM in reverse ordering.

Definition at line 50 of file byte_endian.hpp.

50{ return ch == 0xFFFE; }
Here is the caller graph for this function:

◆ is_bom_rev_32_bit()

auto mtcore::is_bom_rev_32_bit ( const char32_t ch)
constexpr

Checks if a 32-bit character is a BOM in reverse ordering.

Definition at line 55 of file byte_endian.hpp.

55{ return ch == 0xFFFE0000; }
Here is the caller graph for this function:

◆ is_high_surrogate()

bool mtcore::is_high_surrogate ( char16_t ch)
constexpr

Checks if UTF-16 character is a high surrogate *.

Definition at line 147 of file byte_endian.hpp.

147{ return ch >= 0xD800 && ch <= 0xDBFF; }
Here is the caller graph for this function:

◆ is_low_surrogate()

bool mtcore::is_low_surrogate ( char16_t ch)
constexpr

Checks if UTF-16 character is a low surrogate *.

Definition at line 151 of file byte_endian.hpp.

151{ return ch >= 0xDC00 && ch <= 0xDFFF; }
Here is the caller graph for this function:

◆ is_surrogate()

bool mtcore::is_surrogate ( char16_t ch)
constexpr

Checks if UTF-16 character is a surrogate.

Definition at line 143 of file byte_endian.hpp.

143{ return ch >= 0xD800 && ch <= 0xDFFF; }

◆ rune_to_str()

CharSeq mtcore::rune_to_str ( Rune rune)

Converts a UTF-32 Rune to a sequence of char.

Here is the caller graph for this function:

◆ rune_to_utf16()

U16Seq mtcore::rune_to_utf16 ( Rune rune)

Converts a UTF-32 Rune to a utf-16 sequence.

Here is the caller graph for this function:

◆ rune_to_utf8()

U8Seq mtcore::rune_to_utf8 ( Rune rune)

Converts a UTF-32 Rune to a utf-8 sequence.

Here is the caller graph for this function:

◆ slice_from_be_endian() [1/4]

Slice< const char16_t > mtcore::slice_from_be_endian ( SliceConstU16Native s)
inline

Gets a normal slice from a big endian slice.

Does NOT flip endianness of data or add BOM

Definition at line 771 of file byte_endian.hpp.

771{ return {.head = s.head, .len = s.len}; }

◆ slice_from_be_endian() [2/4]

Slice< const char32_t > mtcore::slice_from_be_endian ( SliceConstU32Native s)
inline

Gets a normal slice from a big endian slice.

Does NOT flip endianness of data or add BOM

Definition at line 781 of file byte_endian.hpp.

781{ return {.head = s.head, .len = s.len}; }

◆ slice_from_be_endian() [3/4]

Slice< char16_t > mtcore::slice_from_be_endian ( SliceU16Native s)
inline

Gets a normal slice from a big endian slice.

Does NOT flip endianness of data or add BOM

Definition at line 766 of file byte_endian.hpp.

766{ return {.head = s.head, .len = s.len}; }

◆ slice_from_be_endian() [4/4]

Slice< char32_t > mtcore::slice_from_be_endian ( SliceU32Native s)
inline

Gets a normal slice from a big endian slice.

Does NOT flip endianness of data or add BOM

Definition at line 776 of file byte_endian.hpp.

776{ return {.head = s.head, .len = s.len}; }

◆ slice_from_le_endian() [1/4]

Slice< const char16_t > mtcore::slice_from_le_endian ( SliceConstU16Native s)
inline

Gets a normal slice from a little endian slice.

Does NOT flip endianness of data or add BOM

Definition at line 750 of file byte_endian.hpp.

750{ return {.head = s.head, .len = s.len}; }

◆ slice_from_le_endian() [2/4]

Slice< const char32_t > mtcore::slice_from_le_endian ( SliceConstU32Native s)
inline

Gets a normal slice from a little endian slice.

Does NOT flip endianness of data or add BOM

Definition at line 760 of file byte_endian.hpp.

760{ return {.head = s.head, .len = s.len}; }

◆ slice_from_le_endian() [3/4]

Slice< char16_t > mtcore::slice_from_le_endian ( SliceU16Native s)
inline

Gets a normal slice from a little endian slice.

Does NOT flip endianness of data or add BOM

Definition at line 745 of file byte_endian.hpp.

745{ return {.head = s.head, .len = s.len}; }

◆ slice_from_le_endian() [4/4]

Slice< char32_t > mtcore::slice_from_le_endian ( SliceU32Native s)
inline

Gets a normal slice from a little endian slice.

Does NOT flip endianness of data or add BOM

Definition at line 755 of file byte_endian.hpp.

755{ return {.head = s.head, .len = s.len}; }

◆ slice_from_native_endian() [1/4]

Slice< const char16_t > mtcore::slice_from_native_endian ( SliceConstU16Native s)
inline

Gets a normal slice from a native endian slice.

Does NOT flip endianness of data or add BOM

Definition at line 725 of file byte_endian.hpp.

725 {
726 return {.head = s.head, .len = s.len};
727 }

◆ slice_from_native_endian() [2/4]

Slice< const char32_t > mtcore::slice_from_native_endian ( SliceConstU32Native s)
inline

Gets a normal slice from a native endian slice.

Does NOT flip endianness of data or add BOM

Definition at line 737 of file byte_endian.hpp.

737 {
738 return {.head = s.head, .len = s.len};
739 }

◆ slice_from_native_endian() [3/4]

Slice< char16_t > mtcore::slice_from_native_endian ( SliceU16Native s)
inline

Gets a normal slice from a native endian slice.

Does NOT flip endianness of data or add BOM

Definition at line 720 of file byte_endian.hpp.

720{ return {.head = s.head, .len = s.len}; }

◆ slice_from_native_endian() [4/4]

Slice< char32_t > mtcore::slice_from_native_endian ( SliceU32Native s)
inline

Gets a normal slice from a native endian slice.

Does NOT flip endianness of data or add BOM

Definition at line 732 of file byte_endian.hpp.

732{ return {.head = s.head, .len = s.len}; }

◆ str_rune_iterator()

RuneIterator< char > mtcore::str_rune_iterator ( const Slice< const char > & s)
inline

Rune iterator for a slice of characters.

Definition at line 991 of file byte_endian.hpp.

991{ return {.data = s, .strIndex = 0}; }
Here is the caller graph for this function:

◆ str_to_utf16()

template<WriterImpl WI>
auto mtcore::str_to_utf16 ( io::Writer< WI > & writer,
const Slice< const char > & str,
bool writeBom = false ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Will convert a UTF-8 string to UTF-16.

Template Parameters
WIWriter type
Parameters
writerWriter to write output to (should take char as input)
strUTF-8 string to write
writeBomIf it should write a BOM
Returns
Result with number of UTF32 chars written, or error otherwise

Definition at line 1660 of file byte_endian.hpp.

1661 {
1662 auto runeIter = str_rune_iterator(str);
1663 char32_t rune;
1664 size_t written = 0;
1665
1666 if (writeBom) {
1667 if (auto res = writer.write(bom); res.is_error()) {
1668 return res.error();
1669 }
1670 ++written;
1671 }
1672
1673 while (runeIter.next().copy_if_present(rune)) {
1674 auto seq = rune_to_utf16(rune);
1675 char16_t curCh;
1676 auto charIter = seq.iter();
1677 while (charIter.next().copy_if_present(curCh)) {
1678 if (auto writeRes = writer.write(curCh); writeRes.is_error()) {
1679 return writeRes.error();
1680 }
1681 ++written;
1682 }
1683 }
1684 return success(written);
1685 }
io::Writer< csv::impl::Writer< WI > > writer(io::Writer< WI > &underlying, Options opts={})
Creates a CSV writer which will encode the data before writing it out.
Success< void > success()
Creates a successful void Result object.
Definition result.hpp:398
RuneIterator< char > str_rune_iterator(const Slice< const char > &s)
Rune iterator for a slice of characters.
U16Seq rune_to_utf16(Rune rune)
Converts a UTF-32 Rune to a utf-16 sequence.
Here is the call graph for this function:

◆ str_to_utf32()

template<WriterImpl WI>
auto mtcore::str_to_utf32 ( io::Writer< WI > & writer,
const Slice< const char > & str,
bool writeBom = false ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Will convert a UTF-8 string to UTF-32.

Template Parameters
WIWriter type
Parameters
writerWriter to write output to (should take char as input)
strUTF-8 string to write
writeBomIf it should write a BOM
Returns
Result with number of UTF32 chars written, or error otherwise

Definition at line 1371 of file byte_endian.hpp.

1372 {
1373 auto runeIter = str_rune_iterator(str);
1374 char32_t rune;
1375 size_t written = 0;
1376
1377 if (writeBom) {
1378 if (auto res = writer.write(bom); res.is_error()) {
1379 return res.error();
1380 }
1381 ++written;
1382 }
1383
1384 while (runeIter.next().copy_if_present(rune)) {
1385 if (auto writeRes = writer.write(rune); writeRes.is_error()) {
1386 return writeRes.error();
1387 }
1388 ++written;
1389 }
1390 return success(written);
1391 }
Here is the call graph for this function:

◆ str_to_utf8()

template<WriterImpl WI>
auto mtcore::str_to_utf8 ( io::Writer< WI > & writer,
const Slice< const char > & str ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Will convert a character sequence to UTF-8 string.

Template Parameters
WIWriter type
Parameters
writerWriter to write output to (should take char as input)
strUTF-8 string to write
Returns
Result with number of UTF32 chars written, or error otherwise

Definition at line 1724 of file byte_endian.hpp.

1725 {
1726 auto runeIter = str_rune_iterator(str);
1727 char32_t rune;
1728 size_t written = 0;
1729 while (runeIter.next().copy_if_present(rune)) {
1730 auto seq = rune_to_utf8(rune);
1731 char8_t curCh;
1732 auto charIter = seq.iter();
1733 while (charIter.next().copy_if_present(curCh)) {
1734 if (auto writeRes = writer.write(curCh); writeRes.is_error()) {
1735 return writeRes.error();
1736 }
1737 ++written;
1738 }
1739 }
1740 return success(written);
1741 }
U8Seq rune_to_utf8(Rune rune)
Converts a UTF-32 Rune to a utf-8 sequence.
Here is the call graph for this function:

◆ u16_detect_endian()

Optional< std::endian > mtcore::u16_detect_endian ( const char16_t ch)
inline

Tries to detect the endian encoding based on a possible BOM mark.

Parameters
chCharacter to detect ordering from (should be a BOM or reverse BOM)
Returns
detected endian or nullopt if couldn't detect

Definition at line 66 of file byte_endian.hpp.

66 {
67 if (is_bom(ch)) {
68 return endian::machine;
69 }
70 else if (is_bom_rev_16_bit(ch)) {
71 return endian::opposite;
72 }
73 else {
74 return nullopt;
75 }
76 }
constexpr auto nullopt
Placeholder value for an empty Optional.
Definition optional.hpp:409
constexpr auto opposite
endian that is opposite of machine (opposite of std::endian::native)
constexpr auto machine
endian of machine (alias for std::endian::native)
constexpr auto is_bom(const char32_t ch)
Checks if a character is a BOM in native ordering.
constexpr auto is_bom_rev_16_bit(const char16_t ch)
Checks if a 16-bit character is a BOM in reverse ordering.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ u32_detect_endian()

Optional< std::endian > mtcore::u32_detect_endian ( const char32_t ch)
inline

Tries to detect the endian encoding based on a possible BOM mark.

Parameters
chCharacter to detect ordering from (should be a BOM or reverse BOM)
Returns
detected endian or nullopt if couldn't detect

Definition at line 84 of file byte_endian.hpp.

84 {
85 if (is_bom(ch)) {
86 return endian::machine;
87 }
88 else if (is_bom_rev_32_bit(ch)) {
89 return endian::opposite;
90 }
91 else {
92 return nullopt;
93 }
94 }
constexpr auto is_bom_rev_32_bit(const char32_t ch)
Checks if a 32-bit character is a BOM in reverse ordering.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ utf16_rune_iterator() [1/5]

RuneIterator< char16_t > mtcore::utf16_rune_iterator ( const Slice< const char16_t > & s)
inline

Rune iterator for a UTF16 sequence.

Will try to auto detect endianness from BOM. Will drop BOM if present

Definition at line 1003 of file byte_endian.hpp.

1003 {
1004 if (s.size()) {
1005 if (const auto encoding = u16_detect_endian(s[0]); encoding.has_value()) {
1006 return {.data = s.sub(1), .strIndex = 0, .reverseBom = encoding == endian::opposite};
1007 }
1008 }
1009 return {.data = s, .strIndex = 0};
1010 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ utf16_rune_iterator() [2/5]

RuneIterator< char16_t > mtcore::utf16_rune_iterator ( const SliceConstU16Be & s)
inline

Rune iterator for a big endian UTF16 sequence.

Definition at line 1025 of file byte_endian.hpp.

1025 {
1026 return {
1027 .data = {.head = s.head, .len = s.len}, .strIndex = 0, .reverseBom = std::endian::native != std::endian::big};
1028 }

◆ utf16_rune_iterator() [3/5]

RuneIterator< char16_t > mtcore::utf16_rune_iterator ( const SliceConstU16Le & s)
inline

Rune iterator for a little endian UTF16 sequence.

Definition at line 1016 of file byte_endian.hpp.

1016 {
1017 return {
1018 .data = {.head = s.head, .len = s.len}, .strIndex = 0, .reverseBom = std::endian::native != std::endian::little};
1019 }

◆ utf16_rune_iterator() [4/5]

RuneIterator< char16_t > mtcore::utf16_rune_iterator ( const SliceU16Be & s)
inline

Rune iterator for a big endian UTF16 sequence.

Definition at line 1043 of file byte_endian.hpp.

1043 {
1044 return {
1045 .data = {.head = s.head, .len = s.len}, .strIndex = 0, .reverseBom = std::endian::native != std::endian::big};
1046 }

◆ utf16_rune_iterator() [5/5]

RuneIterator< char16_t > mtcore::utf16_rune_iterator ( const SliceU16Le & s)
inline

Rune iterator for a little endian UTF16 sequence.

Definition at line 1034 of file byte_endian.hpp.

1034 {
1035 return {
1036 .data = {.head = s.head, .len = s.len}, .strIndex = 0, .reverseBom = std::endian::native != std::endian::little};
1037 }

◆ utf16_to_str() [1/3]

template<WriterImpl WI>
auto mtcore::utf16_to_str ( io::Writer< WI > & writer,
const Slice< const char16_t > & str ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Will convert a UTF-16 string to UTF-8.

Template Parameters
WIWriter type
Parameters
writerWriter to write output to (should take char as input)
strUTF-16 string to write (native endian)
Returns
Result with number of UTF32 chars written, or error otherwise

Definition at line 1608 of file byte_endian.hpp.

1609 {
1610 return utf16_to_str(writer, endian_from_native_slice(str));
1611 }
auto utf16_to_str(io::Writer< WI > &writer, const SliceConstU16Be &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
Will convert a UTF-16 string to UTF-8.
SliceU16Native endian_from_native_slice(Slice< char16_t > s)
Gets a UTF-16 endian slice from a slice which is assumed ot be native endian.
Here is the call graph for this function:

◆ utf16_to_str() [2/3]

template<WriterImpl WI>
auto mtcore::utf16_to_str ( io::Writer< WI > & writer,
const SliceConstU16Be & str ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Will convert a UTF-16 string to UTF-8.

Template Parameters
WIWriter type
Parameters
writerWriter to write output to (should take char as input)
strUTF-16 string to write (big endian)
Returns
Result with number of UTF32 chars written, or error otherwise

Definition at line 1538 of file byte_endian.hpp.

1539 {
1540 auto runeIter = utf16_rune_iterator(str);
1541 char32_t rune;
1542 size_t written = 0;
1543 while (runeIter.next().copy_if_present(rune)) {
1544 auto seq = rune_to_str(rune);
1545 char curCh;
1546 auto charIter = seq.iter();
1547 while (charIter.next().copy_if_present(curCh)) {
1548 if (auto writeRes = writer.write(curCh); writeRes.is_error()) {
1549 return writeRes.error();
1550 }
1551 ++written;
1552 }
1553 }
1554 return success(written);
1555 }
RuneIterator< char16_t > utf16_rune_iterator(const Slice< const char16_t > &s)
Rune iterator for a UTF16 sequence.
CharSeq rune_to_str(Rune rune)
Converts a UTF-32 Rune to a sequence of char.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ utf16_to_str() [3/3]

template<WriterImpl WI>
auto mtcore::utf16_to_str ( io::Writer< WI > & writer,
const SliceConstU16Le & str ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Will convert a UTF-16 string to UTF-8.

Template Parameters
WIWriter type
Parameters
writerWriter to write output to (should take char as input)
strUTF-16 string to write (little endian)
Returns
Result with number of UTF32 chars written, or error otherwise

Definition at line 1566 of file byte_endian.hpp.

1567 {
1568 auto runeIter = utf16_rune_iterator(str);
1569 char32_t rune;
1570 size_t written = 0;
1571 while (runeIter.next().copy_if_present(rune)) {
1572 auto seq = rune_to_str(rune);
1573 char curCh;
1574 auto charIter = seq.iter();
1575 while (charIter.next().copy_if_present(curCh)) {
1576 if (auto writeRes = writer.write(curCh); writeRes.is_error()) {
1577 return writeRes.error();
1578 }
1579 ++written;
1580 }
1581 }
1582 return success(written);
1583 }
Here is the call graph for this function:

◆ utf16_to_utf16be() [1/2]

template<WriterImpl WI>
auto mtcore::utf16_to_utf16be ( io::Writer< WI > & writer,
const Slice< const char16_t > & str,
bool writeBom = false ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Converts native UTF-16 to UTF-16 Big Endian.

Template Parameters
WIWriter Type
Parameters
writerWriter
strUTF-16 (native) to write
writeBomIf it should write BOM
Returns
Number of UTF16 chars written, or error otherwise

Definition at line 1848 of file byte_endian.hpp.

1849 {
1850 return utf16_to_utf16be(writer, endian_from_native_slice(str), writeBom);
1851 }
auto utf16_to_utf16be(io::Writer< WI > &writer, const SliceConstU16Native &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
Converts native UTF-16 to UTF-16 Big Endian.
Here is the call graph for this function:

◆ utf16_to_utf16be() [2/2]

template<WriterImpl WI>
auto mtcore::utf16_to_utf16be ( io::Writer< WI > & writer,
const SliceConstU16Native & str,
bool writeBom = false ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Converts native UTF-16 to UTF-16 Big Endian.

Template Parameters
WIWriter Type
Parameters
writerWriter
strUTF-16 (native) to write
writeBomIf it should write BOM
Returns
Number of UTF16 chars written, or error otherwise

Definition at line 1808 of file byte_endian.hpp.

1809 {
1810 auto runeIter = utf16_rune_iterator(str);
1811 char32_t rune;
1812 size_t written = 0;
1813
1814 if (writeBom) {
1815 if (auto res = writer.write(endian_bom<std::endian::big, char16_t>); res.is_error()) {
1816 return res.error();
1817 }
1818 ++written;
1819 }
1820
1821 while (runeIter.next().copy_if_present(rune)) {
1822 auto seq = rune_to_utf16(rune);
1823 char16_t cur;
1824 auto seqIter = seq.iter();
1825 while (seqIter.next().copy_if_present(cur)) {
1826 if constexpr (std::endian::native != std::endian::big) {
1827 cur = flip_endian(cur);
1828 }
1829 if (auto writeRes = writer.write(cur); writeRes.is_error()) {
1830 return writeRes.error();
1831 }
1832 ++written;
1833 }
1834 }
1835 return success(written);
1836 }
constexpr auto flip_endian(const T bytes)
Flips the endian of a u16, char16, u32, or char32.
constexpr T endian_bom
Here is the call graph for this function:
Here is the caller graph for this function:

◆ utf16_to_utf16le() [1/2]

template<WriterImpl WI>
auto mtcore::utf16_to_utf16le ( io::Writer< WI > & writer,
const Slice< const char16_t > & str,
bool writeBom = false ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Converts native UTF-16 to UTF-16 Little Endian.

Template Parameters
WIWriter Type
Parameters
writerWriter
strUTF-16 (native) to write
writeBomIf it should write BOM
Returns
Number of UTF16 chars written, or error otherwise

Definition at line 1793 of file byte_endian.hpp.

1794 {
1795 return utf16_to_utf16le(writer, endian_from_native_slice(str), writeBom);
1796 }
auto utf16_to_utf16le(io::Writer< WI > &writer, const SliceConstU16Native &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
Converts native UTF-16 to UTF-16 Little Endian.
Here is the call graph for this function:

◆ utf16_to_utf16le() [2/2]

template<WriterImpl WI>
auto mtcore::utf16_to_utf16le ( io::Writer< WI > & writer,
const SliceConstU16Native & str,
bool writeBom = false ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Converts native UTF-16 to UTF-16 Little Endian.

Template Parameters
WIWriter Type
Parameters
writerWriter
strUTF-16 (native) to write
writeBomIf it should write BOM
Returns
Number of UTF16 chars written, or error otherwise

Definition at line 1753 of file byte_endian.hpp.

1754 {
1755 auto runeIter = utf16_rune_iterator(str);
1756 char32_t rune;
1757 size_t written = 0;
1758
1759 if (writeBom) {
1760 if (auto res = writer.write(endian_bom<std::endian::little, char16_t>); res.is_error()) {
1761 return res.error();
1762 }
1763 ++written;
1764 }
1765
1766 while (runeIter.next().copy_if_present(rune)) {
1767 auto seq = rune_to_utf16(rune);
1768 char16_t cur;
1769 auto seqIter = seq.iter();
1770 while (seqIter.next().copy_if_present(cur)) {
1771 if constexpr (std::endian::native != std::endian::little) {
1772 cur = flip_endian(cur);
1773 }
1774 if (auto writeRes = writer.write(cur); writeRes.is_error()) {
1775 return writeRes.error();
1776 }
1777 ++written;
1778 }
1779 }
1780 return success(written);
1781 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ utf16_to_utf32() [1/3]

template<WriterImpl WI>
auto mtcore::utf16_to_utf32 ( io::Writer< WI > & writer,
const Slice< const char16_t > & str,
bool writeBom = false ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Will convert a UTF-16 string to UTF-32.

Template Parameters
WIWriter type
Parameters
writerWriter to write output to (should take char as input)
strUTF-16 string to write (native endian)
writeBomIf it should write a BOM
Returns
Result with number of UTF32 chars written, or error otherwise

Definition at line 1496 of file byte_endian.hpp.

1497 {
1498 return utf16_to_utf32(writer, endian_from_native_slice(str), writeBom);
1499 }
auto utf16_to_utf32(io::Writer< WI > &writer, const SliceConstU16Le &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
Will convert a UTF-16 string to UTF-32.
Here is the call graph for this function:

◆ utf16_to_utf32() [2/3]

template<WriterImpl WI>
auto mtcore::utf16_to_utf32 ( io::Writer< WI > & writer,
const SliceConstU16Be & str,
bool writeBom = false ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Will convert a UTF-16 string to UTF-32.

Template Parameters
WIWriter type
Parameters
writerWriter to write output to (should take char as input)
strUTF-16 string to write (big endian)
writeBomIf it should write a BOM
Returns
Result with number of UTF32 chars written, or error otherwise

Definition at line 1464 of file byte_endian.hpp.

1465 {
1466 auto runeIter = utf16_rune_iterator(str);
1467 char32_t rune;
1468 size_t written = 0;
1469
1470 if (writeBom) {
1471 if (auto res = writer.write(bom); res.is_error()) {
1472 return res.error();
1473 }
1474 ++written;
1475 }
1476
1477 while (runeIter.next().copy_if_present(rune)) {
1478 if (auto writeres = writer.write(rune); writeres.is_error()) {
1479 return writeres.error();
1480 }
1481 ++written;
1482 }
1483 return success(written);
1484 }
Here is the call graph for this function:

◆ utf16_to_utf32() [3/3]

template<WriterImpl WI>
auto mtcore::utf16_to_utf32 ( io::Writer< WI > & writer,
const SliceConstU16Le & str,
bool writeBom = false ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Will convert a UTF-16 string to UTF-32.

Template Parameters
WIWriter type
Parameters
writerWriter to write output to (should take char as input)
strUTF-16 string to write (little endian)
writeBomIf it should write a BOM
Returns
Result with number of UTF32 chars written, or error otherwise

Definition at line 1432 of file byte_endian.hpp.

1433 {
1434 auto runeIter = utf16_rune_iterator(str);
1435 char32_t rune;
1436 size_t written = 0;
1437
1438 if (writeBom) {
1439 if (auto res = writer.write(bom); res.is_error()) {
1440 return res.error();
1441 }
1442 ++written;
1443 }
1444
1445 while (runeIter.next().copy_if_present(rune)) {
1446 if (auto writeres = writer.write(rune); writeres.is_error()) {
1447 return writeres.error();
1448 }
1449 ++written;
1450 }
1451 return success(written);
1452 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ utf16_to_utf8() [1/3]

template<WriterImpl WI>
auto mtcore::utf16_to_utf8 ( io::Writer< WI > & writer,
const Slice< const char16_t > & str ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Will convert a UTF-16 string to UTF-8.

Template Parameters
WIWriter type
Parameters
writerWriter to write output to (should take char as input)
strUTF-16 string to write (native endian)
Returns
Result with number of UTF32 chars written, or error otherwise

Definition at line 1594 of file byte_endian.hpp.

1595 {
1596 return utf16_to_utf8(writer, endian_from_native_slice(str));
1597 }
auto utf16_to_utf8(io::Writer< WI > &writer, const SliceConstU16Be &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
Will convert a UTF-16 string to UTF-8.
Here is the call graph for this function:

◆ utf16_to_utf8() [2/3]

template<WriterImpl WI>
auto mtcore::utf16_to_utf8 ( io::Writer< WI > & writer,
const SliceConstU16Be & str ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Will convert a UTF-16 string to UTF-8.

Template Parameters
WIWriter type
Parameters
writerWriter to write output to (should take char as input)
strUTF-16 string to write (little endian)
Returns
Result with number of UTF8 chars written, or error otherwise

Definition at line 1402 of file byte_endian.hpp.

1403 {
1404 auto runeIter = utf16_rune_iterator(str);
1405 char32_t rune;
1406 size_t written = 0;
1407 while (runeIter.next().copy_if_present(rune)) {
1408 auto seq = rune_to_utf8(rune);
1409 char8_t curCh;
1410 auto charIter = seq.iter();
1411 while (charIter.next().copy_if_present(curCh)) {
1412 if (auto writeRes = writer.write(curCh); writeRes.is_error()) {
1413 return writeRes.error();
1414 }
1415 ++written;
1416 }
1417 }
1418 return success(written);
1419 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ utf16_to_utf8() [3/3]

template<WriterImpl WI>
auto mtcore::utf16_to_utf8 ( io::Writer< WI > & writer,
const SliceConstU16Le & str ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Will convert a UTF-16 string to UTF-8.

Template Parameters
WIWriter type
Parameters
writerWriter to write output to (should take char as input)
strUTF-16 string to write (little endian)
Returns
Result with number of UTF32 chars written, or error otherwise

Definition at line 1510 of file byte_endian.hpp.

1511 {
1512 auto runeIter = utf16_rune_iterator(str);
1513 char32_t rune;
1514 size_t written = 0;
1515 while (runeIter.next().copy_if_present(rune)) {
1516 auto seq = rune_to_utf8(rune);
1517 char8_t curCh;
1518 auto charIter = seq.iter();
1519 while (charIter.next().copy_if_present(curCh)) {
1520 if (auto writeRes = writer.write(curCh); writeRes.is_error()) {
1521 return writeRes.error();
1522 }
1523 ++written;
1524 }
1525 }
1526 return success(written);
1527 }
Here is the call graph for this function:

◆ utf16be_to_utf16()

template<WriterImpl WI>
auto mtcore::utf16be_to_utf16 ( io::Writer< WI > & writer,
const SliceConstU16Be & str,
bool writeBom = false ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Converts UTF-16 Big Endian to Native UTF-16.

Template Parameters
WIWriter Type
Parameters
writerWriter
strUTF-16 (big endian) to write
writeBomIf it should write BOM
Returns
Number of UTF16 chars written, or error otherwise

Definition at line 1980 of file byte_endian.hpp.

1981 {
1982 auto runeIter = utf16_rune_iterator(str);
1983 char32_t rune;
1984 size_t written = 0;
1985
1986 if (writeBom) {
1987 if (auto res = writer.write(endian_bom<std::endian::native, char16_t>); res.is_error()) {
1988 return res.error();
1989 }
1990 ++written;
1991 }
1992
1993 while (runeIter.next().copy_if_present(rune)) {
1994 auto seq = rune_to_utf16(rune);
1995 char16_t cur;
1996 auto seqIter = seq.iter();
1997 while (seqIter.next().copy_if_present(cur)) {
1998 if (auto writeRes = writer.write(cur); writeRes.is_error()) {
1999 return writeRes.error();
2000 }
2001 ++written;
2002 }
2003 }
2004 return success(written);
2005 }
Here is the call graph for this function:

◆ utf16be_to_utf16le()

template<WriterImpl WI>
auto mtcore::utf16be_to_utf16le ( io::Writer< WI > & writer,
const SliceConstU16Be & str,
bool writeBom = false ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Converts UTF-16 Big Endian to UTF-16 Little Endian.

Template Parameters
WIWriter Type
Parameters
writerWriter
strUTF-16 (little endian) to write
writeBomIf it should write BOM
Returns
Number of UTF16 chars written, or error otherwise

Definition at line 1903 of file byte_endian.hpp.

1904 {
1905 auto runeIter = utf16_rune_iterator(str);
1906 char32_t rune;
1907 size_t written = 0;
1908
1909 if (writeBom) {
1910 if (auto res = writer.write(endian_bom<std::endian::little, char16_t>); res.is_error()) {
1911 return res.error();
1912 }
1913 ++written;
1914 }
1915
1916 while (runeIter.next().copy_if_present(rune)) {
1917 auto seq = rune_to_utf16(rune);
1918 char16_t cur;
1919 auto seqIter = seq.iter();
1920 while (seqIter.next().copy_if_present(cur)) {
1921 if constexpr (std::endian::native != std::endian::little) {
1922 cur = flip_endian(cur);
1923 }
1924 if (auto writeRes = writer.write(cur); writeRes.is_error()) {
1925 return writeRes.error();
1926 }
1927 ++written;
1928 }
1929 }
1930 return success(written);
1931 }
Here is the call graph for this function:

◆ utf16le_to_utf16()

template<WriterImpl WI>
auto mtcore::utf16le_to_utf16 ( io::Writer< WI > & writer,
const SliceConstU16Le & str,
bool writeBom = false ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Converts UTF-16 Little Endian to Native UTF-16.

Template Parameters
WIWriter Type
Parameters
writerWriter
strUTF-16 (little endian) to write
writeBomIf it should write BOM
Returns
Number of UTF16 chars written, or error otherwise

Definition at line 1943 of file byte_endian.hpp.

1944 {
1945 auto runeIter = utf16_rune_iterator(str);
1946 char32_t rune;
1947 size_t written = 0;
1948
1949 if (writeBom) {
1950 if (auto res = writer.write(endian_bom<std::endian::native, char16_t>); res.is_error()) {
1951 return res.error();
1952 }
1953 ++written;
1954 }
1955
1956 while (runeIter.next().copy_if_present(rune)) {
1957 auto seq = rune_to_utf16(rune);
1958 char16_t cur;
1959 auto seqIter = seq.iter();
1960 while (seqIter.next().copy_if_present(cur)) {
1961 if (auto writeRes = writer.write(cur); writeRes.is_error()) {
1962 return writeRes.error();
1963 }
1964 ++written;
1965 }
1966 }
1967 return success(written);
1968 }
Here is the call graph for this function:

◆ utf16le_to_utf16be()

template<WriterImpl WI>
auto mtcore::utf16le_to_utf16be ( io::Writer< WI > & writer,
const SliceConstU16Le & str,
bool writeBom = false ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Converts UTF-16 Little Endian to UTF-16 Big Endian.

Template Parameters
WIWriter Type
Parameters
writerWriter
strUTF-16 (little endian) to write
writeBomIf it should write BOM
Returns
Number of UTF16 chars written, or error otherwise

Definition at line 1863 of file byte_endian.hpp.

1864 {
1865 auto runeIter = utf16_rune_iterator(str);
1866 char32_t rune;
1867 size_t written = 0;
1868
1869 if (writeBom) {
1870 if (auto res = writer.write(endian_bom<std::endian::big, char16_t>); res.is_error()) {
1871 return res.error();
1872 }
1873 ++written;
1874 }
1875
1876 while (runeIter.next().copy_if_present(rune)) {
1877 auto seq = rune_to_utf16(rune);
1878 char16_t cur;
1879 auto seqIter = seq.iter();
1880 while (seqIter.next().copy_if_present(cur)) {
1881 if constexpr (std::endian::native != std::endian::big) {
1882 cur = flip_endian(cur);
1883 }
1884 if (auto writeRes = writer.write(cur); writeRes.is_error()) {
1885 return writeRes.error();
1886 }
1887 ++written;
1888 }
1889 }
1890 return success(written);
1891 }
Here is the call graph for this function:

◆ utf32_rune_iterator() [1/5]

RuneIterator< char32_t > mtcore::utf32_rune_iterator ( const Slice< const char32_t > & s)
inline

Rune iterator for a UTF32 sequence.

Will try to auto detect endian from BO. Will drop BOM if presentM

Definition at line 1052 of file byte_endian.hpp.

1052 {
1053 if (s.size()) {
1054 if (const auto encoding = u32_detect_endian(s[0]); encoding.has_value()) {
1055 return {.data = s.sub(1), .strIndex = 0, .reverseBom = encoding == endian::opposite};
1056 }
1057 }
1058 return {.data = s, .strIndex = 0};
1059 }
Optional< std::endian > u32_detect_endian(const char32_t ch)
Tries to detect the endian encoding based on a possible BOM mark.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ utf32_rune_iterator() [2/5]

RuneIterator< char32_t > mtcore::utf32_rune_iterator ( const SliceConstU32Be & s)
inline

Rune iterator for a big endian UTF32 sequence.

Definition at line 1074 of file byte_endian.hpp.

1074 {
1075 return {
1076 .data = {.head = s.head, .len = s.len}, .strIndex = 0, .reverseBom = std::endian::native != std::endian::big};
1077 }

◆ utf32_rune_iterator() [3/5]

RuneIterator< char32_t > mtcore::utf32_rune_iterator ( const SliceConstU32Le & s)
inline

Rune iterator for a little endian UTF32 sequence.

Definition at line 1065 of file byte_endian.hpp.

1065 {
1066 return {
1067 .data = {.head = s.head, .len = s.len}, .strIndex = 0, .reverseBom = std::endian::native != std::endian::little};
1068 }

◆ utf32_rune_iterator() [4/5]

RuneIterator< char32_t > mtcore::utf32_rune_iterator ( const SliceU32Be & s)
inline

Rune iterator for a big endian UTF32 sequence.

Definition at line 1092 of file byte_endian.hpp.

1092 {
1093 return {
1094 .data = {.head = s.head, .len = s.len}, .strIndex = 0, .reverseBom = std::endian::native != std::endian::big};
1095 }

◆ utf32_rune_iterator() [5/5]

RuneIterator< char32_t > mtcore::utf32_rune_iterator ( const SliceU32Le & s)
inline

Rune iterator for a little endian UTF32 sequence.

Definition at line 1083 of file byte_endian.hpp.

1083 {
1084 return {
1085 .data = {.head = s.head, .len = s.len}, .strIndex = 0, .reverseBom = std::endian::native != std::endian::little};
1086 }

◆ utf32_to_str() [1/3]

template<WriterImpl WI>
auto mtcore::utf32_to_str ( io::Writer< WI > & writer,
const Slice< const char32_t > & str ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Will convert a UTF-32 string to character sequence (UTF-8 encoded chars)

Template Parameters
WIWriter type
Parameters
writerWriter to write output to (should take char as input)
strUTF-32 string to write (native endian)
Returns
Result with number of UTF8 chars written, or error otherwise

Definition at line 1324 of file byte_endian.hpp.

1325 {
1326 return utf32_to_str(writer, endian_from_native_slice(str));
1327 }
auto utf32_to_str(io::Writer< WI > &writer, const SliceConstU32Be &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
Will convert a UTF-32 string to character sequence (UTF-8 encoded chars)
Here is the call graph for this function:

◆ utf32_to_str() [2/3]

template<WriterImpl WI>
auto mtcore::utf32_to_str ( io::Writer< WI > & writer,
const SliceConstU32Be & str ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Will convert a UTF-32 string to character sequence (UTF-8 encoded chars)

Template Parameters
WIWriter type
Parameters
writerWriter to write output to (should take char as input)
strUTF-32 string to write (big endian)
Returns
Result with number of UTF8 chars written, or error otherwise

Definition at line 1268 of file byte_endian.hpp.

1269 {
1270 char32_t cur;
1271 auto iter = utf32_rune_iterator(str);
1272 size_t written = 0;
1273 while (iter.next().copy_if_present(cur)) {
1274 auto seq = rune_to_str(cur);
1275 char curCh;
1276 auto iter2 = seq.iter();
1277 while (iter2.next().copy_if_present(curCh)) {
1278 if (auto writeRes = writer.write(curCh); writeRes.is_error()) {
1279 return writeRes.error();
1280 }
1281 ++written;
1282 }
1283 }
1284 return success(written);
1285 }
RuneIterator< char32_t > utf32_rune_iterator(const Slice< const char32_t > &s)
Rune iterator for a UTF32 sequence.
Generic iterator defaults built on common contracts Does not guarantee performance of iterators Actua...
Definition iter.hpp:91
Here is the call graph for this function:
Here is the caller graph for this function:

◆ utf32_to_str() [3/3]

template<WriterImpl WI>
auto mtcore::utf32_to_str ( io::Writer< WI > & writer,
const SliceConstU32Le & str ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Will convert a UTF-32 string to character sequence (UTF-8 encoded chars)

Template Parameters
WIWriter type
Parameters
writerWriter to write output to (should take char as input)
strUTF-32 string to write (little endian)
Returns
Result with number of UTF8 chars written, or error otherwise

Definition at line 1296 of file byte_endian.hpp.

1297 {
1298 char32_t cur;
1299 auto iter = utf32_rune_iterator(str);
1300 size_t written = 0;
1301 while (iter.next().copy_if_present(cur)) {
1302 auto seq = rune_to_str(cur);
1303 char curCh;
1304 auto iter2 = seq.iter();
1305 while (iter2.next().copy_if_present(curCh)) {
1306 if (auto writeRes = writer.write(curCh); writeRes.is_error()) {
1307 return writeRes.error();
1308 }
1309 ++written;
1310 }
1311 }
1312 return success(written);
1313 }
Here is the call graph for this function:

◆ utf32_to_utf16() [1/3]

template<WriterImpl WI>
auto mtcore::utf32_to_utf16 ( io::Writer< WI > & writer,
const Slice< const char32_t > & str,
bool writeBom = false ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Will convert a UTF-32 string to UTF-16 string Can optionally write a BOM to the prefix.

Template Parameters
WIWriter type
Parameters
writerWriter to write output to (should take char16_t as input)
strUTF-32 string to write (native endian)
writeBomIf it should write the BOM (will write it in native endian)
Returns
Result with number of UTF16 chars written, or error otherwise

Definition at line 1184 of file byte_endian.hpp.

1185 {
1186 return utf32_to_utf16(writer, endian_from_native_slice(str), writeBom);
1187 }
auto utf32_to_utf16(io::Writer< WI > &writer, const SliceConstU32Be &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
Will convert a UTF-32 string to UTF-16 string Can optionally write a BOM to the prefix.
Here is the call graph for this function:

◆ utf32_to_utf16() [2/3]

template<WriterImpl WI>
auto mtcore::utf32_to_utf16 ( io::Writer< WI > & writer,
const SliceConstU32Be & str,
bool writeBom = false ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Will convert a UTF-32 string to UTF-16 string Can optionally write a BOM to the prefix.

Template Parameters
WIWriter type
Parameters
writerWriter to write output to (should take char16_t as input)
strUTF-32 string to write (big endian)
writeBomIf it should write the BOM (will write it in native endian)
Returns
Result with number of UTF16 chars written, or error otherwise

Definition at line 1108 of file byte_endian.hpp.

1109 {
1110 char32_t cur;
1111 auto iter = utf32_rune_iterator(str);
1112 size_t written = 0;
1113
1114 if (writeBom) {
1115 if (auto res = writer.write(bom); res.is_error()) {
1116 return res.error();
1117 }
1118 ++written;
1119 }
1120
1121 while (iter.next().copy_if_present(cur)) {
1122 auto seq = rune_to_utf16(cur);
1123 char16_t curCh;
1124 auto iter2 = seq.iter();
1125 while (iter2.next().copy_if_present(curCh)) {
1126 if (auto writeRes = writer.write(curCh); writeRes.is_error()) {
1127 return writeRes.error();
1128 }
1129 ++written;
1130 }
1131 }
1132 return success(written);
1133 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ utf32_to_utf16() [3/3]

template<WriterImpl WI>
auto mtcore::utf32_to_utf16 ( io::Writer< WI > & writer,
const SliceConstU32Le & str,
bool writeBom = false ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Will convert a UTF-32 string to UTF-16 string Can optionally write a BOM to the prefix.

Template Parameters
WIWriter type
Parameters
writerWriter to write output to (should take char16_t as input)
strUTF-32 string to write (little endian)
writeBomIf it should write the BOM (will write it in native endian)
Returns
Result with number of UTF16 chars written, or error otherwise

Definition at line 1146 of file byte_endian.hpp.

1147 {
1148 char32_t cur;
1149 auto iter = utf32_rune_iterator(str);
1150 size_t written = 0;
1151
1152 if (writeBom) {
1153 if (auto res = writer.write(bom); res.is_error()) {
1154 return res.error();
1155 }
1156 ++written;
1157 }
1158
1159 while (iter.next().copy_if_present(cur)) {
1160 auto seq = rune_to_utf16(cur);
1161 char16_t curCh;
1162 auto iter2 = seq.iter();
1163 while (iter2.next().copy_if_present(curCh)) {
1164 if (auto writeRes = writer.write(curCh); writeRes.is_error()) {
1165 return writeRes.error();
1166 }
1167 ++written;
1168 }
1169 }
1170 return success(written);
1171 }
Here is the call graph for this function:

◆ utf32_to_utf32be() [1/2]

template<WriterImpl WI>
auto mtcore::utf32_to_utf32be ( io::Writer< WI > & writer,
const Slice< const char32_t > & str,
bool writeBom = false ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Converts UTF-32 Native Endian to UTF-32 Big Endian.

Template Parameters
WIWriter Type
Parameters
writerWriter
strUTF-32 (big endian) to write
writeBomIf it should write BOM
Returns
Number of UTF32 chars written, or error otherwise

Definition at line 2102 of file byte_endian.hpp.

2103 {
2104 return utf32_to_utf32be(writer, endian_from_native_slice(str), writeBom);
2105 }
auto utf32_to_utf32be(io::Writer< WI > &writer, const SliceConstU32Native &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
Converts UTF-32 Native Endian to UTF-32 Big Endian.
Here is the call graph for this function:

◆ utf32_to_utf32be() [2/2]

template<WriterImpl WI>
auto mtcore::utf32_to_utf32be ( io::Writer< WI > & writer,
const SliceConstU32Native & str,
bool writeBom = false ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Converts UTF-32 Native Endian to UTF-32 Big Endian.

Template Parameters
WIWriter Type
Parameters
writerWriter
strUTF-32 (big endian) to write
writeBomIf it should write BOM
Returns
Number of UTF32 chars written, or error otherwise

Definition at line 2067 of file byte_endian.hpp.

2068 {
2069 auto runeIter = utf32_rune_iterator(str);
2070 char32_t rune;
2071 size_t written = 0;
2072
2073 if (writeBom) {
2074 if (auto res = writer.write(endian_bom<std::endian::big, char32_t>); res.is_error()) {
2075 return res.error();
2076 }
2077 ++written;
2078 }
2079
2080 while (runeIter.next().copy_if_present(rune)) {
2081 if constexpr (std::endian::native != std::endian::big) {
2082 rune = flip_endian(rune);
2083 }
2084 if (auto writeRes = writer.write(rune); writeRes.is_error()) {
2085 return writeRes.error();
2086 }
2087 ++written;
2088 }
2089 return success(written);
2090 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ utf32_to_utf32le() [1/2]

template<WriterImpl WI>
auto mtcore::utf32_to_utf32le ( io::Writer< WI > & writer,
const Slice< const char32_t > & str,
bool writeBom = false ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Converts UTF-32 Native Endian to UTF-32 Little Endian.

Template Parameters
WIWriter Type
Parameters
writerWriter
strUTF-32 (little endian) to write
writeBomIf it should write BOM
Returns
Number of UTF32 chars written, or error otherwise

Definition at line 2052 of file byte_endian.hpp.

2053 {
2054 return utf32_to_utf32le(writer, endian_from_native_slice(str), writeBom);
2055 }
auto utf32_to_utf32le(io::Writer< WI > &writer, const SliceConstU32Native &str, bool writeBom=false) -> Result< size_t, typename io::Writer< WI >::ErrType >
Converts UTF-32 Native Endian to UTF-32 Little Endian.
Here is the call graph for this function:

◆ utf32_to_utf32le() [2/2]

template<WriterImpl WI>
auto mtcore::utf32_to_utf32le ( io::Writer< WI > & writer,
const SliceConstU32Native & str,
bool writeBom = false ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Converts UTF-32 Native Endian to UTF-32 Little Endian.

Template Parameters
WIWriter Type
Parameters
writerWriter
strUTF-32 (little endian) to write
writeBomIf it should write BOM
Returns
Number of UTF32 chars written, or error otherwise

Definition at line 2017 of file byte_endian.hpp.

2018 {
2019 auto runeIter = utf32_rune_iterator(str);
2020 char32_t rune;
2021 size_t written = 0;
2022
2023 if (writeBom) {
2024 if (auto res = writer.write(endian_bom<std::endian::little, char32_t>); res.is_error()) {
2025 return res.error();
2026 }
2027 ++written;
2028 }
2029
2030 while (runeIter.next().copy_if_present(rune)) {
2031 if constexpr (std::endian::native != std::endian::little) {
2032 rune = flip_endian(rune);
2033 }
2034 if (auto writeRes = writer.write(rune); writeRes.is_error()) {
2035 return writeRes.error();
2036 }
2037 ++written;
2038 }
2039 return success(written);
2040 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ utf32_to_utf8() [1/3]

template<WriterImpl WI>
auto mtcore::utf32_to_utf8 ( io::Writer< WI > & writer,
const Slice< const char32_t > & str ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Will convert a UTF-32 string to UTF-8 string.

Template Parameters
WIWriter type
Parameters
writerWriter to write output to (should take char8_t as input)
strUTF-32 string to write (native endian)
Returns
Result with number of UTF8 chars written, or error otherwise

Definition at line 1254 of file byte_endian.hpp.

1255 {
1256 return utf32_to_utf8(writer, endian_from_native_slice(str));
1257 }
auto utf32_to_utf8(io::Writer< WI > &writer, const SliceConstU32Be &str) -> Result< size_t, typename io::Writer< WI >::ErrType >
Will convert a UTF-32 string to UTF-8 string.
Here is the call graph for this function:

◆ utf32_to_utf8() [2/3]

template<WriterImpl WI>
auto mtcore::utf32_to_utf8 ( io::Writer< WI > & writer,
const SliceConstU32Be & str ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Will convert a UTF-32 string to UTF-8 string.

Template Parameters
WIWriter type
Parameters
writerWriter to write output to (should take char8_t as input)
strUTF-32 string to write (big endian)
Returns
Result with number of UTF8 chars written, or error otherwise

Definition at line 1198 of file byte_endian.hpp.

1199 {
1200 char32_t cur;
1201 auto iter = utf32_rune_iterator(str);
1202 size_t written = 0;
1203 while (iter.next().copy_if_present(cur)) {
1204 auto seq = rune_to_utf8(cur);
1205 char8_t curCh;
1206 auto iter2 = seq.iter();
1207 while (iter2.next().copy_if_present(curCh)) {
1208 if (auto writeRes = writer.write(curCh); writeRes.is_error()) {
1209 return writeRes.error();
1210 }
1211 ++written;
1212 }
1213 }
1214 return success(written);
1215 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ utf32_to_utf8() [3/3]

template<WriterImpl WI>
auto mtcore::utf32_to_utf8 ( io::Writer< WI > & writer,
const SliceConstU32Le & str ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Will convert a UTF-32 string to UTF-8 string.

Template Parameters
WIWriter type
Parameters
writerWriter to write output to (should take char8_t as input)
strUTF-32 string to write (little endian)
Returns
Result with number of UTF8 chars written, or error otherwise

Definition at line 1226 of file byte_endian.hpp.

1227 {
1228 char32_t cur;
1229 auto iter = utf32_rune_iterator(str);
1230 size_t written = 0;
1231 while (iter.next().copy_if_present(cur)) {
1232 auto seq = rune_to_utf8(cur);
1233 char8_t curCh;
1234 auto iter2 = seq.iter();
1235 while (iter2.next().copy_if_present(curCh)) {
1236 if (auto writeRes = writer.write(curCh); writeRes.is_error()) {
1237 return writeRes.error();
1238 }
1239 ++written;
1240 }
1241 }
1242 return success(written);
1243 }
Here is the call graph for this function:

◆ utf32be_to_utf32()

template<WriterImpl WI>
auto mtcore::utf32be_to_utf32 ( io::Writer< WI > & writer,
const SliceConstU32Be & str,
bool writeBom = false ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Converts UTF-32 Big Endian to UTF-32 Native Endian.

Template Parameters
WIWriter Type
Parameters
writerWriter
strUTF-32 (little endian) to write
writeBomIf it should write BOM
Returns
Number of UTF32 chars written, or error otherwise

Definition at line 2219 of file byte_endian.hpp.

2220 {
2221 auto runeIter = utf32_rune_iterator(str);
2222 char32_t rune;
2223 size_t written = 0;
2224
2225 if (writeBom) {
2226 if (auto res = writer.write(endian_bom<std::endian::native, char32_t>); res.is_error()) {
2227 return res.error();
2228 }
2229 ++written;
2230 }
2231
2232 while (runeIter.next().copy_if_present(rune)) {
2233 if (auto writeRes = writer.write(rune); writeRes.is_error()) {
2234 return writeRes.error();
2235 }
2236 ++written;
2237 }
2238 return success(written);
2239 }
Here is the call graph for this function:

◆ utf32be_to_utf32le()

template<WriterImpl WI>
auto mtcore::utf32be_to_utf32le ( io::Writer< WI > & writer,
const SliceConstU32Be & str,
bool writeBom = false ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Converts UTF-32 Big Endian to UTF-32 Little Endian.

Template Parameters
WIWriter Type
Parameters
writerWriter
strUTF-32 (little endian) to write
writeBomIf it should write BOM
Returns
Number of UTF32 chars written, or error otherwise

Definition at line 2152 of file byte_endian.hpp.

2153 {
2154 auto runeIter = utf32_rune_iterator(str);
2155 char32_t rune;
2156 size_t written = 0;
2157
2158 if (writeBom) {
2159 if (auto res = writer.write(endian_bom<std::endian::little, char32_t>); res.is_error()) {
2160 return res.error();
2161 }
2162 ++written;
2163 }
2164
2165 while (runeIter.next().copy_if_present(rune)) {
2166 if constexpr (std::endian::native != std::endian::little) {
2167 rune = flip_endian(rune);
2168 }
2169 if (auto writeRes = writer.write(rune); writeRes.is_error()) {
2170 return writeRes.error();
2171 }
2172 ++written;
2173 }
2174 return success(written);
2175 }
Here is the call graph for this function:

◆ utf32le_to_utf32()

template<WriterImpl WI>
auto mtcore::utf32le_to_utf32 ( io::Writer< WI > & writer,
const SliceConstU32Le & str,
bool writeBom = false ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Converts UTF-32 Little Endian to UTF-32 Native Endian.

Template Parameters
WIWriter Type
Parameters
writerWriter
strUTF-32 (little endian) to write
writeBomIf it should write BOM
Returns
Number of UTF32 chars written, or error otherwise

Definition at line 2187 of file byte_endian.hpp.

2188 {
2189 auto runeIter = utf32_rune_iterator(str);
2190 char32_t rune;
2191 size_t written = 0;
2192
2193 if (writeBom) {
2194 if (auto res = writer.write(endian_bom<std::endian::native, char32_t>); res.is_error()) {
2195 return res.error();
2196 }
2197 ++written;
2198 }
2199
2200 while (runeIter.next().copy_if_present(rune)) {
2201 if (auto writeRes = writer.write(rune); writeRes.is_error()) {
2202 return writeRes.error();
2203 }
2204 ++written;
2205 }
2206 return success(written);
2207 }
Here is the call graph for this function:

◆ utf32le_to_utf32be()

template<WriterImpl WI>
auto mtcore::utf32le_to_utf32be ( io::Writer< WI > & writer,
const SliceConstU32Le & str,
bool writeBom = false ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Converts UTF-32 Little Endian to UTF-32 Big Endian.

Template Parameters
WIWriter Type
Parameters
writerWriter
strUTF-32 (little endian) to write
writeBomIf it should write BOM
Returns
Number of UTF32 chars written, or error otherwise

Definition at line 2117 of file byte_endian.hpp.

2118 {
2119 auto runeIter = utf32_rune_iterator(str);
2120 char32_t rune;
2121 size_t written = 0;
2122
2123 if (writeBom) {
2124 if (auto res = writer.write(endian_bom<std::endian::big, char32_t>); res.is_error()) {
2125 return res.error();
2126 }
2127 ++written;
2128 }
2129
2130 while (runeIter.next().copy_if_present(rune)) {
2131 if constexpr (std::endian::native != std::endian::big) {
2132 rune = flip_endian(rune);
2133 }
2134 if (auto writeRes = writer.write(rune); writeRes.is_error()) {
2135 return writeRes.error();
2136 }
2137 ++written;
2138 }
2139 return success(written);
2140 }
Here is the call graph for this function:

◆ utf8_rune_iterator()

RuneIterator< char8_t > mtcore::utf8_rune_iterator ( const Slice< const char8_t > & s)
inline

Rune iterator for a UTF8 sequence.

Definition at line 997 of file byte_endian.hpp.

997{ return {.data = s, .strIndex = 0}; }
Here is the caller graph for this function:

◆ utf8_to_str()

template<WriterImpl WI>
auto mtcore::utf8_to_str ( io::Writer< WI > & writer,
const Slice< const char8_t > & str ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Will convert a UTF-8 string to character sequence.

Template Parameters
WIWriter type
Parameters
writerWriter to write output to (should take char as input)
strUTF-8 string to write
Returns
Result with number of UTF32 chars written, or error otherwise

Definition at line 1696 of file byte_endian.hpp.

1697 {
1698 auto runeIter = utf8_rune_iterator(str);
1699 char32_t rune;
1700 size_t written = 0;
1701 while (runeIter.next().copy_if_present(rune)) {
1702 auto seq = rune_to_str(rune);
1703 char curCh;
1704 auto charIter = seq.iter();
1705 while (charIter.next().copy_if_present(curCh)) {
1706 if (auto writeRes = writer.write(curCh); writeRes.is_error()) {
1707 return writeRes.error();
1708 }
1709 ++written;
1710 }
1711 }
1712 return success(written);
1713 }
RuneIterator< char8_t > utf8_rune_iterator(const Slice< const char8_t > &s)
Rune iterator for a UTF8 sequence.
Here is the call graph for this function:

◆ utf8_to_utf16()

template<WriterImpl WI>
auto mtcore::utf8_to_utf16 ( io::Writer< WI > & writer,
const Slice< const char8_t > & str,
bool writeBom = false ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Will convert a UTF-8 string to UTF-16.

Template Parameters
WIWriter type
Parameters
writerWriter to write output to (should take char as input)
strUTF-8 string to write
writeBomIf it should write a BOM
Returns
Result with number of UTF32 chars written, or error otherwise

Definition at line 1623 of file byte_endian.hpp.

1624 {
1625 auto runeIter = utf8_rune_iterator(str);
1626 char32_t rune;
1627 size_t written = 0;
1628
1629 if (writeBom) {
1630 if (auto res = writer.write(bom); res.is_error()) {
1631 return res.error();
1632 }
1633 ++written;
1634 }
1635
1636 while (runeIter.next().copy_if_present(rune)) {
1637 auto seq = rune_to_utf16(rune);
1638 char16_t curCh;
1639 auto charIter = seq.iter();
1640 while (charIter.next().copy_if_present(curCh)) {
1641 if (auto writeRes = writer.write(curCh); writeRes.is_error()) {
1642 return writeRes.error();
1643 }
1644 ++written;
1645 }
1646 }
1647 return success(written);
1648 }
Here is the call graph for this function:

◆ utf8_to_utf32()

template<WriterImpl WI>
auto mtcore::utf8_to_utf32 ( io::Writer< WI > & writer,
const Slice< const char8_t > & str,
bool writeBom = false ) -> Result<size_t, typename io::Writer<WI>::ErrType>

Will convert a UTF-8 string to UTF-32.

Template Parameters
WIWriter type
Parameters
writerWriter to write output to (should take char as input)
strUTF-8 string to write
writeBomIf it should write a BOM
Returns
Result with number of UTF32 chars written, or error otherwise

Definition at line 1339 of file byte_endian.hpp.

1340 {
1341 auto runeIter = utf8_rune_iterator(str);
1342 char32_t rune;
1343 size_t written = 0;
1344
1345 if (writeBom) {
1346 if (auto res = writer.write(bom); res.is_error()) {
1347 return res.error();
1348 }
1349 ++written;
1350 }
1351
1352 while (runeIter.next().copy_if_present(rune)) {
1353 if (auto writeRes = writer.write(rune); writeRes.is_error()) {
1354 return writeRes.error();
1355 }
1356 ++written;
1357 }
1358 return success(written);
1359 }
Here is the call graph for this function:

Variable Documentation

◆ bom

char32_t mtcore::bom = 0xFEFF
constexpr

Native representation of Byte Order Mark (BOM)

Definition at line 39 of file byte_endian.hpp.

◆ oppositeEndian

template<std::endian E = std::endian::native>
auto mtcore::oppositeEndian = E == std::endian::big ? std::endian::little : std::endian::big
constexpr

Returns the opposite endianness of a given endian (default is opposite of the native endian)

Definition at line 158 of file byte_endian.hpp.