X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/566b84d2ade885cc2fb4f75d63718331db8fe2df..103aec296a2c017f915b4b2b2584191fdb716a75:/include/wx/string.h diff --git a/include/wx/string.h b/include/wx/string.h index e997410380..50f9fbf4a1 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -26,6 +26,10 @@ #include #include +#ifdef HAVE_STRINGS_H + #include // for strcasecmp() +#endif // AIX + #ifndef WX_PRECOMP #include "wx/defs.h" @@ -70,7 +74,7 @@ const unsigned int wxSTRING_MAXLEN = UINT_MAX - 100; //--------------------------------------------------------------------------- // 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) @@ -79,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(__VISUALC__) || defined(__MWERKS__) +#if defined(__VISUALC__) || ( defined(__MWERKS__) && defined(__INTEL__) ) return _stricmp(psz1, psz2); #elif defined(__SC__) return _stricmp(psz1, psz2); @@ -91,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++); @@ -144,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++; } @@ -153,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); } }; // --------------------------------------------------------------------------- @@ -316,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__) || wxUSE_SIZE_T_STRING_OPERATOR // operator version of GetChar char operator[](size_t n) const { ASSERT_VALID_INDEX( n ); return m_pchData[n]; } @@ -410,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); } @@ -740,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(); @@ -792,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