Listing 12: String length shims
/* /////////////////////////////////////////////////////////////
* Extract from stlsoft_string_access.h, comstl_string_access.h,
* mfcstl_string_access.h, winstl_string_access.h
*
* www: http://stlsoft.org/, http://comstl.org/
* http://mfcstl.org/, http://winstl.org/
*
* Copyright (C) 2002, Synesis Software Pty Ltd.
* (Licensed under the Synesis Software Standard Source License:
* http://www.synesis.com.au/licenses/ssssl.html)
* ////////////////////////////////////////////////////////// */
namespace stlsoft
{
/* C-style Unicode string */
inline size_t c_str_len(wchar_t const *s)
{
return (s == 0) ? 0 : char_traits<wchar_t>::length(s);
}
} // namespace stlsoft
namespace comstl
{
const size_t COMSTL_CCH_GUID = 38; // Fixed format & length
/* GUID */
inline size_t c_str_len(GUID const &/* guid */)
{
return COMSTL_CCH_GUID;
}
/* VARIANT */
inline size_t c_str_len(VARIANT const &v)
{
if(v.vt == VT_BSTR)
{
return ::SysStringLen(v.bstrVal);
}
else
{
// Do a copy and conversion to VT_BSTR and get
// length from that
...
}
} // namespace comstl
namespace mfcstl
{
/* CString */
inline size_t c_str_len(CString const &s)
{
return s.GetLength();
}
} // namespace mfcstl
namespace winstl
{
/* HWND */
inline size_t c_str_len(HWND h)
{
return static_cast<size_t>(::GetWindowTextLength(h));
}
/* LSA_UNICODE_STRING */
inline size_t c_str_len(LSA_UNICODE_STRING const &s)
{
return s.Length;
}
} // namespace winstl