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 1652 of file byte_endian.hpp.

1653 {
1654 auto runeIter = str_rune_iterator(str);
1655 char32_t rune;
1656 size_t written = 0;
1657
1658 if (writeBom) {
1659 if (auto res = writer.write(bom); res.is_error()) {
1660 return res.error();
1661 }
1662 ++written;
1663 }
1664
1665 while (runeIter.next().copy_if_present(rune)) {
1666 auto seq = rune_to_utf16(rune);
1667 char16_t curCh;
1668 auto charIter = seq.iter();
1669 while (charIter.next().copy_if_present(curCh)) {
1670 if (auto writeRes = writer.write(curCh); writeRes.is_error()) {
1671 return writeRes.error();
1672 }
1673 ++written;
1674 }
1675 }
1676 return success(written);
1677 }
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 1367 of file byte_endian.hpp.

1368 {
1369 auto runeIter = str_rune_iterator(str);
1370 char32_t rune;
1371 size_t written = 0;
1372
1373 if (writeBom) {
1374 if (auto res = writer.write(bom); res.is_error()) {
1375 return res.error();
1376 }
1377 ++written;
1378 }
1379
1380 while (runeIter.next().copy_if_present(rune)) {
1381 if (auto writeRes = writer.write(rune); writeRes.is_error()) {
1382 return writeRes.error();
1383 }
1384 ++written;
1385 }
1386 return success(written);
1387 }
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 1716 of file byte_endian.hpp.

1716 {
1717 auto runeIter = str_rune_iterator(str);
1718 char32_t rune;
1719 size_t written = 0;
1720 while (runeIter.next().copy_if_present(rune)) {
1721 auto seq = rune_to_utf8(rune);
1722 char8_t curCh;
1723 auto charIter = seq.iter();
1724 while (charIter.next().copy_if_present(curCh)) {
1725 if (auto writeRes = writer.write(curCh); writeRes.is_error()) {
1726 return writeRes.error();
1727 }
1728 ++written;
1729 }
1730 }
1731 return success(written);
1732 }
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 1600 of file byte_endian.hpp.

1601 {
1602 return utf16_to_str(writer, endian_from_native_slice(str));
1603 }
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 1532 of file byte_endian.hpp.

1532 {
1533 auto runeIter = utf16_rune_iterator(str);
1534 char32_t rune;
1535 size_t written = 0;
1536 while (runeIter.next().copy_if_present(rune)) {
1537 auto seq = rune_to_str(rune);
1538 char curCh;
1539 auto charIter = seq.iter();
1540 while (charIter.next().copy_if_present(curCh)) {
1541 if (auto writeRes = writer.write(curCh); writeRes.is_error()) {
1542 return writeRes.error();
1543 }
1544 ++written;
1545 }
1546 }
1547 return success(written);
1548 }
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 1559 of file byte_endian.hpp.

1559 {
1560 auto runeIter = utf16_rune_iterator(str);
1561 char32_t rune;
1562 size_t written = 0;
1563 while (runeIter.next().copy_if_present(rune)) {
1564 auto seq = rune_to_str(rune);
1565 char curCh;
1566 auto charIter = seq.iter();
1567 while (charIter.next().copy_if_present(curCh)) {
1568 if (auto writeRes = writer.write(curCh); writeRes.is_error()) {
1569 return writeRes.error();
1570 }
1571 ++written;
1572 }
1573 }
1574 return success(written);
1575 }
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 1839 of file byte_endian.hpp.

1840 {
1841 return utf16_to_utf16be(writer, endian_from_native_slice(str), writeBom);
1842 }
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 1799 of file byte_endian.hpp.

1800 {
1801 auto runeIter = utf16_rune_iterator(str);
1802 char32_t rune;
1803 size_t written = 0;
1804
1805 if (writeBom) {
1806 if (auto res = writer.write(endian_bom<std::endian::big, char16_t>); res.is_error()) {
1807 return res.error();
1808 }
1809 ++written;
1810 }
1811
1812 while (runeIter.next().copy_if_present(rune)) {
1813 auto seq = rune_to_utf16(rune);
1814 char16_t cur;
1815 auto seqIter = seq.iter();
1816 while (seqIter.next().copy_if_present(cur)) {
1817 if constexpr (std::endian::native != std::endian::big) {
1818 cur = flip_endian(cur);
1819 }
1820 if (auto writeRes = writer.write(cur); writeRes.is_error()) {
1821 return writeRes.error();
1822 }
1823 ++written;
1824 }
1825 }
1826 return success(written);
1827 }
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 1784 of file byte_endian.hpp.

