Ookii.CommandLine for C++  2.0.0
Static Public Member Functions | List of all members
ookii::string_convert< CharType, Traits, Alloc > Struct Template Reference

Performs a simple conversion of a narrow character string to a specified character type. More...

#include <ookii/string_helper.h>

Static Public Member Functions

static std::basic_string< CharType, Traits, Alloc > from_bytes (std::string_view value, const std::locale &loc={})
 Converts a string to the specified character type. More...
 

Detailed Description

template<typename CharType, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
struct ookii::string_convert< CharType, Traits, Alloc >

Performs a simple conversion of a narrow character string to a specified character type.

Warning
This method is marginally safer than literal_cast, because it uses the specified locale for the conversion. However, it still works on a per-character basis and will not work correctly on strings containing multi-byte characters.
Template Parameters
CharTypeThe character type used.
TraitsThe character traits to use. Defaults to std::char_traits<CharType>.
AllocThe allocator to use. Defaults to std::allocator<CharType>.

Member Function Documentation

◆ from_bytes()

template<typename CharType , typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
static std::basic_string<CharType, Traits, Alloc> ookii::string_convert< CharType, Traits, Alloc >::from_bytes ( std::string_view  value,
const std::locale &  loc = {} 
)
inlinestatic

Converts a string to the specified character type.

Parameters
valueThe string to convert.
locThe locale to use to widen the characters.
Returns
The converted string.

The documentation for this struct was generated from the following file: