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);
94 return strings == other.strings;
99 return ! operator== (other);
104 strings.swapWith (other.strings);
119 if (isPositiveAndBelow (index,
strings.size()))
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))
161 jassert (
this != &otherArray);
169 if (numElementsToAdd < 0 || startIndex + numElementsToAdd > otherArray.
size())
170 numElementsToAdd = otherArray.
size() - startIndex;
172 while (--numElementsToAdd >= 0)
178 jassert (
this != &otherArray);
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);
319 dest.writeAll (s.getCharPointer());
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)
415 auto s =
strings.getReference (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();
CharType * getAddress() const noexcept
static Type findEndOfToken(Type text, BreakType breakCharacters, Type quoteCharacters)
bool operator==(const StringArray &) const noexcept
String joinIntoString(StringRef separatorString, int startIndex=0, int numberOfElements=-1) const
void appendNumbersToDuplicates(bool ignoreCaseWhenComparing, bool appendNumberToFirstInstance, CharPointer_UTF8 preNumberString=CharPointer_UTF8(nullptr), CharPointer_UTF8 postNumberString=CharPointer_UTF8(nullptr))
String & getReference(int index) noexcept
void removeEmptyStrings(bool removeWhitespaceStrings=true)
void addArray(const StringArray &other, int startIndex=0, int numElementsToAdd=-1)
int indexOf(StringRef stringToLookFor, bool ignoreCase=false, int startIndex=0) const
bool contains(StringRef stringToLookFor, bool ignoreCase=false) const
void removeDuplicates(bool ignoreCase)
static StringArray fromTokens(StringRef stringToTokenise, bool preserveQuotedStrings)
void insert(int index, String stringToAdd)
static StringArray fromLines(StringRef stringToBreakUp)
void minimiseStorageOverheads()
const String & operator[](int index) const noexcept
void removeString(StringRef stringToRemove, bool ignoreCase=false)
void sort(bool ignoreCase)
void move(int currentIndex, int newIndex) noexcept
void swapWith(StringArray &) noexcept
int size() const noexcept
bool operator!=(const StringArray &) const noexcept
void add(String stringToAdd)
int addLines(StringRef stringToBreakUp)
void mergeArray(const StringArray &other, bool ignoreCase=false)
bool addIfNotAlreadyThere(const String &stringToAdd, bool ignoreCase=false)
void removeRange(int startIndex, int numberToRemove)
StringArray & operator=(const StringArray &)
void set(int index, String newString)
void ensureStorageAllocated(int minNumElements)
int addTokens(StringRef stringToTokenise, bool preserveQuotedStrings)
bool isNotEmpty() const noexcept
String::CharPointerType text
CharPointerType getCharPointer() const noexcept
void preallocateBytes(size_t numBytesNeeded)