1785 {
1786 return utf16_to_utf16le(writer, endian_from_native_slice(str), writeBom);
1787 }
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 1744 of file byte_endian.hpp.

1745 {
1746 auto runeIter = utf16_rune_iterator(str);
1747 char32_t rune;
1748 size_t written = 0;
1749
1750 if (writeBom) {
1751 if (auto res = writer.write(endian_bom<std::endian::little, char16_t>); res.is_error()) {
1752 return res.error();
1753 }
1754 ++written;
1755 }
1756
1757 while (runeIter.next().copy_if_present(rune)) {
1758 auto seq = rune_to_utf16(rune);
1759 char16_t cur;
1760 auto seqIter = seq.iter();
1761 while (seqIter.next().copy_if_present(cur)) {
1762 if constexpr (std::endian::native != std::endian::little) {
1763 cur = flip_endian(cur);
1764 }
1765 if (auto writeRes = writer.write(cur); writeRes.is_error()) {
1766 return writeRes.error();
1767 }
1768 ++written;
1769 }
1770 }
1771 return success(written);
1772 }
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 1491 of file byte_endian.hpp.

1492 {
1493 return utf16_to_utf32(writer, endian_from_native_slice(str), writeBom);
1494 }
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 1459 of file byte_endian.hpp.

1460 {
1461 auto runeIter = utf16_rune_iterator(str);
1462 char32_t rune;
1463 size_t written = 0;
1464
1465 if (writeBom) {
1466 if (auto res = writer.write(bom); res.is_error()) {
1467 return res.error();
1468 }
1469 ++written;
1470 }
1471
1472 while (runeIter.next().copy_if_present(rune)) {
1473 if (auto writeres = writer.write(rune); writeres.is_error()) {
1474 return writeres.error();
1475 }
1476 ++written;
1477 }
1478 return success(written);
1479 }
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 1427 of file byte_endian.hpp.

1428 {
1429 auto runeIter = utf16_rune_iterator(str);
1430 char32_t rune;
1431 size_t written = 0;
1432
1433 if (writeBom) {
1434 if (auto res = writer.write(bom); res.is_error()) {
1435 return res.error();
1436 }
1437 ++written;
1438 }
1439
1440 while (runeIter.next().copy_if_present(rune)) {
1441 if (auto writeres = writer.write(rune); writeres.is_error()) {
1442 return writeres.error();
1443 }
1444 ++written;
1445 }
1446 return success(written);
1447 }
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 1586 of file byte_endian.hpp.

1587 {
1588 return utf16_to_utf8(writer, endian_from_native_slice(str));
1589 }
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 1398 of file byte_endian.hpp.

1398 {
1399 auto runeIter = utf16_rune_iterator(str);
1400 char32_t rune;
1401 size_t written = 0;
1402 while (runeIter.next().copy_if_present(rune)) {
1403 auto seq = rune_to_utf8(rune);
1404 char8_t curCh;
1405 auto charIter = seq.iter();
1406 while (charIter.next().copy_if_present(curCh)) {
1407 if (auto writeRes = writer.write(curCh); writeRes.is_error()) {
1408 return writeRes.error();
1409 }
1410 ++written;
1411 }
1412 }
1413 return success(written);
1414 }
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 1505 of file byte_endian.hpp.

1505 {
1506 auto runeIter = utf16_rune_iterator(str);
1507 char32_t rune;
1508 size_t written = 0;
1509 while (runeIter.next().copy_if_present(rune)) {
1510 auto seq = rune_to_utf8(rune);
1511 char8_t curCh;
1512 auto charIter = seq.iter();
1513 while (charIter.next().copy_if_present(curCh)) {
1514 if (auto writeRes = writer.write(curCh); writeRes.is_error()) {
1515 return writeRes.error();
1516 }
1517 ++written;
1518 }
1519 }
1520 return success(written);
1521 }
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 1971 of file byte_endian.hpp.

