yapf/strapi.hpp
branchcustombridgeheads
changeset 5621 6ce400c0a2f4
parent 5620 3b40a41f90d2
child 5622 2f0cb276d32a
equal deleted inserted replaced
5620:3b40a41f90d2 5621:6ce400c0a2f4
     1 /* $Id$ */
       
     2 
       
     3 #ifndef  STRAPI_HPP
       
     4 #define  STRAPI_HPP
       
     5 
       
     6 #include <string.h>
       
     7 #include <wchar.h>
       
     8 
       
     9 #if !defined(_MSC_VER)
       
    10 #define _stricmp strcmp
       
    11 #define _wcsicmp wcscmp
       
    12 #endif //!_MSC_VER
       
    13 
       
    14 /** String API mapper base - just mapping by character type, not by case sensitivity yet.
       
    15 	* Class template CStrApiBaseT declaration is general, but following inline method
       
    16 	* definitions are specialized by character type. Class is not used directly, but only
       
    17 	* as a base class for template class CStrApiT */
       
    18 template <typename Tchar>
       
    19 class CStrApiBaseT
       
    20 {
       
    21 public:
       
    22 	/** ::strlen wrapper */
       
    23 	static size_t StrLen(const Tchar *s);
       
    24 	static int SPrintFL(Tchar *buf, size_t count, const Tchar *fmt, va_list args);
       
    25 };
       
    26 
       
    27 /** ::strlen wrapper specialization for char */
       
    28 template <> /*static*/ inline size_t CStrApiBaseT<char>::StrLen(const char *s)
       
    29 {
       
    30 	return ::strlen(s);
       
    31 }
       
    32 
       
    33 /** ::strlen wrapper specialization for wchar_t */
       
    34 template <> /*static*/ inline size_t CStrApiBaseT<wchar_t>::StrLen(const wchar_t *s)
       
    35 {
       
    36 	return ::wcslen(s);
       
    37 }
       
    38 
       
    39 /** ::vsprintf wrapper specialization for char */
       
    40 template <> /*static*/ inline int CStrApiBaseT<char>::SPrintFL(char *buf, size_t count, const char *fmt, va_list args)
       
    41 {
       
    42 #if defined(_MSC_VER) && (_MSC_VER >= 1400) // VC 8.0 and above
       
    43 	return ::vsnprintf_s(buf, count, count - 1, fmt, args);
       
    44 #else // ! VC 8.0 and above
       
    45 	return ::vsnprintf(buf, count, fmt, args);
       
    46 #endif
       
    47 }
       
    48 
       
    49 /** ::vsprintf wrapper specialization for wchar_t */
       
    50 template <> /*static*/ inline int CStrApiBaseT<wchar_t>::SPrintFL(wchar_t *buf, size_t count, const wchar_t *fmt, va_list args)
       
    51 {
       
    52 #if defined(_MSC_VER) && (_MSC_VER >= 1400) // VC 8.0 and above
       
    53 	return ::_vsnwprintf_s(buf, count, count - 1, fmt, args);
       
    54 #else // ! VC 8.0 and above
       
    55 	return ::vswprintf(buf, count, fmt, args);
       
    56 #endif
       
    57 }
       
    58 
       
    59 
       
    60 
       
    61 template <typename Tchar, bool TcaseInsensitive>
       
    62 class CStrApiT : public CStrApiBaseT<Tchar>
       
    63 {
       
    64 public:
       
    65 	static int StrCmp(const Tchar *s1, const Tchar *s2);
       
    66 };
       
    67 
       
    68 template <> /*static*/ inline int CStrApiT<char, false>::StrCmp(const char *s1, const char *s2)
       
    69 {
       
    70 	return ::strcmp(s1, s2);
       
    71 }
       
    72 
       
    73 template <> /*static*/ inline int CStrApiT<char, true>::StrCmp(const char *s1, const char *s2)
       
    74 {
       
    75 	return ::_stricmp(s1, s2);
       
    76 }
       
    77 
       
    78 template <> /*static*/ inline int CStrApiT<wchar_t, false>::StrCmp(const wchar_t *s1, const wchar_t *s2)
       
    79 {
       
    80 	return ::wcscmp(s1, s2);
       
    81 }
       
    82 
       
    83 template <> /*static*/ inline int CStrApiT<wchar_t, true>::StrCmp(const wchar_t *s1, const wchar_t *s2)
       
    84 {
       
    85 	return ::_wcsicmp(s1, s2);
       
    86 }
       
    87 
       
    88 #endif /* STRAPI_HPP */