3#ifndef ICE_STRING_CONVERTER_H
4#define ICE_STRING_CONVERTER_H
7#include "LocalException.h"
27 virtual std::byte*
getMoreBytes(
size_t howMany, std::byte* firstUnused) = 0;
42 virtual std::byte*
toUTF8(
const charT* sourceStart,
const charT* sourceEnd,
UTF8Buffer& buf)
const = 0;
46 fromUTF8(
const std::byte* sourceStart,
const std::byte* sourceEnd, std::basic_string<charT>& target)
const = 0;
97 const std::wstring& str,
108 const std::string& str,
126#if defined(_WIN32) || defined(ICE_DOXYGEN)
149 [[nodiscard]]
const char*
ice_id() const noexcept final;
158 ICE_API std::vector<unsigned short> toUTF16(
const std::vector<std::uint8_t>&);
159 ICE_API std::vector<unsigned int> toUTF32(
const std::vector<std::uint8_t>&);
164 ICE_API std::vector<std::uint8_t> fromUTF32(
const std::vector<unsigned int>&);
virtual std::byte * toUTF8(const charT *sourceStart, const charT *sourceEnd, UTF8Buffer &buf) const =0
Returns a pointer to byte after the last written byte (which may be past the last byte returned by ge...
virtual void fromUTF8(const std::byte *sourceStart, const std::byte *sourceEnd, std::basic_string< charT > &target) const =0
Unmarshals a UTF-8 sequence into a basic_string.
A StringConverter converts narrow or wide-strings to and from UTF-8 byte sequences.
IllegalConversionException(const char *file, int line, std::string message)
Constructs an IllegalConversionException.
const char * ice_id() const noexcept final
Returns the type ID of this exception.
LocalException(const char *file, int line, std::string message)
Constructs a local exception.
virtual std::byte * getMoreBytes(size_t howMany, std::byte *firstUnused)=0
Obtains more bytes.
Provides bytes to toUTF8.
WstringConverterPtr createUnicodeWstringConverter()
Creates a WstringConverter that converts to and from UTF-16 or UTF-32 depending on sizeof(wchar_t).
void setProcessWstringConverter(const WstringConverterPtr &c)
Sets the per process wide string converter.
std::shared_ptr< StringConverter > StringConverterPtr
A shared pointer to a StringConverter.
std::string nativeToUTF8(std::string_view str, const StringConverterPtr &nc)
Converts the given string from the native narrow string encoding to UTF-8 using the given converter.
BasicStringConverter< char > StringConverter
A narrow string converter.
StringConverterPtr getProcessStringConverter()
Retrieves the per-process narrow string converter.
StringConverterPtr createWindowsStringConverter(unsigned int page)
Creates a StringConverter that converts to and from narrow chars in the given code page,...
std::wstring stringToWstring(const std::string &str, const StringConverterPtr &nc=nullptr, const WstringConverterPtr &wc=nullptr)
Converts the given narrow string to a wide string.
BasicStringConverter< wchar_t > WstringConverter
A wide string converter.
std::string UTF8ToNative(std::string_view str, const StringConverterPtr &nc)
Converts the given string from UTF-8 to the native narrow string encoding using the given converter.
void setProcessStringConverter(const StringConverterPtr &c)
Sets the per-process narrow string converter.
WstringConverterPtr getProcessWstringConverter()
Retrieves the per-process wide string converter.
std::shared_ptr< WstringConverter > WstringConverterPtr
A shared pointer to a WstringConverter.
std::string wstringToString(const std::wstring &str, const StringConverterPtr &nc=nullptr, const WstringConverterPtr &wc=nullptr)
Converts the given wide string to a narrow string.