36 :
strings (std::move (other.strings))
52 strings.addArray (initialStrings, numberOfStrings);
57 strings.addNullTerminatedArray (initialStrings);
62 strings.addArray (initialStrings, numberOfStrings);
67 strings.addNullTerminatedArray (initialStrings);
72 strings.addArray (initialStrings, numberOfStrings);
88 strings = std::move (other.strings);
98 return strings == other.strings;
108 strings.swapWith (other.strings);
123 if (isPositiveAndBelow (index,
strings.size()))
124 return strings.getReference (index);
132 return strings.getReference (index);
139 strings.add (std::move (newString));
146 strings.insert (index, std::move (newString));
151 if (
contains (newString, ignoreCase))
160 jassert (
this != &otherArray);
168 if (numElementsToAdd < 0 || startIndex + numElementsToAdd > otherArray.
size())
169 numElementsToAdd = otherArray.
size() - startIndex;
171 while (--numElementsToAdd >= 0)
177 jassert (
this != &otherArray);
179 for (
auto& s : otherArray)
185 strings.set (index, std::move (newString));
190 return indexOf (stringToLookFor, ignoreCase) >= 0;
198 auto numElements =
size();
202 for (; i < numElements; ++i)
203 if (
strings.getReference(i).equalsIgnoreCase (stringToLookFor))
208 for (; i < numElements; ++i)
209 if (stringToLookFor ==
strings.getReference (i))
218 strings.move (currentIndex, newIndex);
231 for (
int i =
size(); --i >= 0;)
232 if (
strings.getReference(i).equalsIgnoreCase (stringToRemove))
237 for (
int i =
size(); --i >= 0;)
238 if (stringToRemove ==
strings.getReference (i))
245 strings.removeRange (startIndex, numberToRemove);
251 if (removeWhitespaceStrings)
253 for (
int i =
size(); --i >= 0;)
254 if (!
strings.getReference(i).containsNonWhitespaceChars())
259 for (
int i =
size(); --i >= 0;)
260 if (
strings.getReference(i).isEmpty())
290 auto last = (numberToJoin < 0) ?
size()
291 : jmin (
size(), start + numberToJoin);
299 if (start == last - 1)
300 return strings.getReference (start);
302 auto separatorBytes = separator.
text.
sizeInBytes() -
sizeof (String::CharPointerType::CharType);
303 auto bytesNeeded = (size_t) (last - start - 1) * separatorBytes;
305 for (
int i = start; i < last; ++i)
306 bytesNeeded +=
strings.getReference(i).getCharPointer().sizeInBytes() -
sizeof (String::CharPointerType::CharType);
315 auto& s =
strings.getReference (start);
318 dest.writeAll (s.getCharPointer());
320 if (++start < last && separatorBytes > 0)
321 dest.writeAll (separator.
text);
330 return addTokens (text,
" \n\r\t", preserveQuotedStrings ?
"\"" :
"");
339 for (
auto t = text.
text;;)
342 breakCharacters.
text,
343 quoteCharacters.
text);
347 if (tokenEnd.isEmpty())
360 auto text = sourceText.
text;
361 bool finished = text.
isEmpty();
365 for (
auto startOfLine = text;;)
367 auto endOfLine = text;
369 switch (text.getAndAdvance())
371 case 0: finished =
true;
break;
373 case '\r':
if (*text ==
'\n') ++text;
break;
389 s.
addTokens (stringToTokenise, preserveQuotedStrings);
398 s.
addTokens (stringToTokenise, breakCharacters, quoteCharacters);
412 for (
int i = 0; i <
size() - 1; ++i)
414 auto s =
strings.getReference(i);
416 for (
int nextIndex = i + 1;;)
418 nextIndex =
indexOf (s, ignoreCase, nextIndex);
429 bool appendNumberToFirstInstance,
439 for (
int i = 0; i <
size() - 1; ++i)
441 auto& s =
strings.getReference(i);
442 auto nextIndex =
indexOf (s, ignoreCase, i + 1);
449 if (appendNumberToFirstInstance)
450 s = original +
String (preNumberString) +
String (++number) +
String (postNumberString);
454 while (nextIndex >= 0)
456 set (nextIndex, (*this)[nextIndex] + String (preNumberString) + String (++number) + String (postNumberString));
457 nextIndex =
indexOf (original, ignoreCase, nextIndex + 1);
465 strings.ensureStorageAllocated (minNumElements);
470 strings.minimiseStorageOverheads();
void addArray(const StringArray &other, int startIndex=0, int numElementsToAdd=-1)
Appends some strings from another array to the end of this one.
static Type findEndOfToken(Type text, BreakType breakCharacters, Type quoteCharacters)
Returns a pointer to the first character in the string which is found in the breakCharacters string...
A simple class for holding temporary references to a string literal or String.
bool operator!=(const StringArray &) const noexcept
Compares two arrays.
bool isNotEmpty() const noexcept
Returns true if the string is not empty.
void appendNumbersToDuplicates(bool ignoreCaseWhenComparing, bool appendNumberToFirstInstance, CharPointer_UTF8 preNumberString=CharPointer_UTF8(nullptr), CharPointer_UTF8 postNumberString=CharPointer_UTF8(nullptr))
Adds numbers to the strings in the array, to make each string unique.
void removeEmptyStrings(bool removeWhitespaceStrings=true)
Removes empty strings from the array.
void remove(int index)
Removes a string from the array.
void removeDuplicates(bool ignoreCase)
Removes any duplicated elements from the array.
int compareNatural(StringRef other, bool isCaseSensitive=false) const noexcept
Compares two strings, taking into account textual characteristics like numbers and spaces...
CharPointerType getCharPointer() const noexcept
Returns the character pointer currently being used to store this string.
bool isEmpty() const noexcept
Returns true if this pointer is pointing to a null character.
int addLines(StringRef stringToBreakUp)
Breaks up a string into lines and adds them to this array.
void move(int currentIndex, int newIndex) noexcept
Moves one of the strings to a different position.
void sortNatural()
Sorts the array using extra language-aware rules to do a better job of comparing words containing spa...
A special array for holding a list of strings.
void trim()
Deletes any whitespace characters from the starts and ends of all the strings.
String & getReference(int index) noexcept
Returns a reference to one of the strings in the array.
int indexOf(StringRef stringToLookFor, bool ignoreCase=false, int startIndex=0) const
Searches for a string in the array.
int addTokens(StringRef stringToTokenise, bool preserveQuotedStrings)
Breaks up a string into tokens and adds them to this array.
void clearQuick()
Removes all elements from the array without freeing the array's allocated storage.
void minimiseStorageOverheads()
Reduces the amount of storage being used by the array.
void set(int index, String newString)
Replaces one of the strings in the array with another one.
int compareIgnoreCase(const String &other) const noexcept
Case-insensitive comparison with another string.
bool operator==(const StringArray &) const noexcept
Compares two arrays.
void clear()
Removes all elements from the array.
CharType * getAddress() const noexcept
Returns the address that this pointer is pointing to.
void ensureStorageAllocated(int minNumElements)
Increases the array's internal storage to hold a minimum number of elements.
StringArray() noexcept
Creates an empty string array.
void removeString(StringRef stringToRemove, bool ignoreCase=false)
Finds a string in the array and removes it.
void removeRange(int startIndex, int numberToRemove)
Removes a range of elements from the array.
static StringArray fromTokens(StringRef stringToTokenise, bool preserveQuotedStrings)
Returns an array containing the tokens in a given string.
bool addIfNotAlreadyThere(const String &stringToAdd, bool ignoreCase=false)
Adds a string to the array as long as it's not already in there.
Holds a resizable array of primitive or copy-by-value objects.
void sort(bool ignoreCase)
Sorts the array into alphabetical order.
void preallocateBytes(size_t numBytesNeeded)
Increases the string's internally allocated storage.
String::CharPointerType text
The text that is referenced.
bool contains(StringRef stringToLookFor, bool ignoreCase=false) const
Searches for a string in the array.
String joinIntoString(StringRef separatorString, int startIndex=0, int numberOfElements=-1) const
Joins the strings in the array together into one string.
static StringArray fromLines(StringRef stringToBreakUp)
Returns an array containing the lines in a given string.
void insert(int index, String stringToAdd)
Inserts a string into the array.
~StringArray()
Destructor.
int size() const noexcept
Returns the number of strings in the array.
const String & operator[](int index) const noexcept
Returns one of the strings from the array.
Array< String > strings
This is the array holding the actual strings.
void mergeArray(const StringArray &other, bool ignoreCase=false)
Merges the strings from another array into this one.
StringArray & operator=(const StringArray &)
Copies the contents of another string array into this one.
void swapWith(StringArray &) noexcept
Swaps the contents of this and another StringArray.
void add(String stringToAdd)
Appends a string at the end of the array.
size_t sizeInBytes() const noexcept
Returns the number of bytes that are used to represent this string.
Wraps a pointer to a null-terminated UTF-8 character string, and provides various methods to operate ...