⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 string_access.hpp

📁 用STL的方式封装了WindowsAPI、COM调用、ACE、ATL、MFC、WTL等多种组件
💻 HPP
📖 第 1 页 / 共 3 页
字号:
/// \brief Returns the length (in characters) of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_len_a(ss_char_a_t const *s)
{
#if !defined(STLSOFT_CF_STRING_ACCESS_USE_std_char_traits)
    return (s == 0) ? 0 : stlsoft_char_traits<ss_char_a_t>::length(s);
#else /* ? STLSOFT_CF_STRING_ACCESS_USE_std_char_traits */
    return (s == 0) ? 0 : stlsoft_ns_qual_std(char_traits)<ss_char_a_t>::length(s);
#endif /* !STLSOFT_CF_std_char_traits_AVAILABLE */
}

/// \brief Returns the length (in characters) of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_len(ss_char_a_t const *s)
{
    return c_str_len_a(s);
}

/* C-style Unicode string */
/// \brief Returns the length (in characters) of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_len_w(ss_char_w_t const *s)
{
#if defined(STLSOFT_COMPILER_IS_GCC)
    return (s == 0) ? 0 : wcslen(s);
#elif !defined(STLSOFT_CF_STRING_ACCESS_USE_std_char_traits)
    return (s == 0) ? 0 : stlsoft_char_traits<ss_char_w_t>::length(s);
#else /* ? STLSOFT_CF_STRING_ACCESS_USE_std_char_traits */
    return (s == 0) ? 0 : stlsoft_ns_qual_std(char_traits)<ss_char_w_t>::length(s);
#endif /* !STLSOFT_CF_STRING_ACCESS_USE_std_char_traits */
}

/// \brief Returns the length (in characters) of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_len(ss_char_w_t const *s)
{
    return c_str_len_w(s);
}

/* C-style ANSI string */
#ifdef _STLSOFT_STRING_ACCESS_ALLOW_NON_CONST
/// \brief Returns the length (in characters) of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_len_a(ss_char_a_t *s)
{
    return c_str_len_a(static_cast<ss_char_a_t const *>(s));
}

/// \brief Returns the length (in characters) of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_len(ss_char_a_t *s)
{
    return c_str_len_a(s);
}

/* C-style Unicode string */
/// \brief Returns the length (in characters) of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_len_w(ss_char_w_t *s)
{
    return c_str_len_w(static_cast<ss_char_w_t const *>(s));
}

/// \brief Returns the length (in characters) of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_len(ss_char_w_t *s)
{
    return c_str_len_w(s);
}
#endif /* _STLSOFT_STRING_ACCESS_ALLOW_NON_CONST */

/* std::basic_string */
#ifndef STLSOFT_STRING_ACCESS_NO_STD_STRING
# if defined(STLSOFT_COMPILER_IS_MSVC) && \
     _MSC_VER < 1100
/// \brief Returns the length (in characters) of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_len_a(string const &s)
{
    return s.length();
}

/// \brief Returns the length (in characters) of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_len(string const &s)
{
    return c_str_len_a(s);
}

/// \brief Returns the length (in characters) of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_len_w(wstring const &s)
{
    return s.length();
}

/// \brief Returns the length (in characters) of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_len(wstring const &s)
{
    return c_str_len_w(s);
}
# else /* ? compiler */
/// \brief Returns the length (in characters) of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_len_a(stlsoft_ns_qual_std(string) const &s)
{
    return s.length();
}

#  if !defined(STLSOFT_COMPILER_IS_GCC) || \
      !(__GNUC__ < 3)
/// \brief Returns the length (in characters) of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_len_w(_stlsoft_wstring_t const &s)
{
    return s.length();
}
#  endif /* compiler */

/// \brief Returns the length (in characters) of \c s, <b><i>not</i></b> including the null-terminating character
template<   ss_typename_param_k C
        ,   ss_typename_param_k T
        ,   ss_typename_param_k A
        >
inline ss_size_t c_str_len(stlsoft_ns_qual_std(basic_string)<C, T, A> const &s)
{
    return s.length();
}
# endif /* STLSOFT_COMPILER_IS_MSVC && _MSC_VER < 1100 */
#endif /* STLSOFT_STRING_ACCESS_NO_STD_STRING */

/* stlport::basic_string */
#if defined(_STLP_USE_NAMESPACES) && \
    defined(_STLP_USE_OWN_NAMESPACE) && \
    !defined(_STLP_REDEFINE_STD) && \
    (   !defined(_STLPORT_MAJOR) || \
        _STLPORT_MAJOR < 5)
/// \brief Returns the length (in characters) of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_len_a(stlport::string const &s)
{
    return s.length();
}

/// \brief Returns the length (in characters) of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_len_w(stlport::wstring const &s)
{
    return s.length();
}

/// \brief Returns the length (in characters) of \c s, <b><i>not</i></b> including the null-terminating character
template <ss_typename_param_k C>
inline ss_size_t c_str_len(stlport::basic_string<C> const &s)
{
    return s.length();
}
#endif /* _STLP_USE_NAMESPACES && _STLP_USE_OWN_NAMESPACE */

/* /////////////////////////////////////////////////////////////////////////
 * c_str_size
 *
 * This can be applied to an expression, and the return value is the number of
 * bytes required to store the character string in the expression, NOT including
 * the null-terminating character.
 */

/* C-style ANSI string */
/// \brief Returns the size (in bytes) of the contents of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_size_a(ss_char_a_t const *s)
{
    return c_str_len(s) * sizeof(ss_char_a_t);
}

/// \brief Returns the size (in bytes) of the contents of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_size(ss_char_a_t const *s)
{
    return c_str_size_a(s);
}

