mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Added some helpers to StringArray to allow creation from Arrays of string-convertible objects
This commit is contained in:
parent
9da4d4131c
commit
383528ec6e
2 changed files with 35 additions and 0 deletions
|
|
@ -37,6 +37,11 @@ StringArray::StringArray (StringArray&& other) noexcept
|
|||
{
|
||||
}
|
||||
|
||||
StringArray::StringArray (Array<String>&& other) noexcept
|
||||
: strings (static_cast<Array<String>&&> (other))
|
||||
{
|
||||
}
|
||||
|
||||
StringArray::StringArray (const String& firstValue)
|
||||
{
|
||||
strings.add (firstValue);
|
||||
|
|
|
|||
|
|
@ -54,6 +54,16 @@ public:
|
|||
/** Creates an array containing a list of strings. */
|
||||
StringArray (const std::initializer_list<const char*>& strings);
|
||||
|
||||
/** Creates a StringArray by moving from an Array<String> */
|
||||
StringArray (Array<String>&&) noexcept;
|
||||
|
||||
/** Creates a StringArray from an array of objects which can be implicitly converted to Strings. */
|
||||
template <typename Type>
|
||||
StringArray (const Array<Type>& stringArray)
|
||||
{
|
||||
addArray (stringArray.begin(), stringArray.end());
|
||||
}
|
||||
|
||||
/** Creates an array from a raw array of strings.
|
||||
@param strings an array of strings to add
|
||||
@param numberOfStrings how many items there are in the array
|
||||
|
|
@ -96,6 +106,14 @@ public:
|
|||
/** Move assignment operator */
|
||||
StringArray& operator= (StringArray&&) noexcept;
|
||||
|
||||
/** Copies a StringArray from an array of objects which can be implicitly converted to Strings. */
|
||||
template <typename Type>
|
||||
StringArray& operator= (const Array<Type>& stringArray)
|
||||
{
|
||||
addArray (stringArray.begin(), stringArray.end());
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** Swaps the contents of this and another StringArray. */
|
||||
void swapWith (StringArray&) noexcept;
|
||||
|
||||
|
|
@ -208,6 +226,18 @@ public:
|
|||
int startIndex = 0,
|
||||
int numElementsToAdd = -1);
|
||||
|
||||
/** Adds items from a range of start/end iterators of some kind of objects which
|
||||
can be implicitly converted to Strings.
|
||||
*/
|
||||
template <typename Iterator>
|
||||
void addArray (Iterator&& start, Iterator&& end)
|
||||
{
|
||||
ensureStorageAllocated (size() + (int) static_cast<size_t> (end - start));
|
||||
|
||||
while (start != end)
|
||||
strings.add (*start++);
|
||||
}
|
||||
|
||||
/** Merges the strings from another array into this one.
|
||||
This will not add a string that already exists.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue