@@ -102,6 +102,49 @@ class Column
102102 */
103103 std::string getString () const ;
104104
105+ #ifdef __cpp_unicode_characters
106+ /* *
107+ * @brief Return a pointer to the text value (NULL terminated UTF-16 string) of the column.
108+ *
109+ * @warning The value pointed at is only valid while the statement is valid (ie. not finalized),
110+ * thus you must copy it before using it beyond its scope (to a std::u16string for instance).
111+ */
112+ const char16_t * getU16Text (const char16_t * apDefaultValue = u" " ) const noexcept ;
113+ /* *
114+ * @brief Return a std::u16string for a TEXT column.
115+ *
116+ * Note this correctly handles strings that contain null bytes.
117+ */
118+ std::u16string getU16String () const ;
119+ #if WCHAR_MAX == 0xffff
120+ /* *
121+ * @brief Return a pointer to the text value (NULL terminated UTF-16 string) of the column.
122+ *
123+ * @warning The value pointed at is only valid while the statement is valid (ie. not finalized),
124+ * thus you must copy it before using it beyond its scope (to a std::wstring for instance).
125+ */
126+ const wchar_t * getWText (const wchar_t * apDefaultValue = L" " ) const noexcept ;
127+ /* *
128+ * @brief Return a std::wstring for a TEXT column.
129+ */
130+ std::wstring getWString () const ;
131+ #endif // WCHAR_MAX == 0xffff
132+ #endif // __cpp_unicode_characters
133+ #ifdef __cpp_char8_t
134+ /* *
135+ * @brief Return a pointer to the text value (NULL terminated UTF-8 string) of the column.
136+ *
137+ * @warning The value pointed at is only valid while the statement is valid (ie. not finalized),
138+ * thus you must copy it before using it beyond its scope (to a std::u8string for instance).
139+ */
140+ const char8_t * getU8Text (const char8_t * apDefaultValue = u8" " ) const noexcept ;
141+ /* *
142+ * @brief Return a std::u8string for a TEXT or BLOB column.
143+ *
144+ * Note this correctly handles strings that contain null bytes.
145+ */
146+ std::u8string getU8String () const ;
147+ #endif // __cpp_char8_t
105148 /* *
106149 * @brief Return the type of the value of the column using sqlite3_column_type()
107150 *
@@ -142,7 +185,10 @@ class Column
142185 }
143186
144187 /* *
145- * @brief Return the number of bytes used by the text (or blob) value of the column
188+ * @brief Return the number of bytes used by the UTF-8 text (or blob) value of the column
189+ *
190+ * Can cause conversion to text and between UTF-8/UTF-16 encodings
191+ * Be careful when using with getBytes16() and UTF-16 functions
146192 *
147193 * Return either :
148194 * - size in bytes (not in characters) of the string returned by getText() without the '\0' terminator
@@ -152,6 +198,19 @@ class Column
152198 */
153199 int getBytes () const noexcept ;
154200
201+ /* *
202+ * @brief Return the number of bytes used by the UTF-16 text value of the column
203+ *
204+ * Can cause conversion to text and between UTF-8/UTF-16 encodings
205+ * Be careful when using with getBytes() and UTF-8 functions
206+ *
207+ * Return either :
208+ * - size in bytes (not in characters) of the string returned by getText() without the '\0' terminator
209+ * - size in bytes of the string representation of the numerical value (integer or double)
210+ * - 0 for a NULL value
211+ */
212+ int getBytes16 () const noexcept ;
213+
155214 // / Alias returning the number of bytes used by the text (or blob) value of the column
156215 int size () const noexcept
157216 {
@@ -226,6 +285,73 @@ class Column
226285 return getString ();
227286 }
228287
288+ #ifdef __cpp_unicode_characters
289+ /* *
290+ * @brief Inline cast operator to char16_t*
291+ *
292+ * @see getU16String
293+ */
294+ operator const char16_t * () const
295+ {
296+ return getU16Text ();
297+ }
298+ /* *
299+ * @brief Inline cast operator to std::u16string
300+ *
301+ * Handles UTF-16 TEXT
302+ *
303+ * @see getU16String
304+ */
305+ operator std::u16string () const
306+ {
307+ return getU16String ();
308+ }
309+ #if WCHAR_MAX == 0xffff
310+ /* *
311+ * @brief Inline cast operator to wchar_t*
312+ *
313+ * @see getWText
314+ */
315+ operator const wchar_t * () const
316+ {
317+ return getWText ();
318+ }
319+ /* *
320+ * @brief Inline cast operator to std::wstring
321+ *
322+ * Handles UTF-16 TEXT
323+ *
324+ * @see getWString
325+ */
326+ operator std::wstring () const
327+ {
328+ return getWString ();
329+ }
330+ #endif // WCHAR_MAX == 0xffff
331+ #endif // __cpp_unicode_characters
332+ #ifdef __cpp_char8_t
333+ /* *
334+ * @brief Inline cast operator to char8_t*
335+ *
336+ * @see getU8Text
337+ */
338+ operator const char8_t * () const
339+ {
340+ return getU8Text ();
341+ }
342+ /* *
343+ * @brief Inline cast operator to std::u8string
344+ *
345+ * Handles BLOB or TEXT, which may contain null bytes within
346+ *
347+ * @see getU8String
348+ */
349+ operator std::u8string () const
350+ {
351+ return getU8String ();
352+ }
353+ #endif // __cpp_char8_t
354+
229355private:
230356 Statement::TStatementPtr mStmtPtr ; // /< Shared Pointer to the prepared SQLite Statement Object
231357 int mIndex ; // /< Index of the column in the row of result, starting at 0
0 commit comments