X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dcfde59229aeb96908aa0fa234753d22c8452b00..58a8ab88685a72ac030d5e2ade62b4d796f11bed:/include/wx/string.h diff --git a/include/wx/string.h b/include/wx/string.h index c23b431316..97e65cc941 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -16,27 +16,27 @@ #pragma interface "string.h" #endif -/* Dependencies (should be included before this header): - * string.h - * stdio.h - * stdarg.h - * limits.h - */ #ifdef __WXMAC__ -#include + #include #endif + #include #include #include #include #include +#ifdef HAVE_STRINGS_H + #include // for strcasecmp() +#endif // AIX + #ifndef WX_PRECOMP - #include "wx/defs.h" // Robert Roebling + #include "wx/defs.h" + #ifdef WXSTRING_IS_WXOBJECT #include "wx/object.h" #endif -#endif +#endif // !PCH #include "wx/debug.h" @@ -60,7 +60,7 @@ // maximum possible length for a string means "take all string" everywhere // (as sizeof(StringData) is unknown here we substract 100) -#define STRING_MAXLEN (UINT_MAX - 100) +const unsigned int wxSTRING_MAXLEN = UINT_MAX - 100; // 'naughty' cast #define WXSTRINGCAST (char *)(const char *) @@ -74,7 +74,7 @@ //--------------------------------------------------------------------------- // checks whether the passed in pointer is NULL and if the string is empty -inline bool WXDLLEXPORT IsEmpty(const char *p) { return !p || !*p; } +inline bool WXDLLEXPORT IsEmpty(const char *p) { return (!p || !*p); } // safe version of strlen() (returns 0 if passed NULL pointer) inline size_t WXDLLEXPORT Strlen(const char *psz) @@ -83,7 +83,7 @@ inline size_t WXDLLEXPORT Strlen(const char *psz) // portable strcasecmp/_stricmp inline int WXDLLEXPORT Stricmp(const char *psz1, const char *psz2) { -#if defined(_MSC_VER) +#if defined(__VISUALC__) || ( defined(__MWERKS__) && defined(__INTEL__) ) return _stricmp(psz1, psz2); #elif defined(__SC__) return _stricmp(psz1, psz2); @@ -95,7 +95,7 @@ inline int WXDLLEXPORT Stricmp(const char *psz1, const char *psz2) return stricmp(psz1, psz2); #elif defined(__UNIX__) || defined(__GNUWIN32__) return strcasecmp(psz1, psz2); -#elif defined(__MWERKS__) && !defined(_MSC_VER) +#elif defined(__MWERKS__) && !defined(__INTEL__) register char c1, c2; do { c1 = tolower(*psz1++); @@ -148,8 +148,8 @@ struct WXDLLEXPORT wxStringData char* data() const { return (char*)(this + 1); } // empty string has a special ref count so it's never deleted - bool IsEmpty() const { return nRefs == -1; } - bool IsShared() const { return nRefs > 1; } + bool IsEmpty() const { return (nRefs == -1); } + bool IsShared() const { return (nRefs > 1); } // lock/unlock void Lock() { if ( !IsEmpty() ) nRefs++; } @@ -157,8 +157,8 @@ struct WXDLLEXPORT wxStringData // if we had taken control over string memory (GetWriteBuf), it's // intentionally put in invalid state - void Validate(bool b) { nRefs = b ? 1 : 0; } - bool IsValid() const { return nRefs != 0; } + void Validate(bool b) { nRefs = (b ? 1 : 0); } + bool IsValid() const { return (nRefs != 0); } }; // --------------------------------------------------------------------------- @@ -210,7 +210,7 @@ private: // ctors, use Reinit() otherwise) void Init() { m_pchData = (char *)g_szNul; } // initializaes the string with (a part of) C-string - void InitWith(const char *psz, size_t nPos = 0, size_t nLen = STRING_MAXLEN); + void InitWith(const char *psz, size_t nPos = 0, size_t nLen = wxSTRING_MAXLEN); // as Init, but also frees old data void Reinit() { GetStringData()->Unlock(); Init(); } @@ -230,6 +230,13 @@ private: void CopyBeforeWrite(); void AllocBeforeWrite(size_t); + // this method is not implemented - there is _no_ conversion from int to + // string, you're doing something wrong if the compiler wants to call it! + // + // try `s << i' or `s.Printf("%d", i)' instead + wxString(int); + wxString(long); + public: // constructors and destructor // ctor for an empty string @@ -251,11 +258,11 @@ public: // string containing nRepeat copies of ch wxString(char ch, size_t nRepeat = 1); // ctor takes first nLength characters from C string - // (default value of STRING_MAXLEN means take all the string) - wxString(const char *psz, size_t nLength = STRING_MAXLEN) + // (default value of wxSTRING_MAXLEN means take all the string) + wxString(const char *psz, size_t nLength = wxSTRING_MAXLEN) { InitWith(psz, 0, nLength); } // from C string (for compilers using unsigned char) - wxString(const unsigned char* psz, size_t nLength = STRING_MAXLEN); + wxString(const unsigned char* psz, size_t nLength = wxSTRING_MAXLEN); // from wide (UNICODE) string wxString(const wchar_t *pwz); // dtor is not virtual, this class must not be inherited from! @@ -313,9 +320,10 @@ public: char& Last() { wxASSERT( !IsEmpty() ); CopyBeforeWrite(); return m_pchData[Len()-1]; } - // on alpha-linux this gives overload problems: - // Also on Solaris, so removing for now (JACS) -#if ! defined(__ALPHA__) + // under Unix it is tested with configure, assume it works on other + // platforms (there might be overloading problems if size_t and int are + // the same type) +#if !defined(__UNIX__) || defined(wxUSE_SIZE_T_STRING_OPERATOR) // operator version of GetChar char operator[](size_t n) const { ASSERT_VALID_INDEX( n ); return m_pchData[n]; } @@ -407,7 +415,7 @@ public: wxString& operator<<(double d); // string comparison - // case-sensitive comparison: return 0 if =, +1 if > or -1 if < + // case-sensitive comparison (returns a value < 0, = 0 or > 0) int Cmp(const char *psz) const { return strcmp(c_str(), psz); } // same as Cmp() but not case-sensitive int CmpNoCase(const char *psz) const { return Stricmp(c_str(), psz); } @@ -419,7 +427,7 @@ public: // simple sub-string extraction // return substring starting at nFirst of length nCount (or till the end // if nCount = default value) - wxString Mid(size_t nFirst, size_t nCount = STRING_MAXLEN) const; + wxString Mid(size_t nFirst, size_t nCount = wxSTRING_MAXLEN) const; // operator version of Mid() wxString operator()(size_t start, size_t len) const @@ -450,11 +458,12 @@ public: // convert to upper case in place, return the string itself wxString& MakeUpper(); // convert to upper case, return the copy of the string - wxString Upper() const { wxString s(*this); return s.MakeUpper(); } + // Here's something to remember: BC++ doesn't like returns in inlines. + wxString Upper() const ; // convert to lower case in place, return the string itself wxString& MakeLower(); // convert to lower case, return the copy of the string - wxString Lower() const { wxString s(*this); return s.MakeLower(); } + wxString Lower() const ; // trimming/padding whitespace (either side) and truncating // remove spaces from left or from right (default) side @@ -506,15 +515,9 @@ public: enum caseCompare {exact, ignoreCase}; // values for first parameter of Strip function enum stripType {leading = 0x1, trailing = 0x2, both = 0x3}; + // use Printf() - inline int sprintf(const char *pszFormat, ...) - { - va_list argptr; - va_start(argptr, pszFormat); - int iLen = PrintfV(pszFormat, argptr); - va_end(argptr); - return iLen; - } + int sprintf(const char *pszFormat, ...); // use Cmp() inline int CompareTo(const char* psz, caseCompare cmp = exact) const @@ -572,7 +575,7 @@ public: // return the length of the string size_t length() const { return Len(); } // return the maximum size of the string - size_t max_size() const { return STRING_MAXLEN; } + size_t max_size() const { return wxSTRING_MAXLEN; } // resize the string, filling the space with c if c != 0 void resize(size_t nSize, char ch = '\0'); // delete the contents of the string @@ -650,7 +653,7 @@ public: size_t find(const wxString& str, size_t nStart = 0) const; // VC++ 1.5 can't cope with this syntax. -#if !(defined(_MSC_VER) && !defined(__WIN32__)) +#if !defined(__VISUALC__) || defined(__WIN32__) // find first n characters of sz size_t find(const char* sz, size_t nStart = 0, size_t n = npos) const; #endif @@ -666,7 +669,7 @@ public: size_t rfind(const wxString& str, size_t nStart = npos) const; // VC++ 1.5 can't cope with this syntax. -#if ! (defined(_MSC_VER) && !defined(__WIN32__)) +#if !defined(__VISUALC__) || defined(__WIN32__) // as find, but from the end size_t rfind(const char* sz, size_t nStart = npos, size_t n = npos) const; @@ -742,6 +745,10 @@ public: class WXDLLEXPORT wxArrayString { public: + // type of function used by wxArrayString::Sort() + typedef int (*CompareFunction)(const wxString& first, + const wxString& second); + // constructors and destructor // default ctor wxArrayString(); @@ -794,13 +801,19 @@ public: // remove item by index void Remove(size_t nIndex); - // sort array elements - void Sort(bool bCase = TRUE, bool bReverse = FALSE); + // sorting + // sort array elements in alphabetical order (or reversed alphabetical + // order if reverseOrder parameter is TRUE) + void Sort(bool reverseOrder = FALSE); + // sort array elements using specified comparaison function + void Sort(CompareFunction compareFunction); private: void Grow(); // makes array bigger if needed void Free(); // free the string stored + void DoSort(); // common part of all Sort() variants + size_t m_nSize, // current size of the array m_nCount; // current number of elements @@ -859,19 +872,7 @@ wxString WXDLLEXPORT operator+(const char *psz, const wxString& string); #ifdef wxSTD_STRING_COMPATIBILITY -// forward declare iostream -// Known not to work with wxUSE_IOSTREAMH set to 0, so -// replacing with includes (on advice of ungod@pasdex.com.au) -// class WXDLLEXPORT istream; -#if wxUSE_IOSTREAMH -// N.B. BC++ doesn't have istream.h, ostream.h -#include -#else -#include -# ifdef _MSC_VER - using namespace std; -# endif -#endif +#include "wx/ioswrap.h" WXDLLEXPORT istream& operator>>(istream& is, wxString& str);