| ## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# csStringArray Class Reference

An array of strings. More...

`#include <csutil/stringarray.h>`

Inheritance diagram for csStringArray:

[legend]
List of all members.

## Public Types
enum | ConsecutiveDelimiterMode { delimSplitEach, delimIgnore, delimIgnoreDifferent }
| Mode how SplitString() treats consecutive occurance of delimiters. More...
| delimIgnore
| Ignore consecutive delimiters (except the first).
| delimIgnoreDifferent
| Only ignore consecutive delimiters if they're different.
| delimSplitEach
| Split at each different delimiter.
## Public Member Functions
size_t | Contains (const char *str, bool case_sensitive=true) const
| Alias for Find() and FindCaseInsensitive().
| csStringArray (size_t limit=0, size_t threshold=0)
| Initialize object to hold initially `limit` elements, and increase storage by `threshold` each time the upper bound is exceeded.
size_t | Find (const char *str) const
| Find a string, case-sensitive.
size_t | FindCaseInsensitive (const char *str) const
| Find a string, case-insensitive.
size_t | FindSortedKey (char const *key, bool case_sensitive=true, size_t *candidate=0) const
| Find an element.
size_t | FindSortedKey (csArrayCmp< char const *, char const * > comparekey, size_t *candidate=0) const
| Find an element based on some key, using a comparison function.
size_t | InsertSorted (const char *item, bool case_sensitive=true, size_t *equal_index=0)
| Insert an element at a sorted position.
char * | Pop ()
| Pop an element from tail end of array.
void | Sort (bool case_sensitive=true)
| Sort array.
void | Sort (int(*compare)(char const *const &, char const *const &))
| Sort array based on comparison function.
size_t | SplitString (const char *str, const char *delimiters, ConsecutiveDelimiterMode delimMode=delimSplitEach)
| Add a number of strings to this array by splitting str at characters from delimiters.
## Static Public Member Functions
static int | CaseInsensitiveCompare (const char *const &item1, const char *const &item2)
| Case-insensitive comparision function for strings.
static int | CaseSensitiveCompare (const char *const &item1, const char *const &item2)
| Case-sensitive comparision function for strings.

## Detailed Description

An array of strings.

This array will properly make copies of the strings and later delete those copies via delete[].

Definition at line 56 of file stringarray.h.

## Member Enumeration Documentation

enum csStringArray::ConsecutiveDelimiterMode

Mode how SplitString() treats consecutive occurance of delimiters.

Enumerator:

  delimSplitEach | Split at each different delimiter.
  delimIgnore | Ignore consecutive delimiters (except the first). In other words, any number of consecutive delimiters is treated like there was only one delimiter.
  delimIgnoreDifferent | Only ignore consecutive delimiters if they're different.

Definition at line 205 of file stringarray.h.

## Constructor & Destructor Documentation

csStringArray::csStringArray | ( | size_t | limit = `0`,
|  | size_t | threshold = `0` |
| ) |  |  | `[inline]`

Initialize object to hold initially `limit` elements, and increase storage by `threshold` each time the upper bound is exceeded.

Definition at line 66 of file stringarray.h.

## Member Function Documentation

static int csStringArray::CaseInsensitiveCompare | ( | const char *const & | item1,
|  | const char *const & | item2 |
| ) |  |  | `[inline, static]`

Case-insensitive comparision function for strings.

Definition at line 79 of file stringarray.h.

References csStrCaseCmp().

Referenced by FindSortedKey(), InsertSorted(), and Sort().

static int csStringArray::CaseSensitiveCompare | ( | const char *const & | item1,
|  | const char *const & | item2 |
| ) |  |  | `[inline, static]`

Case-sensitive comparision function for strings.

Definition at line 72 of file stringarray.h.

Referenced by FindSortedKey(), InsertSorted(), and Sort().

size_t csStringArray::Contains | ( | const char * | str,
|  | bool | case_sensitive = `true` |
| ) |  |  | const`[inline]`

Alias for Find() and FindCaseInsensitive().

Parameters:

  | str | String to look for in array.
  | case_sensitive | If true, consider case when performing comparison. (default: yes)

Returns:
  csArrayItemNotFound if not found, else item index.

Remarks:
  Works with sorted and unsorted arrays, but FindSortedKey() is faster on sorted arrays.

  Some people find Contains() more idiomatic than Find().

Definition at line 197 of file stringarray.h.

References Find(), and FindCaseInsensitive().

Referenced by scfStringArray::Contains().

