2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: arrstr.h
|
2008-03-10 11:24:38 -04:00
|
|
|
// Purpose: interface of wxArrayString
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
2010-07-13 09:29:13 -04:00
|
|
|
// Licence: wxWindows licence
|
2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxArrayString
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-14 11:35:10 -04:00
|
|
|
wxArrayString is an efficient container for storing wxString objects.
|
|
|
|
|
|
|
|
It has the same features as all wxArray classes, i.e. it dynamically expands
|
|
|
|
when new items are added to it (so it is as easy to use as a linked list),
|
|
|
|
but the access time to the elements is constant, instead of being linear in
|
|
|
|
number of elements as in the case of linked lists. It is also very size
|
|
|
|
efficient and doesn't take more space than a C array @e wxString[] type
|
|
|
|
(wxArrayString uses its knowledge of internals of wxString class to achieve this).
|
|
|
|
|
|
|
|
This class is used in the same way as other dynamic arrays(), except that no
|
2008-03-24 08:45:43 -04:00
|
|
|
::WX_DEFINE_ARRAY declaration is needed for it.
|
2008-03-14 11:35:10 -04:00
|
|
|
When a string is added or inserted in the array, a copy of the string is created,
|
|
|
|
so the original string may be safely deleted (e.g. if it was a @e wxChar *
|
|
|
|
pointer the memory it was using can be freed immediately after this).
|
|
|
|
In general, there is no need to worry about string memory deallocation when using
|
2008-03-08 08:52:38 -05:00
|
|
|
this class - it will always free the memory it uses itself.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-14 11:35:10 -04:00
|
|
|
The references returned by wxArrayString::Item, wxArrayString::Last or
|
|
|
|
wxArrayString::operator[] are not constant, so the array elements may
|
|
|
|
be modified in place like this:
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@code
|
|
|
|
array.Last().MakeUpper();
|
|
|
|
@endcode
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2019-08-08 05:32:04 -04:00
|
|
|
@note None of the methods of wxArrayString is virtual including its
|
2008-03-14 11:35:10 -04:00
|
|
|
destructor, so this class should not be used as a base class.
|
|
|
|
|
|
|
|
Although this is not true strictly speaking, this class may be considered as
|
|
|
|
a specialization of wxArray class for the wxString member data: it is not
|
|
|
|
implemented like this, but it does have all of the wxArray functions.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2009-02-12 07:09:13 -05:00
|
|
|
It also has the full set of <tt>std::vector<wxString></tt> compatible
|
|
|
|
methods, including nested @c iterator and @c const_iterator classes which
|
|
|
|
should be used in the new code for forward compatibility with the future
|
|
|
|
wxWidgets versions.
|
2008-03-14 11:51:35 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
|
|
|
@category{containers}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2019-08-08 05:32:04 -04:00
|
|
|
@see wxSortedArrayString, wxArray<T>, wxString, @ref overview_string
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
class wxArrayString : public wxArray
|
|
|
|
{
|
|
|
|
public:
|
2008-12-29 09:14:39 -05:00
|
|
|
/**
|
2014-06-22 21:08:50 -04:00
|
|
|
The function type used with wxArrayString::Sort().
|
|
|
|
|
|
|
|
This function uses the same conventions as the standard @c qsort()
|
|
|
|
comparison function, that is it should return a negative value if the
|
|
|
|
first argument is less than the second one, a positive value if the
|
|
|
|
first argument is greater than the second one and 0 if the arguments
|
|
|
|
are equal.
|
|
|
|
|
|
|
|
@since 3.1.0
|
2008-12-29 09:14:39 -05:00
|
|
|
*/
|
|
|
|
typedef int (*CompareFunction)(const wxString& first, const wxString& second);
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2008-03-14 11:35:10 -04:00
|
|
|
Default constructor.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
wxArrayString();
|
2008-03-14 11:35:10 -04:00
|
|
|
|
|
|
|
/**
|
2008-03-14 11:51:35 -04:00
|
|
|
Copy constructor.
|
2008-03-14 11:35:10 -04:00
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
wxArrayString(const wxArrayString& array);
|
2008-03-14 11:35:10 -04:00
|
|
|
|
2022-08-03 12:28:06 -04:00
|
|
|
///@{
|
2008-03-14 11:35:10 -04:00
|
|
|
/**
|
2008-03-24 08:45:43 -04:00
|
|
|
Constructor from a C string array. Pass a size @a sz and an array @a arr.
|
2008-03-14 11:35:10 -04:00
|
|
|
**/
|
2008-03-08 09:43:31 -05:00
|
|
|
wxArrayString(size_t sz, const char** arr);
|
|
|
|
wxArrayString(size_t sz, const wchar_t** arr);
|
2022-08-03 12:28:06 -04:00
|
|
|
///@}
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-24 08:45:43 -04:00
|
|
|
Constructor from a wxString array. Pass a size @a sz and array @a arr.
|
2008-03-14 11:35:10 -04:00
|
|
|
*/
|
|
|
|
wxArrayString(size_t sz, const wxString* arr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor frees memory occupied by the array strings. For performance
|
2008-03-08 08:52:38 -05:00
|
|
|
reasons it is not virtual, so this class should not be derived from.
|
|
|
|
*/
|
|
|
|
~wxArrayString();
|
|
|
|
|
|
|
|
/**
|
2008-03-09 08:33:59 -04:00
|
|
|
Appends the given number of @a copies of the new item @a str to the
|
2008-03-08 08:52:38 -05:00
|
|
|
array and returns the index of the first new item in the array.
|
2008-03-14 11:35:10 -04:00
|
|
|
|
|
|
|
@see Insert()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
size_t Add(const wxString& str, size_t copies = 1);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-10-04 16:49:51 -04:00
|
|
|
Preallocates enough memory to store @a nCount items.
|
2008-03-14 11:35:10 -04:00
|
|
|
|
2008-10-04 16:49:51 -04:00
|
|
|
This function may be used to improve array class performance before
|
|
|
|
adding a known number of items consecutively.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void Alloc(size_t nCount);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Clears the array contents and frees memory.
|
2008-03-14 11:35:10 -04:00
|
|
|
|
|
|
|
@see Empty()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
/**
|
2008-03-14 11:35:10 -04:00
|
|
|
Empties the array: after a call to this function GetCount() will return 0.
|
2008-03-20 09:45:17 -04:00
|
|
|
However, this function does not free the memory used by the array and so
|
2008-03-14 11:35:10 -04:00
|
|
|
should be used when the array is going to be reused for storing other strings.
|
|
|
|
Otherwise, you should use Clear() to empty the array and free memory.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void Empty();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the number of items in the array.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
size_t GetCount() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2019-08-08 05:32:04 -04:00
|
|
|
Searches the array for @a str, starting from the beginning if @a bFromEnd
|
|
|
|
is @false or from the end otherwise. If @a bCase, comparison is case sensitive
|
2008-03-14 11:35:10 -04:00
|
|
|
(default), otherwise the case is ignored.
|
|
|
|
|
2008-03-14 11:51:35 -04:00
|
|
|
This function uses linear search for wxArrayString.
|
2019-08-08 05:32:04 -04:00
|
|
|
Returns the index of the first item matched or @c wxNOT_FOUND if there is no match.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2019-08-08 05:32:04 -04:00
|
|
|
int Index(const wxString& str, bool bCase = true, bool bFromEnd = false) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2019-08-08 05:32:04 -04:00
|
|
|
Inserts the given number of @a copies of @a str in the array before the
|
2019-08-10 09:09:59 -04:00
|
|
|
array element at the position @a nIndex. Thus, for example, to insert
|
|
|
|
the string in the beginning of the array you would write:
|
2008-03-14 11:35:10 -04:00
|
|
|
|
|
|
|
@code
|
|
|
|
Insert("foo", 0);
|
|
|
|
@endcode
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-24 08:45:43 -04:00
|
|
|
If @a nIndex is equal to GetCount() this function behaves as Add().
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2019-08-08 05:32:04 -04:00
|
|
|
void Insert(const wxString& str, size_t nIndex, size_t copies = 1);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the array is empty, @false otherwise. This function returns the
|
2008-03-24 08:45:43 -04:00
|
|
|
same result as GetCount() == 0 but is probably easier to read.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-23 21:02:55 -04:00
|
|
|
bool IsEmpty() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-23 21:02:55 -04:00
|
|
|
Return the array element at position @a nIndex. An assert failure will
|
2008-03-08 08:52:38 -05:00
|
|
|
result from an attempt to access an element beyond the end of array in debug
|
|
|
|
mode, but no check is done in release mode.
|
2008-03-14 11:35:10 -04:00
|
|
|
|
|
|
|
@see operator[] for the operator version.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2022-08-03 12:28:06 -04:00
|
|
|
///@{
|
2012-04-02 12:07:41 -04:00
|
|
|
wxString& Item(size_t nIndex);
|
|
|
|
const wxString& Item(size_t nIndex) const;
|
2022-08-03 12:28:06 -04:00
|
|
|
///@}
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the last element of the array. Attempt to access the last element of
|
|
|
|
an empty array will result in assert failure in debug build, however no checks
|
|
|
|
are done in release mode.
|
|
|
|
*/
|
2022-08-03 12:28:06 -04:00
|
|
|
///@{
|
2012-04-02 12:07:41 -04:00
|
|
|
wxString& Last();
|
|
|
|
const wxString& Last() const;
|
2022-08-03 12:28:06 -04:00
|
|
|
///@}
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Removes the first item matching this value. An assert failure is provoked by
|
|
|
|
an attempt to remove an element which does not exist in debug build.
|
2008-03-14 11:35:10 -04:00
|
|
|
|
|
|
|
@see Index()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void Remove(const wxString& sz);
|
|
|
|
|
|
|
|
/**
|
2008-03-09 08:33:59 -04:00
|
|
|
Removes @a count items starting at position @a nIndex from the array.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void RemoveAt(size_t nIndex, size_t count = 1);
|
|
|
|
|
|
|
|
/**
|
2008-10-04 16:49:51 -04:00
|
|
|
Releases the extra memory allocated by the array.
|
|
|
|
This function is useful to minimize the array memory consumption.
|
2008-03-14 11:35:10 -04:00
|
|
|
|
2008-10-04 16:49:51 -04:00
|
|
|
@see Alloc()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void Shrink();
|
|
|
|
|
2008-03-14 11:35:10 -04:00
|
|
|
/**
|
|
|
|
Sorts the array in alphabetical order or in reverse alphabetical order if
|
|
|
|
@a reverseOrder is @true. The sort is case-sensitive.
|
|
|
|
*/
|
|
|
|
void Sort(bool reverseOrder = false);
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2008-03-09 08:33:59 -04:00
|
|
|
Sorts the array using the specified @a compareFunction for item comparison.
|
2008-12-29 09:14:39 -05:00
|
|
|
@a CompareFunction is defined as a function taking two <em>const wxString&</em>
|
2008-03-20 09:45:17 -04:00
|
|
|
parameters and returning an @e int value less than, equal to or greater
|
2008-03-14 11:35:10 -04:00
|
|
|
than 0 if the first string is less than, equal to or greater than the
|
2008-03-08 08:52:38 -05:00
|
|
|
second one.
|
2008-03-14 11:35:10 -04:00
|
|
|
|
|
|
|
Example:
|
|
|
|
The following example sorts strings by their length.
|
|
|
|
|
|
|
|
@code
|
|
|
|
static int CompareStringLen(const wxString& first, const wxString& second)
|
|
|
|
{
|
|
|
|
return first.length() - second.length();
|
|
|
|
}
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-14 11:35:10 -04:00
|
|
|
...
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-14 11:35:10 -04:00
|
|
|
wxArrayString array;
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-14 11:35:10 -04:00
|
|
|
array.Add("one");
|
|
|
|
array.Add("two");
|
|
|
|
array.Add("three");
|
|
|
|
array.Add("four");
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-14 11:35:10 -04:00
|
|
|
array.Sort(CompareStringLen);
|
|
|
|
@endcode
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
void Sort(CompareFunction compareFunction);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Compares 2 arrays respecting the case. Returns @true if the arrays have
|
|
|
|
different number of elements or if the elements don't match pairwise.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool operator !=(const wxArrayString& array) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Assignment operator.
|
|
|
|
*/
|
2008-03-23 21:02:55 -04:00
|
|
|
wxArrayString& operator=(const wxArrayString&);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Compares 2 arrays respecting the case. Returns @true only if the arrays have
|
|
|
|
the same number of elements and the same strings in the same order.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool operator ==(const wxArrayString& array) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2019-08-08 05:32:04 -04:00
|
|
|
Returns the array element at position @a nIndex. An assert failure will
|
2008-03-14 11:35:10 -04:00
|
|
|
result from an attempt to access an element beyond the end of array in
|
|
|
|
debug mode, but no check is done in release mode.
|
|
|
|
|
|
|
|
This is the operator version of the Item() method.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-23 21:02:55 -04:00
|
|
|
wxString& operator[](size_t nIndex) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-14 11:51:35 -04:00
|
|
|
/**
|
|
|
|
@class wxSortedArrayString
|
|
|
|
|
|
|
|
wxSortedArrayString is an efficient container for storing wxString objects
|
2019-08-08 05:32:04 -04:00
|
|
|
which always keeps the strings in alphabetical order.
|
2008-03-14 11:51:35 -04:00
|
|
|
|
2013-08-07 07:08:17 -04:00
|
|
|
wxSortedArrayString uses binary search in its wxSortedArrayString::Index() method
|
2008-03-14 11:51:35 -04:00
|
|
|
(instead of linear search for wxArrayString::Index()) which makes it much more
|
|
|
|
efficient if you add strings to the array rarely (because, of course, you have
|
|
|
|
to pay for Index() efficiency by having Add() be slower) but search for them
|
|
|
|
often. Several methods should not be used with sorted array (basically, all
|
|
|
|
those which break the order of items) which is mentioned in their description.
|
|
|
|
|
|
|
|
@library{wxbase}
|
|
|
|
@category{containers}
|
|
|
|
|
|
|
|
@see wxArray, wxString, @ref overview_string
|
|
|
|
*/
|
2013-08-07 07:08:17 -04:00
|
|
|
class wxSortedArrayString : public wxArray
|
2008-03-14 11:51:35 -04:00
|
|
|
{
|
|
|
|
public:
|
2014-06-22 21:08:50 -04:00
|
|
|
/**
|
|
|
|
Default constructor.
|
|
|
|
|
|
|
|
The elements of the array are kept sorted in alphabetical order.
|
|
|
|
*/
|
|
|
|
wxSortedArrayString();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Constructs a sorted array using the specified @a compareFunction for
|
|
|
|
item comparison.
|
|
|
|
|
2014-06-23 08:02:09 -04:00
|
|
|
@see wxStringSortAscending(), wxDictionaryStringSortAscending()
|
|
|
|
|
2014-06-22 21:08:50 -04:00
|
|
|
@since 3.1.0
|
|
|
|
*/
|
|
|
|
wxSortedArrayString(CompareFunction compareFunction);
|
|
|
|
|
2008-03-14 11:51:35 -04:00
|
|
|
/**
|
2009-06-30 09:31:53 -04:00
|
|
|
Conversion constructor.
|
|
|
|
|
|
|
|
Constructs a sorted array with the same contents as the (possibly
|
2019-08-08 05:32:04 -04:00
|
|
|
unsorted) @a array argument.
|
2008-03-14 11:51:35 -04:00
|
|
|
*/
|
2009-06-30 09:31:53 -04:00
|
|
|
wxSortedArrayString(const wxArrayString& array);
|
2008-03-14 11:51:35 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
@copydoc wxArrayString::Add()
|
|
|
|
|
|
|
|
@warning
|
|
|
|
For sorted arrays, the index of the inserted item will not be, in general,
|
|
|
|
equal to GetCount() - 1 because the item is inserted at the correct position
|
|
|
|
to keep the array sorted and not appended.
|
|
|
|
*/
|
|
|
|
size_t Add(const wxString& str, size_t copies = 1);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@copydoc wxArrayString::Index()
|
|
|
|
|
2008-03-20 09:45:17 -04:00
|
|
|
This function uses binary search for wxSortedArrayString, but it ignores
|
2008-03-14 11:51:35 -04:00
|
|
|
the @a bCase and @a bFromEnd parameters.
|
|
|
|
*/
|
2019-08-08 05:32:04 -04:00
|
|
|
int Index(const wxString& str, bool bCase = true,
|
2008-10-27 17:26:54 -04:00
|
|
|
bool bFromEnd = false) const;
|
2008-03-14 11:51:35 -04:00
|
|
|
|
|
|
|
/**
|
2008-12-29 09:14:39 -05:00
|
|
|
@warning This function should not be used with sorted arrays because it
|
2008-03-14 11:51:35 -04:00
|
|
|
could break the order of items and, for example, subsequent calls
|
|
|
|
to Index() would then not work!
|
2009-07-01 04:56:31 -04:00
|
|
|
|
|
|
|
@warning In STL mode, Insert is private and simply invokes wxFAIL_MSG.
|
2008-03-14 11:51:35 -04:00
|
|
|
*/
|
|
|
|
void Insert(const wxString& str, size_t nIndex,
|
|
|
|
size_t copies = 1);
|
|
|
|
|
2022-08-03 12:28:06 -04:00
|
|
|
///@{
|
2008-03-14 11:51:35 -04:00
|
|
|
/**
|
2008-12-29 09:14:39 -05:00
|
|
|
@warning This function should not be used with sorted array because it could
|
2008-03-14 11:51:35 -04:00
|
|
|
break the order of items and, for example, subsequent calls to Index()
|
2008-03-21 15:06:04 -04:00
|
|
|
would then not work! Also, sorting a wxSortedArrayString doesn't make
|
|
|
|
sense because its elements are always already sorted.
|
2009-07-01 04:56:31 -04:00
|
|
|
|
|
|
|
@warning In STL mode, Sort is private and simply invokes wxFAIL_MSG.
|
2008-03-14 11:51:35 -04:00
|
|
|
*/
|
|
|
|
void Sort(bool reverseOrder = false);
|
|
|
|
void Sort(CompareFunction compareFunction);
|
2022-08-03 12:28:06 -04:00
|
|
|
///@}
|
2008-03-14 11:51:35 -04:00
|
|
|
};
|
|
|
|
|
2014-06-23 08:02:09 -04:00
|
|
|
/**
|
|
|
|
Comparison function comparing strings in alphabetical order.
|
|
|
|
|
|
|
|
This function can be used with wxSortedArrayString::Sort() or passed as an
|
|
|
|
argument to wxSortedArrayString constructor.
|
|
|
|
|
2018-04-09 17:35:00 -04:00
|
|
|
@see wxStringSortDescending(), wxDictionaryStringSortAscending(),
|
|
|
|
wxNaturalStringSortAscending()
|
2014-06-23 08:02:09 -04:00
|
|
|
|
|
|
|
@since 3.1.0
|
|
|
|
*/
|
|
|
|
int wxStringSortAscending(const wxString& s1, const wxString& s2);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Comparison function comparing strings in reverse alphabetical order.
|
|
|
|
|
|
|
|
This function can be used with wxSortedArrayString::Sort() or passed as an
|
|
|
|
argument to wxSortedArrayString constructor.
|
|
|
|
|
2018-04-09 17:35:00 -04:00
|
|
|
@see wxStringSortAscending(), wxDictionaryStringSortDescending(),
|
|
|
|
wxNaturalStringSortDescending()
|
2014-06-23 08:02:09 -04:00
|
|
|
|
|
|
|
@since 3.1.0
|
|
|
|
*/
|
|
|
|
int wxStringSortDescending(const wxString& s1, const wxString& s2);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Comparison function comparing strings in dictionary order.
|
|
|
|
|
|
|
|
The "dictionary order" differs from the alphabetical order in that the
|
|
|
|
strings differing not only in case are compared case-insensitively to
|
|
|
|
ensure that "Aa" comes before "AB" in the sorted array, unlike with
|
|
|
|
wxStringSortAscending().
|
|
|
|
|
|
|
|
This function can be used with wxSortedArrayString::Sort() or passed as an
|
|
|
|
argument to wxSortedArrayString constructor.
|
|
|
|
|
2018-04-09 17:35:00 -04:00
|
|
|
@see wxDictionaryStringSortDescending(),
|
|
|
|
wxStringSortAscending(),
|
|
|
|
wxNaturalStringSortAscending()
|
2020-07-02 12:15:25 -04:00
|
|
|
|
2014-06-23 08:02:09 -04:00
|
|
|
@since 3.1.0
|
|
|
|
*/
|
|
|
|
int wxDictionaryStringSortAscending(const wxString& s1, const wxString& s2);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Comparison function comparing strings in reverse dictionary order.
|
|
|
|
|
|
|
|
See wxDictionaryStringSortAscending() for the dictionary sort description.
|
|
|
|
|
2018-04-09 17:35:00 -04:00
|
|
|
@see wxDictionaryStringSortAscending(),
|
|
|
|
wxStringSortDescending(),
|
|
|
|
wxNaturalStringSortDescending()
|
2014-06-23 08:02:09 -04:00
|
|
|
|
|
|
|
@since 3.1.0
|
|
|
|
*/
|
2018-04-09 17:35:00 -04:00
|
|
|
int wxDictionaryStringSortDescending(const wxString& s1, const wxString& s2);
|
|
|
|
|
|
|
|
|
2020-07-02 12:15:25 -04:00
|
|
|
/**
|
|
|
|
Comparison function comparing strings in natural order.
|
|
|
|
|
|
|
|
This function can be used with wxSortedArrayString::Sort()
|
|
|
|
or passed as an argument to wxSortedArrayString constructor.
|
|
|
|
|
|
|
|
See wxCmpNatural() for more information about how natural
|
|
|
|
sort order is implemented.
|
|
|
|
|
|
|
|
@see wxNaturalStringSortDescending(),
|
|
|
|
wxStringSortAscending(), wxDictionaryStringSortAscending()
|
|
|
|
|
|
|
|
@since 3.1.4
|
|
|
|
*/
|
2018-04-09 17:35:00 -04:00
|
|
|
int wxNaturalStringSortAscending(const wxString& s1, const wxString& s2);
|
|
|
|
|
2020-07-02 12:15:25 -04:00
|
|
|
/**
|
|
|
|
Comparison function comparing strings in reverse natural order.
|
2018-04-09 17:35:00 -04:00
|
|
|
|
2020-07-02 12:15:25 -04:00
|
|
|
This function can be used with wxSortedArrayString::Sort()
|
|
|
|
or passed as an argument to wxSortedArrayString constructor.
|
|
|
|
|
|
|
|
See wxCmpNatural() for more information about how natural
|
|
|
|
sort order is implemented.
|
|
|
|
|
|
|
|
@see wxNaturalStringSortAscending(),
|
|
|
|
wxStringSortDescending(), wxDictionaryStringSortDescending()
|
|
|
|
|
|
|
|
@since 3.1.4
|
|
|
|
*/
|
2018-04-09 17:35:00 -04:00
|
|
|
int wxNaturalStringSortDescending(const wxString& s1, const wxString& s2);
|
|
|
|
|
2020-07-02 12:15:25 -04:00
|
|
|
/**
|
|
|
|
This function compares strings using case-insensitive collation and
|
|
|
|
additionally, numbers within strings are recognised and compared
|
|
|
|
numerically, rather than alphabetically. When used for sorting,
|
|
|
|
the result is that e.g. file names containing numbers are sorted
|
|
|
|
in a natural way.
|
|
|
|
|
|
|
|
For example, sorting with a simple string comparison results in:
|
|
|
|
- file1.txt
|
|
|
|
- file10.txt
|
|
|
|
- file100.txt
|
|
|
|
- file2.txt
|
|
|
|
- file20.txt
|
|
|
|
- file3.txt
|
|
|
|
|
|
|
|
But sorting the same strings in natural sort order results in:
|
|
|
|
- file1.txt
|
|
|
|
- file2.txt
|
|
|
|
- file3.txt
|
|
|
|
- file10.txt
|
|
|
|
- file20.txt
|
|
|
|
- file100.txt
|
|
|
|
|
|
|
|
wxCmpNatural() uses an OS native natural sort function when available
|
|
|
|
(currently only under Microsoft Windows), wxCmpNaturalGeneric() otherwise.
|
|
|
|
|
|
|
|
Be aware that OS native implementations might differ from each other,
|
|
|
|
and might change behaviour from release to release.
|
|
|
|
|
|
|
|
@see wxNaturalStringSortAscending(), wxNaturalStringSortDescending()
|
|
|
|
|
|
|
|
@since 3.1.4
|
|
|
|
*/
|
|
|
|
int wxCmpNatural(const wxString& s1, const wxString& s2);
|
2018-04-09 17:35:00 -04:00
|
|
|
|
2020-07-02 12:15:25 -04:00
|
|
|
/**
|
|
|
|
This is wxWidgets' own implementation of the natural sort comparison function.
|
2018-04-09 17:35:00 -04:00
|
|
|
|
2020-07-02 12:15:25 -04:00
|
|
|
@see wxCmpNatural()
|
2018-04-09 17:35:00 -04:00
|
|
|
|
2020-07-02 12:15:25 -04:00
|
|
|
@since 3.1.4
|
|
|
|
*/
|
|
|
|
int wxCmpNaturalGeneric(const wxString& s1, const wxString& s2);
|
2018-04-09 17:35:00 -04:00
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
// ============================================================================
|
|
|
|
// Global functions/macros
|
|
|
|
// ============================================================================
|
|
|
|
|
2009-01-05 15:48:06 -05:00
|
|
|
/** @addtogroup group_funcmacro_string */
|
2022-08-03 12:28:06 -04:00
|
|
|
///@{
|
2008-03-14 11:35:10 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2008-03-09 08:33:59 -04:00
|
|
|
Splits the given wxString object using the separator @a sep and returns the
|
2008-03-08 08:52:38 -05:00
|
|
|
result as a wxArrayString.
|
2008-03-14 11:35:10 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
If the @a escape character is non-@NULL, then the occurrences of @a sep
|
2008-03-14 11:35:10 -04:00
|
|
|
immediately prefixed with @a escape are not considered as separators.
|
2008-03-08 08:52:38 -05:00
|
|
|
Note that empty tokens will be generated if there are two or more adjacent
|
|
|
|
separators.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
@see wxJoin()
|
2008-03-25 03:36:12 -04:00
|
|
|
|
|
|
|
@header{wx/arrstr.h}
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
wxArrayString wxSplit(const wxString& str, const wxChar sep,
|
2008-03-14 11:35:10 -04:00
|
|
|
const wxChar escape = '\\');
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-14 11:35:10 -04:00
|
|
|
Concatenate all lines of the given wxArrayString object using the separator
|
|
|
|
@a sep and returns the result as a wxString.
|
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
If the @a escape character is non-@NULL, then it's used as prefix for each
|
2008-03-24 08:45:43 -04:00
|
|
|
occurrence of @a sep in the strings contained in @a arr before joining them
|
2008-03-25 03:36:12 -04:00
|
|
|
which is necessary in order to be able to recover the original array
|
2021-04-06 05:31:12 -04:00
|
|
|
contents from the string later using wxSplit(). The @a escape characters
|
|
|
|
themselves are @e not escaped when they occur in the middle of the @a arr
|
|
|
|
elements, but @e are escaped when they occur at the end, i.e.
|
|
|
|
@code
|
|
|
|
wxArrayString arr;
|
|
|
|
arr.push_back("foo^");
|
|
|
|
arr.push_back("bar^baz");
|
|
|
|
wxPuts(wxJoin(arr, ':', '^')); // prints "foo^^:bar^baz"
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
In any case, applying wxSplit() to the result of wxJoin() is guaranteed to
|
|
|
|
recover the original array.
|
2008-03-14 11:35:10 -04:00
|
|
|
|
|
|
|
@see wxSplit()
|
2008-03-25 03:36:12 -04:00
|
|
|
|
|
|
|
@header{wx/arrstr.h}
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
wxString wxJoin(const wxArrayString& arr, const wxChar sep,
|
2008-03-14 11:35:10 -04:00
|
|
|
const wxChar escape = '\\');
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2022-08-03 12:28:06 -04:00
|
|
|
///@}
|
2008-03-25 03:36:12 -04:00
|
|
|
|