OGR
|
String list class designed around our use of C "char**" string lists. More...
#include <cpl_string.h>
Public Member Functions | |
CPLStringList (char **papszList, int bTakeOwnership=TRUE) | |
CPLStringList (const CPLStringList &oOther) | |
Copy constructor. | |
CPLStringList & | Clear () |
int | size () const |
int | Count () const |
bool | empty () const |
CPLStringList & | AddString (const char *pszNewString) |
CPLStringList & | AddStringDirectly (char *pszNewString) |
CPLStringList & | InsertString (int nInsertAtLineNo, const char *pszNewLine) |
Insert into the list at identified location. More... | |
CPLStringList & | InsertStringDirectly (int nInsertAtLineNo, char *pszNewLine) |
int | FindString (const char *pszTarget) const |
int | PartialFindString (const char *pszNeedle) const |
int | FindName (const char *pszName) const |
bool | FetchBool (const char *pszKey, bool bDefault) const |
int | FetchBoolean (const char *pszKey, int bDefault) const |
const char * | FetchNameValue (const char *pszKey) const |
const char * | FetchNameValueDef (const char *pszKey, const char *pszDefault) const |
CPLStringList & | AddNameValue (const char *pszKey, const char *pszValue) |
CPLStringList & | SetNameValue (const char *pszKey, const char *pszValue) |
CPLStringList & | Assign (char **papszListIn, int bTakeOwnership=TRUE) |
CPLStringList & | operator= (char **papszListIn) |
CPLStringList & | operator= (const CPLStringList &oOther) |
char * | operator[] (int i) |
char * | operator[] (size_t i) |
const char * | operator[] (int i) const |
const char * | operator[] (size_t i) const |
char ** | List () |
char ** | StealList () |
CPLStringList & | Sort () |
int | IsSorted () const |
operator char ** (void) | |
String list class designed around our use of C "char**" string lists.
CPLStringList::CPLStringList | ( | char ** | papszListIn, |
int | bTakeOwnership = TRUE |
||
) |
CPLStringList constructor.
papszListIn | the NULL terminated list of strings to consume. |
bTakeOwnership | TRUE if the CPLStringList should take ownership of the list of strings which implies responsibility to free them. |
References Assign().
CPLStringList & CPLStringList::AddNameValue | ( | const char * | pszKey, |
const char * | pszValue | ||
) |
Add a name=value entry to the list.
A key=value string is prepared and appended to the list. There is no check for other values for the same key in the list.
pszKey | the key name to add. |
pszValue | the key value to add. |
References AddStringDirectly(), CPLAssert, CPLMalloc(), InsertStringDirectly(), and IsSorted().
Referenced by SetNameValue().
CPLStringList & CPLStringList::AddString | ( | const char * | pszNewString | ) |
Add a string to the list.
A copy of the passed in string is made and inserted in the list.
pszNewString | the string to add to the list. |
References AddStringDirectly(), and CPLStrdup().
Referenced by CSLTokenizeString2(), GOA2GetAccessToken(), GOA2GetRefreshToken(), OGRFeature::SetField(), and VSIReadDirRecursive().
CPLStringList & CPLStringList::AddStringDirectly | ( | char * | pszNewString | ) |
Add a string to the list.
This method is similar to AddString(), but ownership of the pszNewString is transferred to the CPLStringList class.
pszNewString | the string to add to the list. |
References Count().
Referenced by AddNameValue(), and AddString().
CPLStringList & CPLStringList::Assign | ( | char ** | papszListIn, |
int | bTakeOwnership = TRUE |
||
) |
Assign a list of strings.
papszListIn | the NULL terminated list of strings to consume. |
bTakeOwnership | TRUE if the CPLStringList should take ownership of the list of strings which implies responsibility to free them. |
References Clear().
Referenced by CPLStringList(), CSLTokenizeString2(), and operator=().
CPLStringList & CPLStringList::Clear | ( | ) |
int CPLStringList::Count | ( | ) | const |
References CSLCount().
Referenced by AddStringDirectly(), CSLTokenizeString2(), InsertStringDirectly(), operator[](), SetNameValue(), and Sort().
|
inline |
Return whether the list is empty.
bool CPLStringList::FetchBool | ( | const char * | pszKey, |
bool | bDefault | ||
) | const |
Check for boolean key value.
In a CPLStringList of "Name=Value" pairs, look to see if there is a key with the given name, and if it can be interpreted as being TRUE. If the key appears without any "=Value" portion it will be considered true. If the value is NO, FALSE or 0 it will be considered FALSE otherwise if the key appears in the list it will be considered TRUE. If the key doesn't appear at all, the indicated default value will be returned.
pszKey | the key value to look for (case insensitive). |
bDefault | the value to return if the key isn't found at all. |
References CPLTestBool(), and FetchNameValue().
Referenced by FetchBoolean().
int CPLStringList::FetchBoolean | ( | const char * | pszKey, |
int | bDefault | ||
) | const |
DEPRECATED: Check for boolean key value.
In a CPLStringList of "Name=Value" pairs, look to see if there is a key with the given name, and if it can be interpreted as being TRUE. If the key appears without any "=Value" portion it will be considered true. If the value is NO, FALSE or 0 it will be considered FALSE otherwise if the key appears in the list it will be considered TRUE. If the key doesn't appear at all, the indicated default value will be returned.
pszKey | the key value to look for (case insensitive). |
bDefault | the value to return if the key isn't found at all. |
References FetchBool().
const char * CPLStringList::FetchNameValue | ( | const char * | pszName | ) | const |
Fetch value associated with this key name.
If this list sorted, a fast binary search is done, otherwise a linear scan is done. Name lookup is case insensitive.
pszName | the key name to search for. |
References CPLAssert, and FindName().
Referenced by FetchBool(), and FetchNameValueDef().
const char * CPLStringList::FetchNameValueDef | ( | const char * | pszName, |
const char * | pszDefault | ||
) | const |
Fetch value associated with this key name.
If this list sorted, a fast binary search is done, otherwise a linear scan is done. Name lookup is case insensitive.
pszName | the key name to search for. |
pszDefault | the default value returned if the named entry isn't found. |
References FetchNameValue().
Referenced by GOA2GetAccessToken(), and GOA2GetRefreshToken().
int CPLStringList::FindName | ( | const char * | pszKey | ) | const |
Get index of given name/value keyword.
Note that this search is for a line in the form name=value or name:value. Use FindString() or PartialFindString() for searches not based on name=value pairs.
pszKey | the name to search for. |
References CSLFindName(), EQUALN, and IsSorted().
Referenced by FetchNameValue(), and SetNameValue().
|
inline |
Return index of pszTarget in the list, or -1
References CSLFindString().
|
inline |
Insert into the list at identified location.
This method will insert a string into the list at the identified location. The insertion point must be within or at the end of the list. The following entries are pushed down to make space.
nInsertAtLineNo | the line to insert at, zero to insert at front. |
pszNewLine | to the line to insert. This string will be copied. |
References CPLStrdup().
CPLStringList & CPLStringList::InsertStringDirectly | ( | int | nInsertAtLineNo, |
char * | pszNewLine | ||
) |
Insert into the list at identified location.
This method will insert a string into the list at the identified location. The insertion point must be within or at the end of the list. The following entries are pushed down to make space.
nInsertAtLineNo | the line to insert at, zero to insert at front. |
pszNewLine | to the line to insert, the ownership of this string will be taken over the by the object. It must have been allocated on the heap. |
References Count(), CPLE_AppDefined, and CPLError().
Referenced by AddNameValue().
|
inline |
Returns whether the list is sorted
Referenced by AddNameValue(), and FindName().
|
inline |
Return list. Ownership remains to the object
Referenced by CSLTokenizeString2(), and OGRFeature::SetField().
|
inline |
Return lists
|
inline |
Assignment operator
CPLStringList & CPLStringList::operator= | ( | const CPLStringList & | oOther | ) |
Assignment operator
References Assign().
char * CPLStringList::operator[] | ( | int | i | ) |
Return string at specified index
Fetch entry "i".
Fetches the requested item in the list. Note that the returned string remains owned by the CPLStringList. If "i" is out of range NULL is returned.
i | the index of the list item to return. |
References Count().
|
inline |
Return string at specified index
const char * CPLStringList::operator[] | ( | int | i | ) | const |
Return string at specified index
References Count().
|
inline |
Return string at specified index
|
inline |
Return index of pszTarget in the list (using partial search), or -1
References CSLPartialFindString().
CPLStringList & CPLStringList::SetNameValue | ( | const char * | pszKey, |
const char * | pszValue | ||
) |
Set name=value entry in the list.
Similar to AddNameValue(), except if there is already a value for the key in the list it is replaced instead of adding a new entry to the list. If pszValue is NULL any existing key entry is removed.
pszKey | the key name to add. |
pszValue | the key value to add. |
References AddNameValue(), Count(), CPLFree, CPLMalloc(), and FindName().
|
inline |
Return size of list
CPLStringList & CPLStringList::Sort | ( | ) |
Sort the entries in the list and mark list sorted.
Note that once put into "sorted" mode, the CPLStringList will attempt to keep things in sorted order through calls to AddString(), AddStringDirectly(), AddNameValue(), SetNameValue(). Complete list assignments (via Assign() and operator= will clear the sorting state. When in sorted order FindName(), FetchNameValue() and FetchNameValueDef() will do a binary search to find the key, substantially improve lookup performance in large lists.
References Count().
char ** CPLStringList::StealList | ( | ) |
Seize ownership of underlying string array.
This method is similar to List(), except that the returned list is now owned by the caller and the CPLStringList is emptied.
Referenced by CSLTokenizeString2(), and VSIReadDirRecursive().