size_t csStringArray::Find | ( | const char * | str | ) | const`[inline]`

Find a string, case-sensitive.

Returns:
  csArrayItemNotFound if not found, else item index.

Remarks:
  Works with sorted and unsorted arrays, but FindSortedKey() is faster on sorted arrays.

Definition at line 164 of file stringarray.h.

References csArray< const char *, csStringArrayElementHandler >::Get(), and csArray< const char *, csStringArrayElementHandler >::GetSize().

Referenced by Contains(), and scfStringArray::Find().

size_t csStringArray::FindCaseInsensitive | ( | const char * | str | ) | const`[inline]`

Find a string, case-insensitive.

Returns:
  csArrayItemNotFound if not found, else item index.

Remarks:
  Works with sorted and unsorted arrays, but FindSortedKey() is faster on sorted arrays.

Definition at line 178 of file stringarray.h.

References csStrCaseCmp(), csArray< const char *, csStringArrayElementHandler >::Get(), and csArray< const char *, csStringArrayElementHandler >::GetSize().

Referenced by Contains(), and scfStringArray::FindCaseInsensitive().

size_t csStringArray::FindSortedKey | ( | char const * | key,
|  | bool | case_sensitive = `true`,
|  | size_t * | candidate = `0` |
| ) |  |  | const`[inline]`

Find an element.

Returns:
  csArrayItemNotFound if not found, else item index.

Remarks:
  The array must be sorted.

Definition at line 122 of file stringarray.h.

References CaseInsensitiveCompare(), CaseSensitiveCompare(), and FindSortedKey().

size_t csStringArray::FindSortedKey | ( | csArrayCmp< char const *, char const * > | comparekey,
|  | size_t * | candidate = `0` |
| ) |  |  | const`[inline]`

Find an element based on some key, using a comparison function.

Returns:
  csArrayItemNotFound if not found, else item index.

Remarks:
  The array must be sorted.

Definition at line 111 of file stringarray.h.

References csArray< const char *, csStringArrayElementHandler >::FindSortedKey().

Referenced by FindSortedKey(), and scfStringArray::FindSortedKey().

size_t csStringArray::InsertSorted | ( | const char * | item,
|  | bool | case_sensitive = `true`,
|  | size_t * | equal_index = `0` |
| ) |  |  | `[inline]`

Insert an element at a sorted position.

Remarks:
  Assumes array is already sorted.

Definition at line 135 of file stringarray.h.

References CaseInsensitiveCompare(), CaseSensitiveCompare(), and csArray< const char *, csStringArrayElementHandler >::InsertSorted().

char* csStringArray::Pop | ( |  | ) | `[inline]`

Pop an element from tail end of array.

Remarks:
  Caller is responsible for invoking delete[] on the returned string when no longer needed.

Reimplemented from csArray< const char *, csStringArrayElementHandler >.

Definition at line 148 of file stringarray.h.

References CS_ASSERT, csArray< const char *, csStringArrayElementHandler >::Get(), csArray< const char *, csStringArrayElementHandler >::GetSize(), csArray< const char *, csStringArrayElementHandler >::InitRegion(), and csArray< const char *, csStringArrayElementHandler >::SetSize().

Referenced by scfStringArray::Pop().

void csStringArray::Sort | ( | bool | case_sensitive = `true` | ) | `[inline]`

Sort array.

Parameters:

  | case_sensitive | If true, consider case when performing comparison. (default: yes)

Definition at line 98 of file stringarray.h.

References CaseInsensitiveCompare(), CaseSensitiveCompare(), and Sort().

void csStringArray::Sort | ( | int(*)(char const *const &, char const *const &) | compare | ) | `[inline]`

Sort array based on comparison function.

Reimplemented from csArray< const char *, csStringArrayElementHandler >.

Definition at line 88 of file stringarray.h.

References csArray< const char *, csStringArrayElementHandler >::Sort().

Referenced by Sort(), and scfStringArray::Sort().

size_t csStringArray::SplitString | ( | const char * | str,
|  | const char * | delimiters,
|  | ConsecutiveDelimiterMode | delimMode = `delimSplitEach` |
| ) |  |  | `[inline]`

Add a number of strings to this array by splitting str at characters from delimiters.

Definition at line 224 of file stringarray.h.

References csStringBase::Append(), delimIgnore, delimIgnoreDifferent, delimSplitEach, and csArray< const char *, csStringArrayElementHandler >::Push().

The documentation for this class was generated from the following file:

- csutil/stringarray.h