summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2009-08-19 13:13:32 +0000
committeryexo <yexo@openttd.org>2009-08-19 13:13:32 +0000
commit94198e09ce5c07fb2ac821326dddfb143928578b (patch)
tree1e6bdf80ac5ff4e0443f43c031fce63bd00ae078
parent0fa0286ebb312c0ebbf5e4e84765609b05485041 (diff)
downloadopenttd-94198e09ce5c07fb2ac821326dddfb143928578b.tar.xz
(svn r17219) -Cleanup: remove a lot of unused string code
-rw-r--r--projects/openttd_vs80.vcproj4
-rw-r--r--projects/openttd_vs90.vcproj4
-rw-r--r--source.list1
-rw-r--r--src/misc/blob.hpp3
-rw-r--r--src/misc/str.hpp117
-rw-r--r--src/misc/strapi.hpp101
-rw-r--r--src/stdafx.h5
-rw-r--r--src/strings.cpp2
8 files changed, 22 insertions, 215 deletions
diff --git a/projects/openttd_vs80.vcproj b/projects/openttd_vs80.vcproj
index 60aa9f2db..6590524cd 100644
--- a/projects/openttd_vs80.vcproj
+++ b/projects/openttd_vs80.vcproj
@@ -3367,10 +3367,6 @@
RelativePath=".\..\src\misc\str.hpp"
>
</File>
- <File
- RelativePath=".\..\src\misc\strapi.hpp"
- >
- </File>
</Filter>
<Filter
Name="Network Core"
diff --git a/projects/openttd_vs90.vcproj b/projects/openttd_vs90.vcproj
index b1a6aa123..5433539e5 100644
--- a/projects/openttd_vs90.vcproj
+++ b/projects/openttd_vs90.vcproj
@@ -3364,10 +3364,6 @@
RelativePath=".\..\src\misc\str.hpp"
>
</File>
- <File
- RelativePath=".\..\src\misc\strapi.hpp"
- >
- </File>
</Filter>
<Filter
Name="Network Core"
diff --git a/source.list b/source.list
index 046c7581c..f2e1d964e 100644
--- a/source.list
+++ b/source.list
@@ -808,7 +808,6 @@ misc/dbg_helpers.h
misc/fixedsizearray.hpp
misc/hashtable.hpp
misc/str.hpp
-misc/strapi.hpp
# Network Core
network/core/address.cpp
diff --git a/src/misc/blob.hpp b/src/misc/blob.hpp
index bd626e132..5403adcce 100644
--- a/src/misc/blob.hpp
+++ b/src/misc/blob.hpp
@@ -52,9 +52,6 @@ protected:
/** type used as class member */
union {
bitem_t *m_pData; ///< ptr to the first byte of data
-#if defined(HAS_WCHAR)
- wchar_t *m_pwData; ///< ptr to the first byte of data
-#endif /* HAS_WCHAR */
CHdr *m_pHdr_1; ///< ptr just after the CHdr holding m_size and m_max_size
} ptr_u;
diff --git a/src/misc/str.hpp b/src/misc/str.hpp
index 666c03187..6b9cf87ac 100644
--- a/src/misc/str.hpp
+++ b/src/misc/str.hpp
@@ -7,125 +7,65 @@
#include <errno.h>
#include <stdarg.h>
-#include "strapi.hpp"
+#include "../string_func.h"
-/** Blob based string. */
-template <typename Tchar, bool TcaseInsensitive>
-struct CStrT : public CBlobT<Tchar>
+/** Blob based case sensitive ANSI/UTF-8 string */
+struct CStrA : public CBlobT<char>
{
- typedef CBlobT<Tchar> base; ///< base class
- typedef CStrApiT<Tchar, TcaseInsensitive> Api; ///< string API abstraction layer
- typedef typename base::bsize_t bsize_t; ///< size type inherited from blob
- typedef typename base::OnTransfer OnTransfer; ///< temporary 'transfer ownership' object type
+ typedef CBlobT<char> base; ///< base class
- /** Construction from C zero ended string. */
- FORCEINLINE CStrT(const Tchar *str = NULL)
+ /** Create an empty CStrT */
+ FORCEINLINE CStrA()
{
- AppendStr(str);
- }
-
- /** Construction from C string and given number of characters. */
- FORCEINLINE CStrT(const Tchar *str, bsize_t num_chars) : base(str, num_chars)
- {
- base::FixTail();
- }
-
- /** Construction from C string determined by 'begin' and 'end' pointers. */
- FORCEINLINE CStrT(const Tchar *str, const Tchar *end)
- : base(str, end - str)
- {
- base::FixTail();
- }
-
- /** Construction from blob contents. */
- FORCEINLINE CStrT(const CBlobBaseSimple& src)
- : base(src)
- {
- base::FixTail();
- }
-
- /** Copy constructor. */
- FORCEINLINE CStrT(const CStrT& src)
- : base(src)
- {
- base::FixTail();
}
/** Take over ownership constructor */
- FORCEINLINE CStrT(const OnTransfer& ot)
+ FORCEINLINE CStrA(const OnTransfer& ot)
: base(ot)
{
}
/** Grow the actual buffer and fix the trailing zero at the end. */
- FORCEINLINE Tchar *GrowSizeNC(bsize_t count)
+ FORCEINLINE char *GrowSizeNC(bsize_t count)
{
- Tchar *ret = base::GrowSizeNC(count);
+ char *ret = base::GrowSizeNC(count);
base::FixTail();
return ret;
}
/** Append zero-ended C string. */
- FORCEINLINE void AppendStr(const Tchar *str)
- {
- if (str != NULL && str[0] != '\0') {
- base::Append(str, (bsize_t)Api::StrLen(str));
- base::FixTail();
- }
- }
-
- /** Append another CStrT or blob. */
- FORCEINLINE void Append(const CBlobBaseSimple& src)
+ FORCEINLINE void AppendStr(const char *str)
{
- if (src.RawSize() > 0) {
- base::AppendRaw(src);
+ if (!StrEmpty(str)) {
+ base::Append(str, strlen(str));
base::FixTail();
}
}
/** Assignment from C string. */
- FORCEINLINE CStrT& operator = (const Tchar *src)
+ FORCEINLINE CStrA& operator = (const char *src)
{
base::Clear();
AppendStr(src);
return *this;
}
- /** Assignment from another CStrT or blob. */
- FORCEINLINE CStrT& operator = (const CBlobBaseSimple& src)
- {
- base::Clear();
- base::AppendRaw(src);
- base::FixTail();
- return *this;
- }
-
- /** Assignment from another CStrT or blob. */
- FORCEINLINE CStrT& operator = (const CStrT& src)
- {
- base::Clear();
- base::AppendRaw(src);
- base::FixTail();
- return *this;
- }
-
/** Lower-than operator (to support stl collections) */
- FORCEINLINE bool operator < (const CStrT &other) const
+ FORCEINLINE bool operator < (const CStrA &other) const
{
- return (Api::StrCmp(base::Data(), other.Data()) < 0);
+ return strcmp(base::Data(), other.Data()) < 0;
}
/** Add formated string (like vsprintf) at the end of existing contents. */
- int AddFormatL(const Tchar *format, va_list args)
+ int AddFormatL(const char *format, va_list args)
{
- bsize_t addSize = Api::StrLen(format);
- if (addSize < 16) addSize = 16;
+ bsize_t addSize = max<size_t>(strlen(format), 16);
addSize += addSize / 2;
int ret;
int err = 0;
for (;;) {
- Tchar *buf = MakeFreeSpace(addSize);
- ret = Api::SPrintFL(buf, base::GetReserve(), format, args);
+ char *buf = MakeFreeSpace(addSize);
+ ret = vsnprintf(buf, base::GetReserve(), format, args);
if (ret >= base::GetReserve()) {
/* Greater return than given count means needed buffer size. */
addSize = ret + 1;
@@ -152,7 +92,7 @@ struct CStrT : public CBlobT<Tchar>
}
/** Add formated string (like sprintf) at the end of existing contents. */
- int AddFormat(const Tchar *format, ...)
+ int AddFormat(const char *format, ...)
{
va_list args;
va_start(args, format);
@@ -161,16 +101,8 @@ struct CStrT : public CBlobT<Tchar>
return ret;
}
- /** Assign formated string (like vsprintf). */
- int FormatL(const Tchar *format, va_list args)
- {
- base::Free();
- int ret = AddFormatL(format, args);
- return ret;
- }
-
/** Assign formated string (like sprintf). */
- int Format(const Tchar *format, ...)
+ int Format(const char *format, ...)
{
base::Free();
va_list args;
@@ -181,11 +113,4 @@ struct CStrT : public CBlobT<Tchar>
}
};
-typedef CStrT<char , false> CStrA; ///< Case sensitive ANSI/UTF-8 string
-typedef CStrT<char , true > CStrCiA; ///< Case insensitive ANSI/UTF-8 string
-#if defined(HAS_WCHAR)
-typedef CStrT<wchar_t, false> CStrW; ///< Case sensitive unicode string
-typedef CStrT<wchar_t, true > CStrCiW; ///< Case insensitive unicode string
-#endif /* HAS_WCHAR */
-
#endif /* STR_HPP */
diff --git a/src/misc/strapi.hpp b/src/misc/strapi.hpp
deleted file mode 100644
index 468fac15b..000000000
--- a/src/misc/strapi.hpp
+++ /dev/null
@@ -1,101 +0,0 @@
-/* $Id$ */
-
-/** @file strapi.hpp More string formatting? */
-
-#ifndef STRAPI_HPP
-#define STRAPI_HPP
-
-#include <string.h>
-
-#if defined(HAS_WCHAR)
-#include <wchar.h>
-
-#if !defined(_MSC_VER)
-#define _stricmp strcmp
-#define _wcsicmp wcscmp
-#endif /* !defined(_MSC_VER) */
-#endif /* HAS_WCHAR */
-
-/** String API mapper base - just mapping by character type, not by case sensitivity yet.
- * Class template CStrApiBaseT declaration is general, but following inline method
- * definitions are specialized by character type. Class is not used directly, but only
- * as a base class for template class CStrApiT */
-template <typename Tchar>
-class CStrApiBaseT
-{
-public:
- /** ::strlen wrapper */
- static size_t StrLen(const Tchar *s);
- static int SPrintFL(Tchar *buf, size_t count, const Tchar *fmt, va_list args);
-};
-
-/** ::strlen wrapper specialization for char */
-template <> /* static */ inline size_t CStrApiBaseT<char>::StrLen(const char *s)
-{
- return ::strlen(s);
-}
-
-/** ::vsprintf wrapper specialization for char */
-template <> /* static */ inline int CStrApiBaseT<char>::SPrintFL(char *buf, size_t count, const char *fmt, va_list args)
-{
-#if defined(_MSC_VER) && !defined(WINCE)
- return ::vsnprintf_s(buf, count, count - 1, fmt, args);
-#else
- return ::vsnprintf(buf, count, fmt, args);
-#endif /* _MSC_VER && ! WINCE */
-}
-
-#if defined(HAS_WCHAR)
-/** ::strlen wrapper specialization for wchar_t */
-template <> /* static */ inline size_t CStrApiBaseT<wchar_t>::StrLen(const wchar_t *s)
-{
- return ::wcslen(s);
-}
-
-/** ::vsprintf wrapper specialization for wchar_t */
-template <> /* static */ inline int CStrApiBaseT<wchar_t>::SPrintFL(wchar_t *buf, size_t count, const wchar_t *fmt, va_list args)
-{
-#if defined(_MSC_VER) && !defined(WINCE)
- return ::_vsnwprintf_s(buf, count, count - 1, fmt, args);
-#else
-# if defined(_WIN32)
- return ::_vsnwprintf(buf, count, fmt, args);
-# else /* !_WIN32 */
- return ::vswprintf(buf, count, fmt, args);
-# endif /* !_WIN32 */
-#endif /* _MSC_VER && ! WINCE */
-}
-#endif /* HAS_WCHAR */
-
-
-
-template <typename Tchar, bool TcaseInsensitive>
-class CStrApiT : public CStrApiBaseT<Tchar>
-{
-public:
- static int StrCmp(const Tchar *s1, const Tchar *s2);
-};
-
-template <> /* static */ inline int CStrApiT<char, false>::StrCmp(const char *s1, const char *s2)
-{
- return ::strcmp(s1, s2);
-}
-
-template <> /* static */ inline int CStrApiT<char, true>::StrCmp(const char *s1, const char *s2)
-{
- return ::_stricmp(s1, s2);
-}
-
-#if defined(HAS_WCHAR)
-template <> /* static */ inline int CStrApiT<wchar_t, false>::StrCmp(const wchar_t *s1, const wchar_t *s2)
-{
- return ::wcscmp(s1, s2);
-}
-
-template <> /* static */ inline int CStrApiT<wchar_t, true>::StrCmp(const wchar_t *s1, const wchar_t *s2)
-{
- return ::_wcsicmp(s1, s2);
-}
-#endif /* HAS_WCHAR */
-
-#endif /* STRAPI_HPP */
diff --git a/src/stdafx.h b/src/stdafx.h
index bbb25639e..dfe185c7f 100644
--- a/src/stdafx.h
+++ b/src/stdafx.h
@@ -365,11 +365,6 @@ void NORETURN CDECL error(const char *str, ...) WARN_FORMAT(1, 2);
#define _stricmp strcasecmp
#endif
-#if !defined(MORPHOS) && !defined(OPENBSD) && !defined(__NDS__) && !defined(__DJGPP__)
- /* NDS, MorphOS & OpenBSD don't know wchars, the rest does :( */
- #define HAS_WCHAR
-#endif /* !defined(MORPHOS) && !defined(OPENBSD) && !defined(__NDS__) */
-
#if !defined(MAX_PATH)
#define MAX_PATH 260
#endif
diff --git a/src/strings.cpp b/src/strings.cpp
index bd1b6abaa..322b0e569 100644
--- a/src/strings.cpp
+++ b/src/strings.cpp
@@ -719,7 +719,7 @@ static char *FormatString(char *buff, const char *str, int64 *argv, uint casei,
const char *s = GetStringPtr(argv_orig[(byte)*str++]); // contains the string that determines gender.
int gender = 0;
if (s != NULL) {
- wchar_t c = Utf8Consume(&s);
+ WChar c = Utf8Consume(&s);
/* Switch case is always put before genders, so remove those bits */
if (c == SCC_SWITCH_CASE) {
/* Skip to the last (i.e. default) case */