📄 char_conversions.hpp
字号:
class encoding2encoding
{
public:
encoding2encoding(C const* s)
: m_s(s)
{}
encoding2encoding(C *s)
: m_s(s)
{}
template <ss_typename_param_k S>
encoding2encoding(S const& s)
: m_s(s.c_str())
{}
public:
C const* c_str() const
{
return m_s;
}
operator C const* () const
{
return m_s;
}
private:
C const* m_s;
};
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/* ////////////////////////////////////////////////////////////////////// */
/** \brief Type that converts a multibyte string to a wide string.
*
* \ingroup group__library__conversion
*/
typedef multibyte2wide<256> a2w;
/** \brief Type that converts a wide string to a multibyte string.
*
* \ingroup group__library__conversion
*/
typedef wide2multibyte<256> w2a;
#if defined(UNICODE)
typedef encoding2encoding<ws_char_w_t> t2w;
typedef encoding2encoding<ws_char_w_t> w2t;
typedef w2a t2a;
typedef a2w a2t;
#else /* ? UNICODE */
typedef encoding2encoding<ws_char_a_t> t2a;
typedef encoding2encoding<ws_char_a_t> a2t;
typedef a2w t2w;
typedef w2a w2t;
#endif /* UNICODE */
/* /////////////////////////////////////////////////////////////////////////
* Shims
*/
/** \brief \ref group__concept__shim__string_access__c_str_ptr_null for winstl::multibyte2wide
*
* \ingroup group__concept__shim__string_access
*/
template< ws_size_t CCH
>
inline ws_char_w_t const* c_str_ptr_null(winstl_ns_qual(multibyte2wide)<CCH> const& b)
{
return stlsoft_ns_qual(c_str_ptr_null)(b.c_str());
}
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
template< ws_size_t CCH
>
inline ws_char_w_t const* c_str_ptr_null_w(winstl_ns_qual(multibyte2wide)<CCH> const& b)
{
return stlsoft_ns_qual(c_str_ptr_null)(b.c_str());
}
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/** \brief \ref group__concept__shim__string_access__c_str_ptr for winstl::multibyte2wide
*
* \ingroup group__concept__shim__string_access
*/
template< ws_size_t CCH
>
inline ws_char_w_t const* c_str_ptr(winstl_ns_qual(multibyte2wide)<CCH> const& b)
{
return b.c_str();
}
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
template< ws_size_t CCH
>
inline ws_char_w_t const* c_str_ptr_w(winstl_ns_qual(multibyte2wide)<CCH> const& b)
{
return b.c_str();
}
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/** \brief \ref group__concept__shim__string_access__c_str_data for winstl::multibyte2wide
*
* \ingroup group__concept__shim__string_access
*/
template< ws_size_t CCH
>
inline ws_char_w_t const* c_str_data(winstl_ns_qual(multibyte2wide)<CCH> const& b)
{
return b.c_str();
}
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
template< ws_size_t CCH
>
inline ws_char_w_t const* c_str_data_w(winstl_ns_qual(multibyte2wide)<CCH> const& b)
{
return b.c_str();
}
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/** \brief \ref group__concept__shim__string_access__c_str_len for winstl::multibyte2wide
*
* \ingroup group__concept__shim__string_access
*/
template< ws_size_t CCH
>
inline ws_size_t c_str_len(winstl_ns_qual(multibyte2wide)<CCH> const& b)
{
return stlsoft_ns_qual(c_str_len)(b.c_str());
}
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
template< ws_size_t CCH
>
inline ws_size_t c_str_len_w(winstl_ns_qual(multibyte2wide)<CCH> const& b)
{
return stlsoft_ns_qual(c_str_len_w)(b.c_str());
}
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/** \brief \ref group__concept__shim__string_access__c_str_ptr_null for winstl::wide2multibyte
*
* \ingroup group__concept__shim__string_access
*/
template< ws_size_t CCH
>
inline ws_char_a_t const* c_str_ptr_null(winstl_ns_qual(wide2multibyte)<CCH> const& b)
{
return stlsoft_ns_qual(c_str_ptr_null)(b.c_str());
}
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
template< ws_size_t CCH
>
inline ws_char_a_t const* c_str_ptr_null_a(winstl_ns_qual(wide2multibyte)<CCH> const& b)
{
return stlsoft_ns_qual(c_str_ptr_null)(b.c_str());
}
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/** \brief \ref group__concept__shim__string_access__c_str_ptr for winstl::wide2multibyte
*
* \ingroup group__concept__shim__string_access
*/
template< ws_size_t CCH
>
inline ws_char_a_t const* c_str_ptr(winstl_ns_qual(wide2multibyte)<CCH> const& b)
{
return b.c_str();
}
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
template< ws_size_t CCH
>
inline ws_char_a_t const* c_str_ptr_a(winstl_ns_qual(wide2multibyte)<CCH> const& b)
{
return b.c_str();
}
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/** \brief \ref group__concept__shim__string_access__c_str_data for winstl::wide2multibyte
*
* \ingroup group__concept__shim__string_access
*/
template< ws_size_t CCH
>
inline ws_char_a_t const* c_str_data(winstl_ns_qual(wide2multibyte)<CCH> const& b)
{
return b.c_str();
}
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
template< ws_size_t CCH
>
inline ws_char_a_t const* c_str_data_a(winstl_ns_qual(wide2multibyte)<CCH> const& b)
{
return b.c_str();
}
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/** \brief \ref group__concept__shim__string_access__c_str_len for winstl::wide2multibyte
*
* \ingroup group__concept__shim__string_access
*/
template< ws_size_t CCH
>
inline ws_size_t c_str_len(winstl_ns_qual(wide2multibyte)<CCH> const& b)
{
return stlsoft_ns_qual(c_str_len)(b.c_str());
}
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
template< ws_size_t CCH
>
inline ws_size_t c_str_len_a(winstl_ns_qual(wide2multibyte)<CCH> const& b)
{
return stlsoft_ns_qual(c_str_len_a)(b.c_str());
}
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/** \brief \ref group__concept__shim__stream_insertion "stream insertion shim" for winstl::multibyte2wide
*
* \ingroup group__concept__shim__stream_insertion
*/
template< ss_typename_param_k S
, ws_size_t CCH
>
inline S& operator <<(S& s, winstl_ns_qual(multibyte2wide)<CCH> const& b)
{
s << b.c_str();
return s;
}
/** \brief \ref group__concept__shim__stream_insertion "stream insertion shim" for winstl::wide2multibyte
*
* \ingroup group__concept__shim__stream_insertion
*/
template< ss_typename_param_k S
, ws_size_t CCH
>
inline S& operator <<(S& s, winstl_ns_qual(wide2multibyte)<CCH> const& b)
{
s << b.c_str();
return s;
}
////////////////////////////////////////////////////////////////////////////
// Unit-testing
#ifdef STLSOFT_UNITTEST
# include "./unittest/char_conversions_unittest_.h"
#endif /* STLSOFT_UNITTEST */
/* ////////////////////////////////////////////////////////////////////// */
#ifndef _WINSTL_NO_NAMESPACE
# if defined(_STLSOFT_NO_NAMESPACE) || \
defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
} // namespace winstl
# else
} // namespace winstl_project
} // namespace stlsoft
# endif /* _STLSOFT_NO_NAMESPACE */
#endif /* !_WINSTL_NO_NAMESPACE */
/* /////////////////////////////////////////////////////////////////////////
* Namespace
*
* The string access shims exist either in the stlsoft namespace, or in the
* global namespace. This is required by the lookup rules.
*
*/
#ifndef _WINSTL_NO_NAMESPACE
# if !defined(_STLSOFT_NO_NAMESPACE) && \
!defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
namespace stlsoft
{
# else /* ? _STLSOFT_NO_NAMESPACE */
/* There is no stlsoft namespace, so must define in the global namespace */
# endif /* !_STLSOFT_NO_NAMESPACE */
using ::winstl::c_str_data;
using ::winstl::c_str_data_a;
using ::winstl::c_str_data_w;
using ::winstl::c_str_len;
using ::winstl::c_str_len_a;
using ::winstl::c_str_len_w;
using ::winstl::c_str_ptr;
using ::winstl::c_str_ptr_a;
using ::winstl::c_str_ptr_w;
using ::winstl::c_str_ptr_null;
using ::winstl::c_str_ptr_null_a;
using ::winstl::c_str_ptr_null_w;
# if !defined(_STLSOFT_NO_NAMESPACE) && \
!defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
} // namespace stlsoft
# else /* ? _STLSOFT_NO_NAMESPACE */
/* There is no stlsoft namespace, so must define in the global namespace */
# endif /* !_STLSOFT_NO_NAMESPACE */
#endif /* !_WINSTL_NO_NAMESPACE */
/* /////////////////////////////////////////////////////////////////////////
* Global namespace shims
*/
/* This defines stream inserter shim function templates for the converters
* for use with the Visual C++ <7.1 standard library.
*/
#if defined(STLSOFT_CF_STD_LIBRARY_IS_DINKUMWARE_VC) && \
STLSOFT_CF_STD_LIBRARY_DINKUMWARE_VC_VERSION < STLSOFT_CF_DINKUMWARE_VC_VERSION_7_1
# include <iosfwd>
template <winstl_ns_qual(ws_size_t) CCH>
inline winstl_ns_qual_std(basic_ostream)<char>& operator <<(winstl_ns_qual_std(basic_ostream)<char> &stm, winstl_ns_qual(wide2multibyte)<CCH> const& b)
{
return stm << b.c_str();
}
template <winstl_ns_qual(ws_size_t) CCH>
inline winstl_ns_qual_std(basic_ostream)<wchar_t>& operator <<(winstl_ns_qual_std(basic_ostream)<wchar_t> &stm, winstl_ns_qual(multibyte2wide)<CCH> const& b)
{
return stm << b.c_str();
}
#endif /* library */
/* ////////////////////////////////////////////////////////////////////// */
#endif /* WINSTL_INCL_WINSTL_CONVERSION_HPP_CHAR_CONVERSIONS */
/* ////////////////////////////////////////////////////////////////////// */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -