From 91d6051adb8c17c1dd31566c48f4488340091359 Mon Sep 17 00:00:00 2001 From: KUDr Date: Fri, 29 Jun 2007 22:33:58 +0000 Subject: (svn r10389) -Add: CStrA, CStrCiA, CStrW, CStrCiW - case sensitive/insensitive ANSI/UNICODE string classes that support formatted (sprintf like) output. --- src/misc/strapi.hpp | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/misc/strapi.hpp (limited to 'src/misc/strapi.hpp') diff --git a/src/misc/strapi.hpp b/src/misc/strapi.hpp new file mode 100644 index 000000000..c901af6ea --- /dev/null +++ b/src/misc/strapi.hpp @@ -0,0 +1,94 @@ +/* $Id$ */ + +/** @file strapi.hpp */ + +#ifndef STRAPI_HPP +#define STRAPI_HPP + +#include +#include + +#if !defined(_MSC_VER) +#define _stricmp strcmp +#define _wcsicmp wcscmp +#endif //!_MSC_VER + +/** String API mapper base - just mapping by character type, not by case sensitivity yet. + * Class template CStrApiBaseT declaration is general, but following inline method + * definitions are specialized by character type. Class is not used directly, but only + * as a base class for template class CStrApiT */ +template +class CStrApiBaseT +{ +public: + /** ::strlen wrapper */ + static size_t StrLen(const Tchar *s); + static int SPrintFL(Tchar *buf, size_t count, const Tchar *fmt, va_list args); +}; + +/** ::strlen wrapper specialization for char */ +template <> /*static*/ inline size_t CStrApiBaseT::StrLen(const char *s) +{ + return ::strlen(s); +} + +/** ::strlen wrapper specialization for wchar_t */ +template <> /*static*/ inline size_t CStrApiBaseT::StrLen(const wchar_t *s) +{ + return ::wcslen(s); +} + +/** ::vsprintf wrapper specialization for char */ +template <> /*static*/ inline int CStrApiBaseT::SPrintFL(char *buf, size_t count, const char *fmt, va_list args) +{ +#if defined(_MSC_VER) && (_MSC_VER >= 1400) // VC 8.0 and above + return ::vsnprintf_s(buf, count, count - 1, fmt, args); +#else // ! VC 8.0 and above + return ::vsnprintf(buf, count, fmt, args); +#endif +} + +/** ::vsprintf wrapper specialization for wchar_t */ +template <> /*static*/ inline int CStrApiBaseT::SPrintFL(wchar_t *buf, size_t count, const wchar_t *fmt, va_list args) +{ +#if defined(_MSC_VER) && (_MSC_VER >= 1400) // VC 8.0 and above + return ::_vsnwprintf_s(buf, count, count - 1, fmt, args); +#else // ! VC 8.0 and above +# if defined(_WIN32) + return ::_vsnwprintf(buf, count, fmt, args); +# else // !_WIN32 + return ::vswprintf(buf, count, fmt, args); +# endif // !_WIN32 +#endif +} + + + +template +class CStrApiT : public CStrApiBaseT +{ +public: + static int StrCmp(const Tchar *s1, const Tchar *s2); +}; + +template <> /*static*/ inline int CStrApiT::StrCmp(const char *s1, const char *s2) +{ + return ::strcmp(s1, s2); +} + +template <> /*static*/ inline int CStrApiT::StrCmp(const char *s1, const char *s2) +{ + return ::_stricmp(s1, s2); +} + +template <> /*static*/ inline int CStrApiT::StrCmp(const wchar_t *s1, const wchar_t *s2) +{ + return ::wcscmp(s1, s2); +} + +template <> /*static*/ inline int CStrApiT::StrCmp(const wchar_t *s1, const wchar_t *s2) +{ + return ::_wcsicmp(s1, s2); +} + +#endif /* STRAPI_HPP */ -- cgit v1.2.3-70-g09d2