31 : strings (other.strings)
36 : strings (std::move (other.strings))
41 : strings (std::move (other))
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);
94 return strings == other.strings;
99 return ! operator== (other);
104 strings.swapWith (other.strings);
120 return strings.getReference (index);
128 return strings.getReference (index);
133 return strings.getReference (index);
140 strings.add (std::move (newString));
147 strings.insert (index, std::move (newString));
152 if (
contains (newString, ignoreCase))
169 if (numElementsToAdd < 0 || startIndex + numElementsToAdd > otherArray.
size())
170 numElementsToAdd = otherArray.
size() - startIndex;
172 while (--numElementsToAdd >= 0)
180 for (
auto& s : otherArray)
186 strings.set (index, std::move (newString));
191 return indexOf (stringToLookFor, ignoreCase) >= 0;
199 auto numElements =
size();
203 for (; i < numElements; ++i)
204 if (
strings.getReference (i).equalsIgnoreCase (stringToLookFor))
209 for (; i < numElements; ++i)
210 if (stringToLookFor ==
strings.getReference (i))
219 strings.move (currentIndex, newIndex);
232 for (
int i =
size(); --i >= 0;)
233 if (
strings.getReference (i).equalsIgnoreCase (stringToRemove))
238 for (
int i =
size(); --i >= 0;)
239 if (stringToRemove ==
strings.getReference (i))
246 strings.removeRange (startIndex, numberToRemove);
252 if (removeWhitespaceStrings)
254 for (
int i =
size(); --i >= 0;)
255 if (!
strings.getReference (i).containsNonWhitespaceChars())
260 for (
int i =
size(); --i >= 0;)
261 if (
strings.getReference (i).isEmpty())
277 [] (
const String& a,
const String& b) { return a.compareIgnoreCase (b) < 0; });
285 [] (
const String& a,
const String& b) { return a.compareNatural (b) < 0; });
291 auto last = (numberToJoin < 0) ?
size()
292 :
jmin (
size(), start + numberToJoin);
300 if (start == last - 1)
301 return strings.getReference (start);
303 auto separatorBytes = separator.
text.
sizeInBytes() -
sizeof (String::CharPointerType::CharType);
304 auto bytesNeeded = (
size_t) (last - start - 1) * separatorBytes;
306 for (
int i = start; i < last; ++i)
307 bytesNeeded +=
strings.getReference (i).getCharPointer().sizeInBytes() -
sizeof (String::CharPointerType::CharType);
316 auto& s =
strings.getReference (start);
321 if (++start < last && separatorBytes > 0)
322 dest.writeAll (separator.
text);
331 return addTokens (text,
" \n\r\t", preserveQuotedStrings ?
"\"" :
"");
340 for (
auto t = text.
text;;)
343 breakCharacters.
text,
344 quoteCharacters.
text);
348 if (tokenEnd.isEmpty())
361 auto text = sourceText.
text;
362 bool finished = text.
isEmpty();
366 for (
auto startOfLine = text;;)
368 auto endOfLine = text;
370 switch (text.getAndAdvance())
372 case 0: finished =
true;
break;
374 case '\r':
if (*text ==
'\n') ++text;
break;
390 s.
addTokens (stringToTokenise, preserveQuotedStrings);
399 s.
addTokens (stringToTokenise, breakCharacters, quoteCharacters);
413 for (
int i = 0; i <
size() - 1; ++i)
417 for (
int nextIndex = i + 1;;)
419 nextIndex =
indexOf (s, ignoreCase, nextIndex);
430 bool appendNumberToFirstInstance,
440 for (
int i = 0; i <
size() - 1; ++i)
442 auto& s =
strings.getReference (i);
443 auto nextIndex =
indexOf (s, ignoreCase, i + 1);
450 if (appendNumberToFirstInstance)
451 s = original +
String (preNumberString) +
String (++number) +
String (postNumberString);
455 while (nextIndex >= 0)
457 set (nextIndex, (*
this)[nextIndex] +
String (preNumberString) +
String (++number) +
String (postNumberString));
458 nextIndex =
indexOf (original, ignoreCase, nextIndex + 1);
466 strings.ensureStorageAllocated (minNumElements);
471 strings.minimiseStorageOverheads();
Holds a resizable array of primitive or copy-by-value objects.
Wraps a pointer to a null-terminated UTF-8 character string, and provides various methods to operate ...
void writeAll(const CharPointer src) noexcept
Copies a source string to this pointer, advancing this pointer as it goes.
size_t sizeInBytes() const noexcept
Returns the number of bytes that are used to represent this string.
bool isEmpty() const noexcept
Returns true if this pointer is pointing to a null character.
CharType * getAddress() const noexcept
Returns the address that this pointer is pointing to.
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 special array for holding a list of strings.
bool operator==(const StringArray &) const noexcept
Compares two arrays.
String joinIntoString(StringRef separatorString, int startIndex=0, int numberOfElements=-1) const
Joins the strings in the array together into one string.
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.
String & getReference(int index) noexcept
Returns a reference to one of the strings in the array.
void removeEmptyStrings(bool removeWhitespaceStrings=true)
Removes empty strings from the array.
void addArray(const StringArray &other, int startIndex=0, int numElementsToAdd=-1)
Appends some strings from another array to the end of this one.
int indexOf(StringRef stringToLookFor, bool ignoreCase=false, int startIndex=0) const
Searches for a string in the array.
void sortNatural()
Sorts the array using extra language-aware rules to do a better job of comparing words containing spa...
bool contains(StringRef stringToLookFor, bool ignoreCase=false) const
Searches for a string in the array.
void removeDuplicates(bool ignoreCase)
Removes any duplicated elements from the array.
static StringArray fromTokens(StringRef stringToTokenise, bool preserveQuotedStrings)
Returns an array containing the tokens in a given string.
void insert(int index, String stringToAdd)
Inserts a string into the array.
static StringArray fromLines(StringRef stringToBreakUp)
Returns an array containing the lines in a given string.
void minimiseStorageOverheads()
Reduces the amount of storage being used by the array.
void clear()
Removes all elements from the array.
Array< String > strings
This is the array holding the actual strings.
StringArray() noexcept
Creates an empty string array.
const String & operator[](int index) const noexcept
Returns one of the strings from the array.
void removeString(StringRef stringToRemove, bool ignoreCase=false)
Finds a string in the array and removes it.
void sort(bool ignoreCase)
Sorts the array into alphabetical order.
void move(int currentIndex, int newIndex) noexcept
Moves one of the strings to a different position.
void swapWith(StringArray &) noexcept
Swaps the contents of this and another StringArray.
int size() const noexcept
Returns the number of strings in the array.
bool operator!=(const StringArray &) const noexcept
Compares two arrays.
void trim()
Deletes any whitespace characters from the starts and ends of all the strings.
void add(String stringToAdd)
Appends a string at the end of the array.
int addLines(StringRef stringToBreakUp)
Breaks up a string into lines and adds them to this array.
void clearQuick()
Removes all elements from the array without freeing the array's allocated storage.
void mergeArray(const StringArray &other, bool ignoreCase=false)
Merges the strings from another array into this one.
bool addIfNotAlreadyThere(const String &stringToAdd, bool ignoreCase=false)
Adds a string to the array as long as it's not already in there.
void removeRange(int startIndex, int numberToRemove)
Removes a range of elements from the array.
StringArray & operator=(const StringArray &)
Copies the contents of another string array into this one.
void set(int index, String newString)
Replaces one of the strings in the array with another one.
void remove(int index)
Removes a string from the array.
void ensureStorageAllocated(int minNumElements)
Increases the array's internal storage to hold a minimum number of elements.
int addTokens(StringRef stringToTokenise, bool preserveQuotedStrings)
Breaks up a string into tokens and adds them to this array.
A simple class for holding temporary references to a string literal or String.
bool isNotEmpty() const noexcept
Returns true if the string is not empty.
String::CharPointerType text
The text that is referenced.
CharPointerType getCharPointer() const noexcept
Returns the character pointer currently being used to store this string.
void preallocateBytes(size_t numBytesNeeded)
Increases the string's internally allocated storage.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
bool isPositiveAndBelow(Type1 valueToTest, Type2 upperLimit) noexcept
Returns true if a value is at least zero, and also below a specified upper limit.