KUDr@7612: /* $Id$ */ KUDr@7612: KUDr@7612: /** @file strapi.hpp */ KUDr@7612: KUDr@7612: #ifndef STRAPI_HPP KUDr@7612: #define STRAPI_HPP KUDr@7612: KUDr@7612: #include rubidium@7751: rubidium@7751: #if defined(HAS_WCHAR) KUDr@7612: #include KUDr@7612: KUDr@7612: #if !defined(_MSC_VER) KUDr@7612: #define _stricmp strcmp KUDr@7612: #define _wcsicmp wcscmp rubidium@7751: #endif /* !defined(_MSC_VER) */ rubidium@7751: #endif /* HAS_WCHAR */ KUDr@7612: KUDr@7612: /** String API mapper base - just mapping by character type, not by case sensitivity yet. KUDr@7612: * Class template CStrApiBaseT declaration is general, but following inline method KUDr@7612: * definitions are specialized by character type. Class is not used directly, but only KUDr@7612: * as a base class for template class CStrApiT */ KUDr@7612: template KUDr@7612: class CStrApiBaseT KUDr@7612: { KUDr@7612: public: KUDr@7612: /** ::strlen wrapper */ KUDr@7612: static size_t StrLen(const Tchar *s); KUDr@7612: static int SPrintFL(Tchar *buf, size_t count, const Tchar *fmt, va_list args); KUDr@7612: }; KUDr@7612: KUDr@7612: /** ::strlen wrapper specialization for char */ KUDr@7612: template <> /*static*/ inline size_t CStrApiBaseT::StrLen(const char *s) KUDr@7612: { KUDr@7612: return ::strlen(s); KUDr@7612: } KUDr@7612: KUDr@7612: /** ::vsprintf wrapper specialization for char */ KUDr@7612: template <> /*static*/ inline int CStrApiBaseT::SPrintFL(char *buf, size_t count, const char *fmt, va_list args) KUDr@7612: { truelight@7901: #if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(WINCE) // VC 8.0 and above KUDr@7612: return ::vsnprintf_s(buf, count, count - 1, fmt, args); rubidium@7751: #else /* ! VC 8.0 and above */ KUDr@7612: return ::vsnprintf(buf, count, fmt, args); KUDr@7612: #endif KUDr@7612: } KUDr@7612: rubidium@7751: #if defined(HAS_WCHAR) rubidium@7751: /** ::strlen wrapper specialization for wchar_t */ rubidium@7751: template <> /*static*/ inline size_t CStrApiBaseT::StrLen(const wchar_t *s) rubidium@7751: { rubidium@7751: return ::wcslen(s); rubidium@7751: } rubidium@7751: KUDr@7612: /** ::vsprintf wrapper specialization for wchar_t */ KUDr@7612: template <> /*static*/ inline int CStrApiBaseT::SPrintFL(wchar_t *buf, size_t count, const wchar_t *fmt, va_list args) KUDr@7612: { truelight@7901: #if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(WINCE) // VC 8.0 and above KUDr@7612: return ::_vsnwprintf_s(buf, count, count - 1, fmt, args); rubidium@7751: #else /* ! VC 8.0 and above */ KUDr@7612: # if defined(_WIN32) KUDr@7612: return ::_vsnwprintf(buf, count, fmt, args); rubidium@7751: # else /* !_WIN32 */ KUDr@7612: return ::vswprintf(buf, count, fmt, args); rubidium@7751: # endif /* !_WIN32 */ KUDr@7612: #endif KUDr@7612: } rubidium@7751: #endif /* HAS_WCHAR */ KUDr@7612: KUDr@7612: KUDr@7612: KUDr@7612: template KUDr@7612: class CStrApiT : public CStrApiBaseT KUDr@7612: { KUDr@7612: public: KUDr@7612: static int StrCmp(const Tchar *s1, const Tchar *s2); KUDr@7612: }; KUDr@7612: KUDr@7612: template <> /*static*/ inline int CStrApiT::StrCmp(const char *s1, const char *s2) KUDr@7612: { KUDr@7612: return ::strcmp(s1, s2); KUDr@7612: } KUDr@7612: KUDr@7612: template <> /*static*/ inline int CStrApiT::StrCmp(const char *s1, const char *s2) KUDr@7612: { KUDr@7612: return ::_stricmp(s1, s2); KUDr@7612: } KUDr@7612: rubidium@7751: #if defined(HAS_WCHAR) KUDr@7612: template <> /*static*/ inline int CStrApiT::StrCmp(const wchar_t *s1, const wchar_t *s2) KUDr@7612: { KUDr@7612: return ::wcscmp(s1, s2); KUDr@7612: } KUDr@7612: KUDr@7612: template <> /*static*/ inline int CStrApiT::StrCmp(const wchar_t *s1, const wchar_t *s2) KUDr@7612: { KUDr@7612: return ::_wcsicmp(s1, s2); KUDr@7612: } rubidium@7751: #endif /* HAS_WCHAR */ KUDr@7612: KUDr@7612: #endif /* STRAPI_HPP */