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