strapi.hpp

Go to the documentation of this file.
00001 /* $Id: strapi.hpp 15718 2009-03-15 00:32:18Z rubidium $ */
00002 
00005 #ifndef  STRAPI_HPP
00006 #define  STRAPI_HPP
00007 
00008 #include <string.h>
00009 
00010 #if defined(HAS_WCHAR)
00011 #include <wchar.h>
00012 
00013 #if !defined(_MSC_VER)
00014 #define _stricmp strcmp
00015 #define _wcsicmp wcscmp
00016 #endif /* !defined(_MSC_VER) */
00017 #endif /* HAS_WCHAR */
00018 
00023 template <typename Tchar>
00024 class CStrApiBaseT
00025 {
00026 public:
00028   static size_t StrLen(const Tchar *s);
00029   static int SPrintFL(Tchar *buf, size_t count, const Tchar *fmt, va_list args);
00030 };
00031 
00033 template <> /* static */ inline size_t CStrApiBaseT<char>::StrLen(const char *s)
00034 {
00035   return ::strlen(s);
00036 }
00037 
00039 template <> /* static */ inline int CStrApiBaseT<char>::SPrintFL(char *buf, size_t count, const char *fmt, va_list args)
00040 {
00041 #if defined(_MSC_VER) && !defined(WINCE)
00042   return ::vsnprintf_s(buf, count, count - 1, fmt, args);
00043 #else
00044   return ::vsnprintf(buf, count, fmt, args);
00045 #endif /* _MSC_VER && ! WINCE */
00046 }
00047 
00048 #if defined(HAS_WCHAR)
00049 
00050 template <> /* static */ inline size_t CStrApiBaseT<wchar_t>::StrLen(const wchar_t *s)
00051 {
00052   return ::wcslen(s);
00053 }
00054 
00056 template <> /* static */ inline int CStrApiBaseT<wchar_t>::SPrintFL(wchar_t *buf, size_t count, const wchar_t *fmt, va_list args)
00057 {
00058 #if defined(_MSC_VER) && !defined(WINCE)
00059   return ::_vsnwprintf_s(buf, count, count - 1, fmt, args);
00060 #else
00061 # if defined(_WIN32)
00062    return ::_vsnwprintf(buf, count, fmt, args);
00063 # else /* !_WIN32 */
00064    return ::vswprintf(buf, count, fmt, args);
00065 # endif /* !_WIN32 */
00066 #endif /* _MSC_VER && ! WINCE */
00067 }
00068 #endif /* HAS_WCHAR */
00069 
00070 
00071 
00072 template <typename Tchar, bool TcaseInsensitive>
00073 class CStrApiT : public CStrApiBaseT<Tchar>
00074 {
00075 public:
00076   static int StrCmp(const Tchar *s1, const Tchar *s2);
00077 };
00078 
00079 template <> /* static */ inline int CStrApiT<char, false>::StrCmp(const char *s1, const char *s2)
00080 {
00081   return ::strcmp(s1, s2);
00082 }
00083 
00084 template <> /* static */ inline int CStrApiT<char, true>::StrCmp(const char *s1, const char *s2)
00085 {
00086   return ::_stricmp(s1, s2);
00087 }
00088 
00089 #if defined(HAS_WCHAR)
00090 template <> /* static */ inline int CStrApiT<wchar_t, false>::StrCmp(const wchar_t *s1, const wchar_t *s2)
00091 {
00092   return ::wcscmp(s1, s2);
00093 }
00094 
00095 template <> /* static */ inline int CStrApiT<wchar_t, true>::StrCmp(const wchar_t *s1, const wchar_t *s2)
00096 {
00097   return ::_wcsicmp(s1, s2);
00098 }
00099 #endif /* HAS_WCHAR */
00100 
00101 #endif /* STRAPI_HPP */

Generated on Wed Jun 3 19:05:11 2009 for OpenTTD by  doxygen 1.5.6