1972 {
1973 auto runeIter = utf16_rune_iterator(str);
1974 char32_t rune;
1975 size_t written = 0;
1976
1977 if (writeBom) {
1978 if (auto res = writer.write(endian_bom<std::endian::native, char16_t>); res.is_error()) {
1979 return res.error();
1980 }
1981 ++written;
1982 }
1983
1984 while (runeIter.next().copy_if_present(rune)) {
1985 auto seq = rune_to_utf16(rune);
1986 char16_t cur;
1987 auto seqIter = seq.iter();
1988 while (seqIter.next().copy_if_present(cur)) {
1989 if (auto writeRes = writer.write(cur); writeRes.is_error()) {
1990 return writeRes.error();
1991 }
1992 ++written;
1993 }
1994 }
1995 return success(written);
1996 }
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 1894 of file byte_endian.hpp.

1895 {
1896 auto runeIter = utf16_rune_iterator(str);
1897 char32_t rune;
1898 size_t written = 0;
1899
1900 if (writeBom) {
1901 if (auto res = writer.write(endian_bom<std::endian::little, char16_t>); res.is_error()) {
1902 return res.error();
1903 }
1904 ++written;
1905 }
1906
1907 while (runeIter.next().copy_if_present(rune)) {
1908 auto seq = rune_to_utf16(rune);
1909 char16_t cur;
1910 auto seqIter = seq.iter();
1911 while (seqIter.next().copy_if_present(cur)) {
1912 if constexpr (std::endian::native != std::endian::little) {
1913 cur = flip_endian(cur);
1914 }
1915 if (auto writeRes = writer.write(cur); writeRes.is_error()) {
1916 return writeRes.error();
1917 }
1918 ++written;
1919 }
1920 }
1921 return success(written);
1922 }
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 1934 of file byte_endian.hpp.

1935 {
1936 auto runeIter = utf16_rune_iterator(str);
1937 char32_t rune;
1938 size_t written = 0;
1939
1940 if (writeBom) {
1941 if (auto res = writer.write(endian_bom<std::endian::native, char16_t>); res.is_error()) {
1942 return res.error();
1943 }
1944 ++written;
1945 }
1946
1947 while (runeIter.next().copy_if_present(rune)) {
1948 auto seq = rune_to_utf16(rune);
1949 char16_t cur;
1950 auto seqIter = seq.iter();
1951 while (seqIter.next().copy_if_present(cur)) {
1952 if (auto writeRes = writer.write(cur); writeRes.is_error()) {
1953 return writeRes.error();
1954 }
1955 ++written;
1956 }
1957 }
1958 return success(written);
1959 }
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 1854 of file byte_endian.hpp.

1855 {
1856 auto runeIter = utf16_rune_iterator(str);
1857 char32_t rune;
1858 size_t written = 0;
1859
1860 if (writeBom) {
1861 if (auto res = writer.write(endian_bom<std::endian::big, char16_t>); res.is_error()) {
1862 return res.error();
1863 }
1864 ++written;
1865 }
1866
1867 while (runeIter.next().copy_if_present(rune)) {
1868 auto seq = rune_to_utf16(rune);
1869 char16_t cur;
1870 auto seqIter = seq.iter();
1871 while (seqIter.next().copy_if_present(cur)) {
1872 if constexpr (std::endian::native != std::endian::big) {
1873 cur = flip_endian(cur);
1874 }
1875 if (auto writeRes = writer.write(cur); writeRes.is_error()) {
1876 return writeRes.error();
1877 }
1878 ++written;
1879 }
1880 }
1881 return success(written);
1882 }
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 1320 of file byte_endian.hpp.

1321 {
1322 return utf32_to_str(writer, endian_from_native_slice(str));
1323 }
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 1266 of file byte_endian.hpp.

1266 {
1267 char32_t cur;
1268 auto iter = utf32_rune_iterator(str);
1269 size_t written = 0;
1270 while (iter.next().copy_if_present(cur)) {
1271 auto seq = rune_to_str(cur);
1272 char curCh;
1273 auto iter2 = seq.iter();
1274 while (iter2.next().copy_if_present(curCh)) {
1275 if (auto writeRes = writer.write(curCh); writeRes.is_error()) {
1276 return writeRes.error();
1277 }
1278 ++written;
1279 }
1280 }
1281 return success(written);
1282 }
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 1293 of file byte_endian.hpp.