/* C-style Unicode string */
/// \brief Returns the size (in bytes) of the contents of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_size_w(ss_char_w_t const *s)
{
    return c_str_len(s) * sizeof(ss_char_w_t);
}

/// \brief Returns the size (in bytes) of the contents of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_size(ss_char_w_t const *s)
{
    return c_str_size_w(s);
}

/* C-style ANSI string */
#ifdef _STLSOFT_STRING_ACCESS_ALLOW_NON_CONST
/// \brief Returns the size (in bytes) of the contents of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_size_a(ss_char_a_t *s)
{
    return c_str_len(s) * sizeof(ss_char_a_t);
}

/// \brief Returns the size (in bytes) of the contents of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_size(ss_char_a_t *s)
{
    return c_str_size_a(s);
}

/* C-style Unicode string */
/// \brief Returns the size (in bytes) of the contents of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_size_w(ss_char_w_t *s)
{
    return c_str_len(s) * sizeof(ss_char_w_t);
}

/// \brief Returns the size (in bytes) of the contents of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_size(ss_char_w_t *s)
{
    return c_str_size_w(s);
}
#endif /* _STLSOFT_STRING_ACCESS_ALLOW_NON_CONST */

#if 0
/* std::basic_string */
#ifndef STLSOFT_STRING_ACCESS_NO_STD_STRING
# if defined(STLSOFT_COMPILER_IS_MSVC) && \
     _MSC_VER < 1100
/// \brief Returns the size (in bytes) of the contents of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_size_a(string const &s)
{
    return c_str_len(s) * sizeof(string::value_type);
}

/// \brief Returns the size (in bytes) of the contents of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_size(string const &s)
{
    return c_str_size_a(s);
}

/// \brief Returns the size (in bytes) of the contents of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_size_w(wstring const &s)
{
    return c_str_len(s) * sizeof(wstring::value_type);
}

/// \brief Returns the size (in bytes) of the contents of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_size(wstring const &s)
{
    return c_str_size_w(s);
}
# else /* ? compiler */
/// \brief Returns the size (in bytes) of the contents of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_size_a(stlsoft_ns_qual_std(string) const &s)
{
    return c_str_len(s) * sizeof(ss_char_a_t);
}

#  if !defined(STLSOFT_COMPILER_IS_GCC) || \
      !(__GNUC__ < 3)
/// \brief Returns the size (in bytes) of the contents of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_size_w(_stlsoft_wstring_t const &s)
{
    return c_str_len(s) * sizeof(ss_char_w_t);
}
#  endif /* compiler */

/// \brief Returns the size (in bytes) of the contents of \c s, <b><i>not</i></b> including the null-terminating character
template<   ss_typename_param_k C
        ,   ss_typename_param_k T
        ,   ss_typename_param_k A
        >
inline ss_size_t c_str_size(stlsoft_ns_qual_std(basic_string)<C, T, A> const &s)
{
    return c_str_len(s) * sizeof(C);
}
# endif /* STLSOFT_COMPILER_IS_MSVC && _MSC_VER < 1100 */
#endif /* STLSOFT_STRING_ACCESS_NO_STD_STRING */

/* stlport::basic_string */
/// \brief Returns the size (in bytes) of the contents of \c s, <b><i>not</i></b> including the null-terminating character
#if defined(_STLP_USE_NAMESPACES) && \
    defined(_STLP_USE_OWN_NAMESPACE) && \
    !defined(_STLP_REDEFINE_STD) && \
    (   !defined(_STLPORT_MAJOR) || \
        _STLPORT_MAJOR < 5)
inline ss_size_t c_str_size_a(stlport::string const &s)
{
    return c_str_len(s) * sizeof(ss_char_a_t);
}

/// \brief Returns the size (in bytes) of the contents of \c s, <b><i>not</i></b> including the null-terminating character
inline ss_size_t c_str_size_w(stlport::wstring const &s)
{
    return c_str_len(s) * sizeof(ss_char_w_t);
}

/// \brief Returns the size (in bytes) of the contents of \c s, <b><i>not</i></b> including the null-terminating character
template <ss_typename_param_k C>
inline ss_size_t c_str_size(stlport::basic_string<C> const &s)
{
    return c_str_len(s) * sizeof(C);
}
#endif /* _STLP_USE_NAMESPACES && _STLP_USE_OWN_NAMESPACE */
#else /* ? 0 */

template <ss_typename_param_k S>
inline ss_size_t c_str_size_a(S const &s)
{
    return sizeof(ss_char_a_t) * c_str_len(s);
}

template <ss_typename_param_k S>
inline ss_size_t c_str_size_w(S const &s)
{
    return sizeof(ss_char_w_t) * c_str_len(s);
}

template <ss_typename_param_k S>
inline ss_size_t c_str_size(S const &s)
{
    return sizeof(*c_str_ptr(s)) * c_str_len(s);
}

inline cannot_use_untyped_0_or_NULL_with_shims &c_str_size(int deny_literal_NULL);

#endif /* 0 */

////////////////////////////////////////////////////////////////////////////
// Unit-testing

#ifdef STLSOFT_UNITTEST
# include "./unittest/string_access_unittest_.h"
#endif /* STLSOFT_UNITTEST */

/* ////////////////////////////////////////////////////////////////////// */

#ifndef _STLSOFT_NO_NAMESPACE
} // namespace stlsoft
#endif /* _STLSOFT_NO_NAMESPACE */

/* ////////////////////////////////////////////////////////////////////// */

#endif /* !STLSOFT_INCL_STLSOFT_HPP_STRING_ACCESS */

/* ////////////////////////////////////////////////////////////////////// */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -