wxWidgets: interface/wx/arrstr.h File Reference

| Version: 3.1.5

Loading...
Searching...
No Matches
Classes | Functions
arrstr.h File Reference

## Classes
class | wxArrayString
| wxArrayString is an efficient container for storing wxString objects. More...
class | wxSortedArrayString
| wxSortedArrayString is an efficient container for storing wxString objects which always keeps the strings in alphabetical order. More...

## Functions
int | wxStringSortAscending (const wxString &s1, const wxString &s2)
| Comparison function comparing strings in alphabetical order.
int | wxStringSortDescending (const wxString &s1, const wxString &s2)
| Comparison function comparing strings in reverse alphabetical order.
int | wxDictionaryStringSortAscending (const wxString &s1, const wxString &s2)
| Comparison function comparing strings in dictionary order.
int | wxDictionaryStringSortDescending (const wxString &s1, const wxString &s2)
| Comparison function comparing strings in reverse dictionary order.
int | wxNaturalStringSortAscending (const wxString &s1, const wxString &s2)
| Comparison function comparing strings in natural order.
int | wxNaturalStringSortDescending (const wxString &s1, const wxString &s2)
| Comparison function comparing strings in reverse natural order.
int | wxCmpNatural (const wxString &s1, const wxString &s2)
| This function compares strings using case-insensitive collation and additionally, numbers within strings are recognised and compared numerically, rather than alphabetically.
int | wxCmpNaturalGeneric (const wxString &s1, const wxString &s2)
| This is wxWidgets' own implementation of the natural sort comparison function.
wxArrayString | wxSplit (const wxString &str, const wxChar sep, const wxChar escape='\\')
| Splits the given wxString object using the separator sep and returns the result as a wxArrayString.
wxString | wxJoin (const wxArrayString &arr, const wxChar sep, const wxChar escape='\\')
| Concatenate all lines of the given wxArrayString object using the separator sep and returns the result as a wxString.

## Function Documentation

## ◆ wxCmpNatural()

int wxCmpNatural | ( | const wxString & | s1,
|  | const wxString & | s2 )

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 also
  wxNaturalStringSortAscending(), wxNaturalStringSortDescending()

Since
  3.1.4

## ◆ wxCmpNaturalGeneric()

int wxCmpNaturalGeneric | ( | const wxString & | s1,
|  | const wxString & | s2 )

This is wxWidgets' own implementation of the natural sort comparison function.

See also
  wxCmpNatural()

Since
  3.1.4

## ◆ wxDictionaryStringSortAscending()

int wxDictionaryStringSortAscending | ( | 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.

See also
  wxDictionaryStringSortDescending(), wxStringSortAscending(), wxNaturalStringSortAscending()

Since
  3.1.0

## ◆ wxDictionaryStringSortDescending()

int wxDictionaryStringSortDescending | ( | const wxString & | s1,
|  | const wxString & | s2 )

Comparison function comparing strings in reverse dictionary order.

See wxDictionaryStringSortAscending() for the dictionary sort description.

See also
  wxDictionaryStringSortAscending(), wxStringSortDescending(), wxNaturalStringSortDescending()

Since
  3.1.0

## ◆ wxJoin()

wxString wxJoin | ( | const wxArrayString & | arr,
|  | const wxChar | sep,
|  | const wxChar | escape = '\\' )

Concatenate all lines of the given wxArrayString object using the separator sep and returns the result as a wxString.

If the escape character is non-NULL, then it's used as prefix for each occurrence of sep in the strings contained in arr before joining them which is necessary in order to be able to recover the original array contents from the string later using wxSplit(). The escape characters themselves are not escaped when they occur in the middle of the arr elements, but are escaped when they occur at the end, i.e.

wxArrayString arr;
arr.push_back("foo^");
arr.push_back("bar^baz");
wxPuts(wxJoin(arr, ':', '^')); // prints "foo^^:bar^baz"
wxJoin
wxString wxJoin(const wxArrayString &arr, const wxChar sep, const wxChar escape='\\')
Concatenate all lines of the given wxArrayString object using the separator sep and returns the resul...
wxArrayString
wxArrayString is an efficient container for storing wxString objects.
Definition arrstr.h:54

In any case, applying wxSplit() to the result of wxJoin() is guaranteed to recover the original array.

See also
  wxSplit()

Include file:

    #include <wx/arrstr.h>

## ◆ wxNaturalStringSortAscending()

int wxNaturalStringSortAscending | ( | const wxString & | s1,
|  | const wxString & | s2 )

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 also
  wxNaturalStringSortDescending(), wxStringSortAscending(), wxDictionaryStringSortAscending()

Since
  3.1.4

## ◆ wxNaturalStringSortDescending()

int wxNaturalStringSortDescending | ( | const wxString & | s1,
|  | const wxString & | s2 )

Comparison function comparing strings in reverse 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 also
  wxNaturalStringSortAscending(), wxStringSortDescending(), wxDictionaryStringSortDescending()

Since
  3.1.4

## ◆ wxSplit()

wxArrayString wxSplit | ( | const wxString & | str,
|  | const wxChar | sep,
|  | const wxChar | escape = '\\' )

Splits the given wxString object using the separator sep and returns the result as a wxArrayString.

If the escape character is non-NULL, then the occurrences of sep immediately prefixed with escape are not considered as separators. Note that empty tokens will be generated if there are two or more adjacent separators.

See also
  wxJoin()

Include file:

    #include <wx/arrstr.h>

## ◆ wxStringSortAscending()

int wxStringSortAscending | ( | const wxString & | s1,
|  | const wxString & | s2 )

Comparison function comparing strings in alphabetical order.

This function can be used with wxSortedArrayString::Sort() or passed as an argument to wxSortedArrayString constructor.

See also
  wxStringSortDescending(), wxDictionaryStringSortAscending(), wxNaturalStringSortAscending()

Since
  3.1.0

## ◆ wxStringSortDescending()

int wxStringSortDescending | ( | 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.

See also
  wxStringSortAscending(), wxDictionaryStringSortDescending(), wxNaturalStringSortDescending()

Since
  3.1.0