CommonLib
Loading...
Searching...
No Matches
hedgedev::csl::ut::encoding Namespace Reference

Enumerations

enum  encoding_type {
  unknown = 0 << 0 , utf8 = 1 << 0 , utf16_le = 1 << 1 , utf16_be = 1 << 2 ,
  utf32_le = 1 << 3 , utf32_be = 1 << 4 , latin1 = 1 << 5
}

Functions

template<expr::basic_string T_result, expr::any_string T_str>
T_result convert (const T_str &in_str, encoding_type in_dst_encoding=expr::get_char_encoding_type< T_result >(), encoding_type in_src_encoding=expr::get_char_encoding_type< T_str >())
template<encoding_type dst_encoding, expr::any_string T_str, expr::any_string T_result = expr::encoded_string_t<dst_encoding>>
T_result convert (const T_str &in_str)
std::vector< uint8_t > get_bom (encoding_type in_encoding)
constexpr size_t get_bom_length (encoding_type in_encoding)
template<encoding_type encoding>
constexpr size_t get_bom_length ()
template<expr::any_string... T_args, typename T_result = expr::pi_string_t<T_args...>>
std::array< T_result, sizeof...(T_args)> precedent_convert (const T_args &... in_args)
template<expr::basic_string T_result, expr::any_string T_str>
bool try_convert (const T_str &in_str, T_result &out_result, encoding_type in_dst_encoding=expr::get_char_encoding_type< T_result >(), encoding_type in_src_encoding=expr::get_char_encoding_type< T_str >())
template<encoding_type dst_encoding, expr::any_string T_str, expr::any_string T_result = expr::encoded_string_t<dst_encoding>>
bool try_convert (const T_str &in_str, T_result &out_result)

Enumeration Type Documentation

◆ encoding_type

Enumerator
unknown 0 << 0 
utf8 1 << 0 
utf16_le 1 << 1 
utf16_be 1 << 2 
utf32_le 1 << 3 
utf32_be 1 << 4 
latin1 1 << 5 

Function Documentation

◆ convert() [1/2]

template<encoding_type dst_encoding, expr::any_string T_str, expr::any_string T_result = expr::encoded_string_t<dst_encoding>>
T_result hedgedev::csl::ut::encoding::convert ( const T_str & in_str)
inline

Converts a string to a different encoding format.

Template Parameters
dst_encodingThe encoding to convert to.
T_strThe string type to convert from.
T_resultThe string type to convert to, inferred from the encoding type.
Parameters
in_strThe string to convert.
Returns
If successful, the input string in the destination format. Otherwise, an empty string in the destination format.

◆ convert() [2/2]

template<expr::basic_string T_result, expr::any_string T_str>
T_result hedgedev::csl::ut::encoding::convert ( const T_str & in_str,
encoding_type in_dst_encoding = expr::get_char_encoding_type<T_result>(),
encoding_type in_src_encoding = expr::get_char_encoding_type<T_str>() )
inline

Converts a string to a different encoding format.

Template Parameters
T_resultThe string type to convert to.
T_strThe string type to convert from.
Parameters
in_strThe string to convert.
in_src_encodingThe encoding to convert from, inferred from the input string type.
in_dst_encodingThe encoding to convert to, inferred from the return type.
Returns
If successful, the input string in the destination format. Otherwise, an empty string in the destination format.

◆ get_bom()

std::vector< uint8_t > hedgedev::csl::ut::encoding::get_bom ( encoding_type in_encoding)
inline

Gets the byte order mark of an encoding type.

Parameters
in_encodingThe encoding type.
Returns
An vector of bytes containing the byte order mark for the specified encoding.

◆ get_bom_length() [1/2]

template<encoding_type encoding>
size_t hedgedev::csl::ut::encoding::get_bom_length ( )
inlineconstexpr

Gets the length of the byte order mark of an encoding type.

Template Parameters
encodingThe encoding type.
Returns
The length of the byte order mark.

◆ get_bom_length() [2/2]

size_t hedgedev::csl::ut::encoding::get_bom_length ( encoding_type in_encoding)
inlineconstexpr

Gets the length of the byte order mark of an encoding type.

Parameters
in_encodingThe encoding type.
Returns
The length of the byte order mark.

◆ precedent_convert()

template<expr::any_string... T_args, typename T_result = expr::pi_string_t<T_args...>>
std::array< T_result, sizeof...(T_args)> hedgedev::csl::ut::encoding::precedent_convert ( const T_args &... in_args)
inline

Converts multiple strings to share the same encoding format.

Template Parameters
T_argsThe string types.
T_resultThe string type to convert to inferred from the string with the largest character size.
Parameters
in_argsThe strings to convert.
Returns
An array of strings in the same destination format. If a string failed to convert, an empty string will be put in its place.

◆ try_convert() [1/2]

template<encoding_type dst_encoding, expr::any_string T_str, expr::any_string T_result = expr::encoded_string_t<dst_encoding>>
bool hedgedev::csl::ut::encoding::try_convert ( const T_str & in_str,
T_result & out_result )
inline

Tries to convert a string to a different encoding format.

Template Parameters
dst_encodingThe encoding to convert to.
T_strThe string type to convert from.
T_resultThe string type to convert to, inferred from the encoding type.
Parameters
in_strThe string to convert.
out_resultThe output string to set.
Returns
true if the conversion was successful. Otherwise, false.

◆ try_convert() [2/2]

template<expr::basic_string T_result, expr::any_string T_str>
bool hedgedev::csl::ut::encoding::try_convert ( const T_str & in_str,
T_result & out_result,
encoding_type in_dst_encoding = expr::get_char_encoding_type<T_result>(),
encoding_type in_src_encoding = expr::get_char_encoding_type<T_str>() )
inline

Tries to convert a string to a different encoding format.

Template Parameters
T_resultThe string type to convert to.
T_strThe string type to convert from.
Parameters
in_strThe string to convert.
out_resultThe output string to set.
in_src_encodingThe encoding to convert from, inferred from the input string type.
in_dst_encodingThe encoding to convert to, inferred from the return type.
Returns
true if the conversion was successful. Otherwise, false.