1293 {
1294 char32_t cur;
1295 auto iter = utf32_rune_iterator(str);
1296 size_t written = 0;
1297 while (iter.next().copy_if_present(cur)) {
1298 auto seq = rune_to_str(cur);
1299 char curCh;
1300 auto iter2 = seq.iter();
1301 while (iter2.next().copy_if_present(curCh)) {
1302 if (auto writeRes = writer.write(curCh); writeRes.is_error()) {
1303 return writeRes.error();
1304 }
1305 ++written;
1306 }
1307 }
1308 return success(written);
1309 }
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 2093 of file byte_endian.hpp.

2094 {
2095 return utf32_to_utf32be(writer, endian_from_native_slice(str), writeBom);
2096 }
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 2058 of file byte_endian.hpp.

2059 {
2060 auto runeIter = utf32_rune_iterator(str);
2061 char32_t rune;
2062 size_t written = 0;
2063
2064 if (writeBom) {
2065 if (auto res = writer.write(endian_bom<std::endian::big, char32_t>); res.is_error()) {
2066 return res.error();
2067 }
2068 ++written;
2069 }
2070
2071 while (runeIter.next().copy_if_present(rune)) {
2072 if constexpr (std::endian::native != std::endian::big) {
2073 rune = flip_endian(rune);
2074 }
2075 if (auto writeRes = writer.write(rune); writeRes.is_error()) {
2076 return writeRes.error();
2077 }
2078 ++written;
2079 }
2080 return success(written);
2081 }
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 2043 of file byte_endian.hpp.

2044 {
2045 return utf32_to_utf32le(writer, endian_from_native_slice(str), writeBom);
2046 }
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 2008 of file byte_endian.hpp.

2009 {
2010 auto runeIter = utf32_rune_iterator(str);
2011 char32_t rune;
2012 size_t written = 0;
2013
2014 if (writeBom) {
2015 if (auto res = writer.write(endian_bom<std::endian::little, char32_t>); res.is_error()) {
2016 return res.error();
2017 }
2018 ++written;
2019 }
2020
2021 while (runeIter.next().copy_if_present(rune)) {
2022 if constexpr (std::endian::native != std::endian::little) {
2023 rune = flip_endian(rune);
2024 }
2025 if (auto writeRes = writer.write(rune); writeRes.is_error()) {
2026 return writeRes.error();
2027 }
2028 ++written;
2029 }
2030 return success(written);
2031 }
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 1252 of file byte_endian.hpp.

1253 {
1254 return utf32_to_utf8(writer, endian_from_native_slice(str));
1255 }
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.

1198 {
1199 char32_t cur;
1200 auto iter = utf32_rune_iterator(str);
1201 size_t written = 0;
1202 while (iter.next().copy_if_present(cur)) {
1203 auto seq = rune_to_utf8(cur);
1204 char8_t curCh;
1205 auto iter2 = seq.iter();
1206 while (iter2.next().copy_if_present(curCh)) {
1207 if (auto writeRes = writer.write(curCh); writeRes.is_error()) {
1208 return writeRes.error();
1209 }
1210 ++written;
1211 }
1212 }
1213 return success(written);
1214 }
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 1225 of file byte_endian.hpp.

1225 {
1226 char32_t cur;
1227 auto iter = utf32_rune_iterator(str);
1228 size_t written = 0;
1229 while (iter.next().copy_if_present(cur)) {
1230 auto seq = rune_to_utf8(cur);
1231 char8_t curCh;
1232 auto iter2 = seq.iter();
1233 while (iter2.next().copy_if_present(curCh)) {
1234 if (auto writeRes = writer.write(curCh); writeRes.is_error()) {
1235 return writeRes.error();
1236 }
1237 ++written;
1238 }
1239 }
1240 return success(written);
1241 }
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 2210 of file byte_endian.hpp.

2211 {
2212 auto runeIter = utf32_rune_iterator(str);
2213 char32_t rune;
2214 size_t written = 0;
2215
2216 if (writeBom) {
2217 if (auto res = writer.write(endian_bom<std::endian::native, char32_t>); res.is_error()) {
2218 return res.error();
2219 }
2220 ++written;
2221 }
2222
2223 while (runeIter.next().copy_if_present(rune)) {
2224 if (auto writeRes = writer.write(rune); writeRes.is_error()) {
2225 return writeRes.error();
2226 }
2227 ++written;
2228 }
2229 return success(written);
2230 }
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 2143 of file byte_endian.hpp.

