OpenShot Library | libopenshot-audio
0.2.0
|
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);
98 return strings == other.strings;
103 return ! operator== (other);
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())
276 [] (
const String& a,
const String& b) { return a.compareIgnoreCase (b) < 0; });
284 [] (
const String& a,
const String& b) { return a.compareNatural (b) < 0; });
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 = separatorBytes * (size_t) (last - start - 1);
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();
A special array for holding a list of 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.
CharType * getAddress() const noexcept
Returns the address that this pointer is pointing to.
A simple class for holding temporary references to a string literal or String.
StringArray() noexcept
Creates an empty string array.
void removeRange(int startIndex, int numberToRemove)
Removes a range of elements from the array.
Array< String > strings
This is the array holding the actual strings.
void set(int index, String newString)
Replaces one of the strings in the array with another one.
void insert(int index, String stringToAdd)
Inserts a string into the array.
void sort(bool ignoreCase)
Sorts the array into alphabetical order.
void mergeArray(const StringArray &other, bool ignoreCase=false)
Merges the strings from another array into this one.
void trim()
Deletes any whitespace characters from the starts and ends of all the strings.
void removeEmptyStrings(bool removeWhitespaceStrings=true)
Removes empty strings from the array.
bool isEmpty() const noexcept
Returns true if this pointer is pointing to a null character.
bool operator!=(const StringArray &) const noexcept
Compares two arrays.
CharPointerType getCharPointer() const noexcept
Returns the character pointer currently being used to store this string.
void removeString(StringRef stringToRemove, bool ignoreCase=false)
Finds a string in the array and removes it.
String joinIntoString(StringRef separatorString, int startIndex=0, int numberOfElements=-1) const
Joins the strings in the array together into one string.
static StringArray fromTokens(StringRef stringToTokenise, bool preserveQuotedStrings)
Returns an array containing the tokens in a given string.
void clearQuick()
Removes all elements from the array without freeing the array's allocated storage.
Holds a resizable array of primitive or copy-by-value objects.
bool operator==(const StringArray &) const noexcept
Compares two arrays.
String::CharPointerType text
The text that is referenced.
const String & operator[](int index) const noexcept
Returns one of the 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.
void move(int currentIndex, int newIndex) noexcept
Moves one of the strings to a different position.
bool contains(StringRef stringToLookFor, bool ignoreCase=false) const
Searches for a string in the array.
int size() const noexcept
Returns the number of strings in the array.
static StringArray fromLines(StringRef stringToBreakUp)
Returns an array containing the lines in a given string.
void swapWith(StringArray &) noexcept
Swaps the contents of this and another StringArray.
void preallocateBytes(size_t numBytesNeeded)
Increases the string's internally allocated storage.
void remove(int index)
Removes a string from the array.
bool addIfNotAlreadyThere(const String &stringToAdd, bool ignoreCase=false)
Adds a string to the array as long as it's not already in there.
size_t sizeInBytes() const noexcept
Returns the number of bytes that are used to represent this string.
StringArray & operator=(const StringArray &)
Copies the contents of another string array into this one.
void sortNatural()
Sorts the array using extra language-aware rules to do a better job of comparing words containing spa...
Wraps a pointer to a null-terminated UTF-8 character string, and provides various methods to operate ...
int addTokens(StringRef stringToTokenise, bool preserveQuotedStrings)
Breaks up a string into tokens and adds them to this array.
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.
bool isNotEmpty() const noexcept
Returns true if the string is not empty.
void removeDuplicates(bool ignoreCase)
Removes any duplicated elements from the array.
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.
int addLines(StringRef stringToBreakUp)
Breaks up a string into lines and adds them to this array.
void ensureStorageAllocated(int minNumElements)
Increases the array's internal storage to hold a minimum number of elements.
void add(String stringToAdd)
Appends a string at the end of the array.
void clear()
Removes all elements from the array.
~StringArray()
Destructor.
void minimiseStorageOverheads()
Reduces the amount of storage being used by the array.