Browse Source

Added some helpers to StringArray to allow creation from Arrays of string-convertible objects

tags/2021-05-28
jules 7 years ago
parent
commit
383528ec6e
2 changed files with 35 additions and 0 deletions
  1. +5
    -0
      modules/juce_core/text/juce_StringArray.cpp
  2. +30
    -0
      modules/juce_core/text/juce_StringArray.h

+ 5
- 0
modules/juce_core/text/juce_StringArray.cpp View File

@@ -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);


+ 30
- 0
modules/juce_core/text/juce_StringArray.h View File

@@ -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…
Cancel
Save