2144 {
2145 auto runeIter = utf32_rune_iterator(str);
2146 char32_t rune;
2147 size_t written = 0;
2148
2149 if (writeBom) {
2150 if (auto res = writer.write(endian_bom<std::endian::little, char32_t>); res.is_error()) {
2151 return res.error();
2152 }
2153 ++written;
2154 }
2155
2156 while (runeIter.next().copy_if_present(rune)) {
2157 if constexpr (std::endian::native != std::endian::little) {
2158 rune = flip_endian(rune);
2159 }
2160 if (auto writeRes = writer.write(rune); writeRes.is_error()) {
2161 return writeRes.error();
2162 }
2163 ++written;
2164 }
2165 return success(written);
2166 }
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 2178 of file byte_endian.hpp.

2179 {
2180 auto runeIter = utf32_rune_iterator(str);
2181 char32_t rune;
2182 size_t written = 0;
2183
2184 if (writeBom) {
2185 if (auto res = writer.write(endian_bom<std::endian::native, char32_t>); res.is_error()) {
2186 return res.error();
2187 }
2188 ++written;
2189 }
2190
2191 while (runeIter.next().copy_if_present(rune)) {
2192 if (auto writeRes = writer.write(rune); writeRes.is_error()) {
2193 return writeRes.error();
2194 }
2195 ++written;
2196 }
2197 return success(written);
2198 }
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 2108 of file byte_endian.hpp.

2109 {
2110 auto runeIter = utf32_rune_iterator(str);
2111 char32_t rune;
2112 size_t written = 0;
2113
2114 if (writeBom) {
2115 if (auto res = writer.write(endian_bom<std::endian::big, char32_t>); res.is_error()) {
2116 return res.error();
2117 }
2118 ++written;
2119 }
2120
2121 while (runeIter.next().copy_if_present(rune)) {
2122 if constexpr (std::endian::native != std::endian::big) {
2123 rune = flip_endian(rune);
2124 }
2125 if (auto writeRes = writer.write(rune); writeRes.is_error()) {
2126 return writeRes.error();
2127 }
2128 ++written;
2129 }
2130 return success(written);
2131 }
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 1688 of file byte_endian.hpp.

1689 {
1690 auto runeIter = utf8_rune_iterator(str);
1691 char32_t rune;
1692 size_t written = 0;
1693 while (runeIter.next().copy_if_present(rune)) {
1694 auto seq = rune_to_str(rune);
1695 char curCh;
1696 auto charIter = seq.iter();
1697 while (charIter.next().copy_if_present(curCh)) {
1698 if (auto writeRes = writer.write(curCh); writeRes.is_error()) {
1699 return writeRes.error();
1700 }
1701 ++written;
1702 }
1703 }
1704 return success(written);
1705 }
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 1615 of file byte_endian.hpp.

1616 {
1617 auto runeIter = utf8_rune_iterator(str);
1618 char32_t rune;
1619 size_t written = 0;
1620
1621 if (writeBom) {
1622 if (auto res = writer.write(bom); res.is_error()) {
1623 return res.error();
1624 }
1625 ++written;
1626 }
1627
1628 while (runeIter.next().copy_if_present(rune)) {
1629 auto seq = rune_to_utf16(rune);
1630 char16_t curCh;
1631 auto charIter = seq.iter();
1632 while (charIter.next().copy_if_present(curCh)) {
1633 if (auto writeRes = writer.write(curCh); writeRes.is_error()) {
1634 return writeRes.error();
1635 }
1636 ++written;
1637 }
1638 }
1639 return success(written);
1640 }
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 1335 of file byte_endian.hpp.

1336 {
1337 auto runeIter = utf8_rune_iterator(str);
1338 char32_t rune;
1339 size_t written = 0;
1340
1341 if (writeBom) {
1342 if (auto res = writer.write(bom); res.is_error()) {
1343 return res.error();
1344 }
1345 ++written;
1346 }
1347
1348 while (runeIter.next().copy_if_present(rune)) {
1349 if (auto writeRes = writer.write(rune); writeRes.is_error()) {
1350 return writeRes.error();
1351 }
1352 ++written;
1353 }
1354 return success(written);
1355 }
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.