Loading...
Searching...
No Matches
juce::StringPairArray Class Reference

## Detailed Description

A container for holding a set of strings which are keyed by another string.

See also
  StringArray

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

- juce_core/text/juce_StringPairArray.h

## Public Member Functions

| StringPairArray (bool ignoreCaseWhenComparingKeys=true)
| Creates an empty array.
| StringPairArray (const StringPairArray &other)
| Creates a copy of another array.
| ~StringPairArray ()=default
| Destructor.
StringPairArray & | operator= (const StringPairArray &other)
| Copies the contents of another string array into this one.
bool | operator== (const StringPairArray &other) const
| Compares two arrays.
bool | operator!= (const StringPairArray &other) const
| Compares two arrays.
const String & | operator[] (StringRef key) const
| Finds the value corresponding to a key string.
String | getValue (StringRef, const String &defaultReturnValue) const
| Finds the value corresponding to a key string.
bool | containsKey (StringRef key) const noexcept
| Returns true if the given key exists.
const StringArray & | getAllKeys () const noexcept
| Returns a list of all keys in the array.
const StringArray & | getAllValues () const noexcept
| Returns a list of all values in the array.
int | size () const noexcept
| Returns the number of strings in the array.
void | set (const String &key, const String &value)
| Adds or amends a key/value pair.
void | addArray (const StringPairArray &other)
| Adds the items from another array to this one.
void | clear ()
| Removes all elements from the array.
void | remove (StringRef key)
| Removes a string from the array based on its key.
void | remove (int index)
| Removes a string from the array based on its index.
void | setIgnoresCase (bool shouldIgnoreCase)
| Indicates whether to use a case-insensitive search when looking up a key string.
bool | getIgnoresCase () const noexcept
| Indicates whether a case-insensitive search is used when looking up a key string.
String | getDescription () const
| Returns a descriptive string containing the items.
void | minimiseStorageOverheads ()
| Reduces the amount of storage being used by the array.
void | addMap (const std::map< String, String > &mapToAdd)
| Adds the contents of a map to this StringPairArray.
void | addUnorderedMap (const std::unordered_map< String, String > &mapToAdd)
| Adds the contents of an unordered map to this StringPairArray.

## Constructors and Destructors

## StringPairArray() [1/2]

juce::StringPairArray::StringPairArray | ( | bool | ignoreCaseWhenComparingKeys = true | ) |

Creates an empty array.

Referenced by addArray(), addUnorderedMap(), operator!=(), operator=(), operator==(), and StringPairArray().

## StringPairArray() [2/2]

juce::StringPairArray::StringPairArray | ( | const StringPairArray & | other | ) |

Creates a copy of another array.

References StringPairArray().

## ~StringPairArray()

juce::StringPairArray::~StringPairArray | ( |  | ) |

default

Destructor.

## Member Functions

## operator=()

StringPairArray & juce::StringPairArray::operator= | ( | const StringPairArray & | other | ) |

Copies the contents of another string array into this one.

References StringPairArray().

## operator==()

bool juce::StringPairArray::operator== | ( | const StringPairArray & | other | ) | const

Compares two arrays.

Comparisons are case-sensitive.

Returns
  true only if the other array contains exactly the same strings with the same keys

References StringPairArray().

## operator!=()

bool juce::StringPairArray::operator!= | ( | const StringPairArray & | other | ) | const

Compares two arrays.

Comparisons are case-sensitive.

Returns
  false if the other array contains exactly the same strings with the same keys

References StringPairArray().

## operator[]()

const String & juce::StringPairArray::operator[] | ( | StringRef | key | ) | const

Finds the value corresponding to a key string.

If no such key is found, this will just return an empty string. To check whether a given key actually exists (because it might actually be paired with an empty string), use the getAllKeys() method to obtain a list.

Obviously the reference returned shouldn't be stored for later use, as the string it refers to may disappear when the array changes.

See also
  getValue

## getValue()

String juce::StringPairArray::getValue | ( | StringRef | ,
|  | const String & | defaultReturnValue ) const

Finds the value corresponding to a key string.

If no such key is found, this will just return the value provided as a default.

See also
  operator[]

## containsKey()

bool juce::StringPairArray::containsKey | ( | StringRef | key | ) | const

noexcept

Returns true if the given key exists.

## getAllKeys()

const StringArray & juce::StringPairArray::getAllKeys | ( |  | ) | const

inline noexcept

Returns a list of all keys in the array.

## getAllValues()

const StringArray & juce::StringPairArray::getAllValues | ( |  | ) | const

inline noexcept

Returns a list of all values in the array.

## size()

int juce::StringPairArray::size | ( |  | ) | const

inline noexcept

Returns the number of strings in the array.

## set()

void juce::StringPairArray::set | ( | const String & | key,
|  | const String & | value )

Adds or amends a key/value pair.

If a value already exists with this key, its value will be overwritten, otherwise the key/value pair will be added to the array.

## addArray()

void juce::StringPairArray::addArray | ( | const StringPairArray & | other | ) |

Adds the items from another array to this one.

This is equivalent to using set() to add each of the pairs from the other array.

References StringPairArray().

## clear()

void juce::StringPairArray::clear | ( |  | ) |

Removes all elements from the array.

## remove() [1/2]

void juce::StringPairArray::remove | ( | StringRef | key | ) |

Removes a string from the array based on its key.

If the key isn't found, nothing will happen.

## remove() [2/2]

void juce::StringPairArray::remove | ( | int | index | ) |

Removes a string from the array based on its index.

If the index is out-of-range, no action will be taken.

## setIgnoresCase()

void juce::StringPairArray::setIgnoresCase | ( | bool | shouldIgnoreCase | ) |

Indicates whether to use a case-insensitive search when looking up a key string.

## getIgnoresCase()

bool juce::StringPairArray::getIgnoresCase | ( |  | ) | const

noexcept

Indicates whether a case-insensitive search is used when looking up a key string.

## getDescription()

String juce::StringPairArray::getDescription | ( |  | ) | const

Returns a descriptive string containing the items.

This is handy for dumping the contents of an array.

References getDescription().

Referenced by getDescription().

## minimiseStorageOverheads()

void juce::StringPairArray::minimiseStorageOverheads | ( |  | ) |

Reduces the amount of storage being used by the array.

Arrays typically allocate slightly more storage than they need, and after removing elements, they may have quite a lot of unused space allocated. This method will reduce the amount of allocated storage to a minimum.

References minimiseStorageOverheads().

Referenced by minimiseStorageOverheads().

## addMap()

void juce::StringPairArray::addMap | ( | const std::map< String, String > & | mapToAdd | ) |

Adds the contents of a map to this StringPairArray.

References addMap().

Referenced by addMap().

## addUnorderedMap()

void juce::StringPairArray::addUnorderedMap | ( | const std::unordered_map< String, String > & | mapToAdd | ) |

Adds the contents of an unordered map to this StringPairArray.

References addUnorderedMap(), JUCE_LEAK_DETECTOR, and StringPairArray().

Referenced by addUnorderedMap().

### Purchase

Get JUCE

### Discover

What's New in JUCE Features

### Learn

Documentaion Tutorials Made with JUCE Resources

### Support

JUCE Forum Newsletter Archive

### About

Contact Us JUCE Legal JUCE Licensing FAQ

### Events

Audio Developer Conference
© Raw Material Software Limited