Files
YYCCommonplace/src/yycc/encoding/stl.hpp
2025-08-12 16:15:00 +08:00

44 lines
1.2 KiB
C++

#pragma once
#include <string>
#include <string_view>
#include <expected>
namespace yycc::encoding::stl {
/// @brief Possible convertion error occurs in this module.
struct ConvError {};
/// @brief The result type of this module.
template<typename T>
using ConvResult = std::expected<T, ConvError>;
/**
* @brief UTF8 -> UTF16
* @param[in] src The string to be converted.
* @return The converted string, or error occurring.
*/
ConvResult<std::u16string> to_utf16(const std::u8string_view& src);
/**
* @brief UTF16 -> UTF8
* @param[in] src The string to be converted.
* @return The converted string, or error occurring.
*/
ConvResult<std::u8string> to_utf8(const std::u16string_view& src);
/**
* @brief UTF8 -> UTF32
* @param[in] src The string to be converted.
* @return The converted string, or error occurring.
*/
ConvResult<std::u32string> to_utf32(const std::u8string_view& src);
/**
* @brief UTF32 -> UTF8
* @param[in] src The string to be converted.
* @return The converted string, or error occurring.
*/
ConvResult<std::u8string> to_utf8(const std::u32string_view& src);
}