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