Return to Index

StringArray

This class implements a simple interface for working with arrays of strings. It is nothing more than a vector of strings (i.e. Vector‹ String ›), except that a few convenience functions are provided. Traversing the elements in a string array involves a simple for loop:
   StringArray args;
   ...
   for (int i=0;i ‹ args.length();i++)
     printf("%s\n", args[i].cStr());


Method Summary:
StringArray::StringArray(int (=0) size);
StringArray& StringArray::operator=(const StringArray& array);
String StringArray::operator[](int i);
String& StringArray::operator[](int i);
void StringArray::prepend(const String& s);
void StringArray::append(const String& s);
void StringArray::insert(const String& s, int index);
int StringArray::find(const String& s);
void StringArray::remove(const String& s);
void StringArray::remove(int index);
void StringArray::clear();
void StringArray::preAlloc(int size);
int StringArray::length();
int StringArray::capacity();
StringArray StringArray::make(int n, ... .);



StringArray::StringArray
StringArray::StringArray(int (=0) size);

Constructs a new string array optionally of the specified size.
Parameters:
int (=0) sizeThe initial capacity of the string array. Defaults to 0.

StringArray& StringArray::operator=
StringArray& StringArray::operator=(const StringArray& array);

Assigns one string array to another.
Parameters:
const StringArray& arrayThe StringArray to assign.

String StringArray::operator[]
String StringArray::operator[](int i);

Indexing operator to return strings in the array.
   String str = args[2];
Parameters:
int iSpecifies which string to return.

String& StringArray::operator[]
String& StringArray::operator[](int i);

Indexing operator to allow for assignment into the array.
   args[2] = "Hello!";
Parameters:
int iSpecifies which string to return a reference to.

void StringArray::prepend
void StringArray::prepend(const String& s);

Prepends the specified string to the beginning of the array, shifting the other elements down.
Parameters:
const String& sThe string to prepend.

void StringArray::append
void StringArray::append(const String& s);

Appends the specified string to the end of the array, increasing the capacity of the array if necessary.
Parameters:
const String& sThe string to append.

void StringArray::insert
void StringArray::insert(const String& s, int index);

Inserts a string to a specified location in the array, increasing the capacity of the array if necessary.
Parameters:
const String& sThe string to insert.
int indexThe insertion index.

int StringArray::find
int StringArray::find(const String& s);

Searches the array for a string.

Returns: Returns the index of the first occurence if found, otherwise returns -1.
Parameters:
const String& sThe string to search for.

void StringArray::remove
void StringArray::remove(const String& s);

Removes the first occurrence of the specified string, if it is found.
Parameters:
const String& sThe string to find and remove.

void StringArray::remove
void StringArray::remove(int index);

Removes the string at the given index.
Parameters:
int indexThe index of the string to remove.

void StringArray::clear
void StringArray::clear();

Empties the string array.

void StringArray::preAlloc
void StringArray::preAlloc(int size);

Increases the capacity of the string array to the given size.
Parameters:
int sizeThe new capacity of the array.

int StringArray::length
int StringArray::length();

Returns the number of strings in the array.

int StringArray::capacity
int StringArray::capacity();

Returns the capacity of the array. Note that this not necessarily the same as length() .

StringArray StringArray::make
StringArray StringArray::make(int n, ... .);

A static function that creates a string array from a var-arg list of c-strings.
Parameters:
int nThe number of strings in the list.
... .A variable-length list of char* arguments.


Generated automatically by docgen 0.0.1
© 2003 Aron Dobos