5#include "../SqlColumnTypeDefinitions.hpp"
8#include "UnicodeConverter.hpp"
14constexpr size_t SqlMaxColumnSize = (std::numeric_limits<uint32_t>::max)();
21template <std::
size_t N,
typename T =
char>
25 static constexpr std::size_t DynamicCapacity = N;
27 using string_type = std::basic_string<T>;
30 template <std::
size_t SourceSize>
32 _value { text, SourceSize - 1 }
34 static_assert(SourceSize <= N + 1,
"RHS string size must not exceed target string's capacity.");
51 LIGHTWEIGHT_FORCE_INLINE constexpr
SqlDynamicString(std::basic_string_view<T> s) noexcept:
57 LIGHTWEIGHT_FORCE_INLINE
constexpr SqlDynamicString(std::basic_string<T>
const& s)
noexcept:
63 [[nodiscard]] LIGHTWEIGHT_FORCE_INLINE
constexpr std::basic_string_view<T>
str() const noexcept
65 return std::basic_string_view<T> {
data(),
size() };
69 [[nodiscard]] LIGHTWEIGHT_FORCE_INLINE string_type
const&
value() const noexcept
75 [[nodiscard]] LIGHTWEIGHT_FORCE_INLINE string_type&
value() noexcept
81 [[nodiscard]] LIGHTWEIGHT_FORCE_INLINE T
const*
data() const noexcept
87 [[nodiscard]] LIGHTWEIGHT_FORCE_INLINE T*
data() noexcept
93 [[nodiscard]] LIGHTWEIGHT_FORCE_INLINE T
const*
c_str() const noexcept
95 return _value.c_str();
99 [[nodiscard]] LIGHTWEIGHT_FORCE_INLINE std::size_t
capacity() const noexcept
105 [[nodiscard]] LIGHTWEIGHT_FORCE_INLINE std::size_t
size() const noexcept
107 return _value.size();
111 [[nodiscard]] LIGHTWEIGHT_FORCE_INLINE
constexpr bool empty() const noexcept
113 return _value.empty();
117 LIGHTWEIGHT_FORCE_INLINE
constexpr void clear() noexcept
123 LIGHTWEIGHT_FORCE_INLINE
constexpr void resize(std::size_t n)
noexcept
129 [[nodiscard]] LIGHTWEIGHT_FORCE_INLINE
constexpr std::basic_string_view<T>
ToStringView() const noexcept
131 return { _value.data(), _value.size() };
134 [[nodiscard]] LIGHTWEIGHT_FORCE_INLINE
constexpr T& operator[](std::size_t index)
noexcept
136 return _value[index];
139 [[nodiscard]] LIGHTWEIGHT_FORCE_INLINE
constexpr T
const& operator[](std::size_t index)
const noexcept
141 return _value[index];
144 [[nodiscard]] LIGHTWEIGHT_FORCE_INLINE
constexpr explicit operator std::basic_string_view<T>() const noexcept
149 template <std::
size_t OtherSize>
152 return _value <=> other._value;
155 template <std::
size_t OtherSize>
158 return (*this <=> other) == std::weak_ordering::equivalent;
161 template <std::
size_t OtherSize>
164 return !(*
this == other);
167 LIGHTWEIGHT_FORCE_INLINE
constexpr bool operator==(std::basic_string_view<T> other)
const noexcept
169 return (
ToStringView() <=> other) == std::weak_ordering::equivalent;
172 LIGHTWEIGHT_FORCE_INLINE
constexpr bool operator!=(std::basic_string_view<T> other)
const noexcept
174 return !(*
this == other);
181template <std::
size_t N,
typename CharT>
186 return { str.
data(), str.size() };
194struct IsSqlDynamicStringImpl: std::false_type
198template <std::
size_t N,
typename T>
203template <std::
size_t N,
typename T>
204struct IsSqlDynamicStringImpl<std::optional<SqlDynamicString<N, T>>>: std::true_type
211constexpr bool IsSqlDynamicString = detail::IsSqlDynamicStringImpl<T>::value;
216template <std::
size_t N>
222template <std::
size_t N>
228template <std::
size_t N>
234template <std::
size_t N>
237template <std::
size_t N,
typename T>
242 auto format(value_type
const& text, format_context& ctx)
const
244 if constexpr (detail::OneOf<T, wchar_t, char32_t, char16_t>)
245 return std::formatter<std::string>::format((
char const*)
ToUtf8(text.ToStringView()).c_str(), ctx);
247 return std::formatter<std::string>::format((
char const*) text.data(), ctx);
251template <std::
size_t N,
typename T>
257 static constexpr SqlColumnTypeDefinition ColumnType = []()
constexpr {
258 if constexpr (std::same_as<CharType, char>)
259 return SqlColumnTypeDefinitions::Varchar { N };
261 return SqlColumnTypeDefinitions::NVarchar { N };
264 static CharType
const* Data(ValueType
const* str)
noexcept
269 static CharType* Data(ValueType* str)
noexcept
274 static SQLULEN Size(ValueType
const* str)
noexcept
279 static void Clear(ValueType* str)
noexcept
281 str->value().clear();
284 static void Reserve(ValueType* str,
size_t capacity)
noexcept
286 str->value().resize((std::min)(N, capacity));
289 static void Resize(ValueType* str, SQLLEN indicator)
noexcept
291 str->value().resize(indicator);
LIGHTWEIGHT_FORCE_INLINE std::size_t capacity() const noexcept
Retrieves the string's capacity.
LIGHTWEIGHT_FORCE_INLINE T * data() noexcept
Retrieves the string's inner value (as T*).
LIGHTWEIGHT_FORCE_INLINE string_type & value() noexcept
Retrieves the string's inner value (std::basic_string<T>).
LIGHTWEIGHT_FORCE_INLINE T const * data() const noexcept
Retrieves the string's inner value (as T const*).
LIGHTWEIGHT_FORCE_INLINE string_type const & value() const noexcept
Retrieves the string's inner value (std::basic_string<T>).
LIGHTWEIGHT_FORCE_INLINE constexpr void resize(std::size_t n) noexcept
Resizes the string.
LIGHTWEIGHT_FORCE_INLINE constexpr SqlDynamicString(T const *s, T const *e) noexcept
Constructs a fixed-size string from a string pointer and end pointer.
LIGHTWEIGHT_FORCE_INLINE constexpr void clear() noexcept
Clears the string.
LIGHTWEIGHT_FORCE_INLINE constexpr std::basic_string_view< T > str() const noexcept
Returns a string view of the string.
LIGHTWEIGHT_FORCE_INLINE std::size_t size() const noexcept
Retrieves the string's size.
LIGHTWEIGHT_FORCE_INLINE constexpr std::basic_string_view< T > ToStringView() const noexcept
Retrieves a string view of the string.
LIGHTWEIGHT_FORCE_INLINE T const * c_str() const noexcept
Retrieves the string's inner value (as T const*).
constexpr LIGHTWEIGHT_FORCE_INLINE SqlDynamicString(T const (&text)[SourceSize])
Constructs a fixed-size string from a string literal.
LIGHTWEIGHT_FORCE_INLINE constexpr bool empty() const noexcept
Tests if the string is empty.
LIGHTWEIGHT_FORCE_INLINE constexpr SqlDynamicString(std::basic_string< T > const &s) noexcept
Constructs a fixed-size string from a string.
LIGHTWEIGHT_API std::u8string ToUtf8(std::u32string_view u32InputString)