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