tdslite latest
C++ API reference
Loading...
Searching...
No Matches
tdsl::u16le_view Struct Reference

Non-owning view of a UTF-16LE string stored in a byte buffer, such as a string in a server response. More...

#include <tdslite/util/tdsl_u16le_view.hpp>

Classes

struct  const_iterator
 

Public Types

using value_type = char16_t
 
using size_type = tdsl::byte_view::size_type
 

Public Member Functions

constexpr u16le_view () noexcept=default
 
constexpr u16le_view (tdsl::byte_view bytes) noexcept
 
constexpr size_type size () const noexcept
 Number of UTF-16 code units.
 
constexpr size_type size_bytes () const noexcept
 
constexpr bool empty () const noexcept
 
constexpr char16_t operator[] (size_type index) const noexcept
 Code unit at index (must be less than size())
 
const_iterator begin () const noexcept
 
const_iterator end () const noexcept
 
constexpr tdsl::byte_view bytes () const noexcept
 The underlying UTF-16LE bytes.
 
size_type copy_to (char16_t *dst, size_type capacity) const noexcept
 Copy up to capacity code units to dst.
 
template<typename T >
bool equals (const T &other) const noexcept
 Compare with a char16_t string (e.g.
 

Detailed Description

Non-owning view of a UTF-16LE string stored in a byte buffer, such as a string in a server response.

Strings in a TDS message are not aligned to 2 bytes, so they can't be read through a const char16_t * (a misaligned load is undefined behavior, and faults on some CPUs). This view keeps the bytes as they are and builds each code unit from two bytes when it is read, which also gives the right value on big-endian hosts.

Iterating yields char16_t values:

for (char16_t ch : token.msgtext) { ... }

Use copy_to() to get the string into a char16_t array.

Member Typedef Documentation

◆ value_type

using tdsl::u16le_view::value_type = char16_t

◆ size_type

Constructor & Destructor Documentation

◆ u16le_view() [1/2]

constexpr tdsl::u16le_view::u16le_view ( )
inlineconstexprdefaultnoexcept

◆ u16le_view() [2/2]

constexpr tdsl::u16le_view::u16le_view ( tdsl::byte_view  bytes)
inlineexplicitconstexprnoexcept
Parameters
[in]bytesUTF-16LE encoded string. A trailing odd byte is ignored.

Member Function Documentation

◆ size()

constexpr size_type tdsl::u16le_view::size ( ) const
inlineconstexprnoexcept

Number of UTF-16 code units.

◆ size_bytes()

constexpr size_type tdsl::u16le_view::size_bytes ( ) const
inlineconstexprnoexcept

◆ empty()

constexpr bool tdsl::u16le_view::empty ( ) const
inlineconstexprnoexcept

◆ operator[]()

constexpr char16_t tdsl::u16le_view::operator[] ( size_type  index) const
inlineconstexprnoexcept

Code unit at index (must be less than size())

◆ begin()

const_iterator tdsl::u16le_view::begin ( ) const
inlinenoexcept

◆ end()

const_iterator tdsl::u16le_view::end ( ) const
inlinenoexcept

◆ bytes()

constexpr tdsl::byte_view tdsl::u16le_view::bytes ( ) const
inlineconstexprnoexcept

The underlying UTF-16LE bytes.

◆ copy_to()

size_type tdsl::u16le_view::copy_to ( char16_t *  dst,
size_type  capacity 
) const
inlinenoexcept

Copy up to capacity code units to dst.

Returns
Number of code units copied

◆ equals()

template<typename T >
bool tdsl::u16le_view::equals ( const T &  other) const
inlinenoexcept

Compare with a char16_t string (e.g.

u"text")


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