mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Modernised a bunch of code mainly relating to character/string iteration
This commit is contained in:
parent
d346d6ef50
commit
f0ef700e46
27 changed files with 356 additions and 379 deletions
|
|
@ -176,7 +176,7 @@ private:
|
||||||
|
|
||||||
if (CharacterFunctions::compareUpTo (CharPointer_ASCII (token), t, len) == 0)
|
if (CharacterFunctions::compareUpTo (CharPointer_ASCII (token), t, len) == 0)
|
||||||
{
|
{
|
||||||
String::CharPointerType end = t + len;
|
auto end = t + len;
|
||||||
|
|
||||||
if (end.isEmpty() || end.isWhitespace())
|
if (end.isEmpty() || end.isWhitespace())
|
||||||
{
|
{
|
||||||
|
|
@ -279,7 +279,7 @@ private:
|
||||||
|
|
||||||
for (int lineNum = 0; lineNum < lines.size(); ++lineNum)
|
for (int lineNum = 0; lineNum < lines.size(); ++lineNum)
|
||||||
{
|
{
|
||||||
String::CharPointerType l = lines[lineNum].getCharPointer().findEndOfWhitespace();
|
auto l = lines[lineNum].getCharPointer().findEndOfWhitespace();
|
||||||
|
|
||||||
if (matchToken (l, "v")) { mesh.vertices.add (parseVertex (l)); continue; }
|
if (matchToken (l, "v")) { mesh.vertices.add (parseVertex (l)); continue; }
|
||||||
if (matchToken (l, "vn")) { mesh.normals.add (parseVertex (l)); continue; }
|
if (matchToken (l, "vn")) { mesh.normals.add (parseVertex (l)); continue; }
|
||||||
|
|
@ -341,7 +341,7 @@ private:
|
||||||
|
|
||||||
for (int i = 0; i < lines.size(); ++i)
|
for (int i = 0; i < lines.size(); ++i)
|
||||||
{
|
{
|
||||||
String::CharPointerType l (lines[i].getCharPointer().findEndOfWhitespace());
|
auto l = lines[i].getCharPointer().findEndOfWhitespace();
|
||||||
|
|
||||||
if (matchToken (l, "newmtl")) { materials.add (material); material.name = String (l).trim(); continue; }
|
if (matchToken (l, "newmtl")) { materials.add (material); material.name = String (l).trim(); continue; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -176,7 +176,7 @@ private:
|
||||||
|
|
||||||
if (CharacterFunctions::compareUpTo (CharPointer_ASCII (token), t, len) == 0)
|
if (CharacterFunctions::compareUpTo (CharPointer_ASCII (token), t, len) == 0)
|
||||||
{
|
{
|
||||||
String::CharPointerType end = t + len;
|
auto end = t + len;
|
||||||
|
|
||||||
if (end.isEmpty() || end.isWhitespace())
|
if (end.isEmpty() || end.isWhitespace())
|
||||||
{
|
{
|
||||||
|
|
@ -279,7 +279,7 @@ private:
|
||||||
|
|
||||||
for (int lineNum = 0; lineNum < lines.size(); ++lineNum)
|
for (int lineNum = 0; lineNum < lines.size(); ++lineNum)
|
||||||
{
|
{
|
||||||
String::CharPointerType l = lines[lineNum].getCharPointer().findEndOfWhitespace();
|
auto l = lines[lineNum].getCharPointer().findEndOfWhitespace();
|
||||||
|
|
||||||
if (matchToken (l, "v")) { mesh.vertices.add (parseVertex (l)); continue; }
|
if (matchToken (l, "v")) { mesh.vertices.add (parseVertex (l)); continue; }
|
||||||
if (matchToken (l, "vn")) { mesh.normals.add (parseVertex (l)); continue; }
|
if (matchToken (l, "vn")) { mesh.normals.add (parseVertex (l)); continue; }
|
||||||
|
|
@ -341,7 +341,7 @@ private:
|
||||||
|
|
||||||
for (int i = 0; i < lines.size(); ++i)
|
for (int i = 0; i < lines.size(); ++i)
|
||||||
{
|
{
|
||||||
String::CharPointerType l (lines[i].getCharPointer().findEndOfWhitespace());
|
auto l = lines[i].getCharPointer().findEndOfWhitespace();
|
||||||
|
|
||||||
if (matchToken (l, "newmtl")) { materials.add (material); material.name = String (l).trim(); continue; }
|
if (matchToken (l, "newmtl")) { materials.add (material); material.name = String (l).trim(); continue; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -476,7 +476,7 @@ struct ClassDatabase
|
||||||
|
|
||||||
void add (const Class& c, const String::CharPointerType& localName)
|
void add (const Class& c, const String::CharPointerType& localName)
|
||||||
{
|
{
|
||||||
const String::CharPointerType nextDoubleColon (CharacterFunctions::find (localName, CharPointer_ASCII ("::")));
|
auto nextDoubleColon = CharacterFunctions::find (localName, CharPointer_ASCII ("::"));
|
||||||
|
|
||||||
if (nextDoubleColon.isEmpty())
|
if (nextDoubleColon.isEmpty())
|
||||||
merge (c);
|
merge (c);
|
||||||
|
|
|
||||||
|
|
@ -159,12 +159,12 @@ namespace CodeHelpers
|
||||||
StringArray lines;
|
StringArray lines;
|
||||||
|
|
||||||
{
|
{
|
||||||
String::CharPointerType t (text.getCharPointer());
|
auto t = text.getCharPointer();
|
||||||
bool finished = t.isEmpty();
|
bool finished = t.isEmpty();
|
||||||
|
|
||||||
while (! finished)
|
while (! finished)
|
||||||
{
|
{
|
||||||
for (String::CharPointerType startOfLine (t);;)
|
for (auto startOfLine = t;;)
|
||||||
{
|
{
|
||||||
switch (t.getAndAdvance())
|
switch (t.getAndAdvance())
|
||||||
{
|
{
|
||||||
|
|
@ -437,7 +437,7 @@ namespace CodeHelpers
|
||||||
String getLeadingWhitespace (String line)
|
String getLeadingWhitespace (String line)
|
||||||
{
|
{
|
||||||
line = line.removeCharacters ("\r\n");
|
line = line.removeCharacters ("\r\n");
|
||||||
const String::CharPointerType endOfLeadingWS (line.getCharPointer().findEndOfWhitespace());
|
auto endOfLeadingWS = line.getCharPointer().findEndOfWhitespace();
|
||||||
return String (line.getCharPointer(), endOfLeadingWS);
|
return String (line.getCharPointer(), endOfLeadingWS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ void setValueIfVoid (Value value, const var& defaultValue)
|
||||||
StringPairArray parsePreprocessorDefs (const String& text)
|
StringPairArray parsePreprocessorDefs (const String& text)
|
||||||
{
|
{
|
||||||
StringPairArray result;
|
StringPairArray result;
|
||||||
String::CharPointerType s (text.getCharPointer());
|
auto s = text.getCharPointer();
|
||||||
|
|
||||||
while (! s.isEmpty())
|
while (! s.isEmpty())
|
||||||
{
|
{
|
||||||
|
|
@ -136,8 +136,9 @@ String createGCCPreprocessorFlags (const StringPairArray& defs)
|
||||||
|
|
||||||
for (int i = 0; i < defs.size(); ++i)
|
for (int i = 0; i < defs.size(); ++i)
|
||||||
{
|
{
|
||||||
String def (defs.getAllKeys()[i]);
|
auto def = defs.getAllKeys()[i];
|
||||||
const String value (defs.getAllValues()[i]);
|
auto value = defs.getAllValues()[i];
|
||||||
|
|
||||||
if (value.isNotEmpty())
|
if (value.isNotEmpty())
|
||||||
def << "=" << value;
|
def << "=" << value;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,9 +38,8 @@ struct TranslationHelpers
|
||||||
|
|
||||||
static void scanFileForTranslations (StringArray& strings, const File& file)
|
static void scanFileForTranslations (StringArray& strings, const File& file)
|
||||||
{
|
{
|
||||||
const String content (file.loadFileAsString());
|
auto content = file.loadFileAsString();
|
||||||
|
auto p = content.getCharPointer();
|
||||||
String::CharPointerType p (content.getCharPointer());
|
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
|
@ -69,11 +68,11 @@ struct TranslationHelpers
|
||||||
|
|
||||||
if (p.getAndAdvance() == '"')
|
if (p.getAndAdvance() == '"')
|
||||||
{
|
{
|
||||||
String::CharPointerType start (p);
|
auto start = p;
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
juce_wchar c = *p;
|
auto c = *p;
|
||||||
|
|
||||||
if (c == '"')
|
if (c == '"')
|
||||||
{
|
{
|
||||||
|
|
@ -101,7 +100,7 @@ struct TranslationHelpers
|
||||||
|
|
||||||
static juce_wchar readEscapedChar (String::CharPointerType& p)
|
static juce_wchar readEscapedChar (String::CharPointerType& p)
|
||||||
{
|
{
|
||||||
juce_wchar c = *p;
|
auto c = *p;
|
||||||
|
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -193,8 +193,8 @@ private:
|
||||||
private:
|
private:
|
||||||
String::CharPointerType p;
|
String::CharPointerType p;
|
||||||
|
|
||||||
static bool isIdentifierStart (const juce_wchar c) noexcept { return CharacterFunctions::isLetter (c) || c == '_'; }
|
static bool isIdentifierStart (juce_wchar c) noexcept { return CharacterFunctions::isLetter (c) || c == '_'; }
|
||||||
static bool isIdentifierBody (const juce_wchar c) noexcept { return CharacterFunctions::isLetterOrDigit (c) || c == '_'; }
|
static bool isIdentifierBody (juce_wchar c) noexcept { return CharacterFunctions::isLetterOrDigit (c) || c == '_'; }
|
||||||
|
|
||||||
TokenType matchNextToken()
|
TokenType matchNextToken()
|
||||||
{
|
{
|
||||||
|
|
@ -245,7 +245,7 @@ private:
|
||||||
|
|
||||||
if (*p == '/')
|
if (*p == '/')
|
||||||
{
|
{
|
||||||
const juce_wchar c2 = p[1];
|
auto c2 = p[1];
|
||||||
|
|
||||||
if (c2 == '/') { p = CharacterFunctions::find (p, (juce_wchar) '\n'); continue; }
|
if (c2 == '/') { p = CharacterFunctions::find (p, (juce_wchar) '\n'); continue; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ public:
|
||||||
*/
|
*/
|
||||||
LinkedListPointer& getLast() noexcept
|
LinkedListPointer& getLast() noexcept
|
||||||
{
|
{
|
||||||
LinkedListPointer* l = this;
|
auto* l = this;
|
||||||
|
|
||||||
while (l->item != nullptr)
|
while (l->item != nullptr)
|
||||||
l = &(l->item->nextListItem);
|
l = &(l->item->nextListItem);
|
||||||
|
|
@ -127,7 +127,7 @@ public:
|
||||||
{
|
{
|
||||||
int total = 0;
|
int total = 0;
|
||||||
|
|
||||||
for (ObjectType* i = item; i != nullptr; i = i->nextListItem)
|
for (auto* i = item; i != nullptr; i = i->nextListItem)
|
||||||
++total;
|
++total;
|
||||||
|
|
||||||
return total;
|
return total;
|
||||||
|
|
@ -139,7 +139,7 @@ public:
|
||||||
*/
|
*/
|
||||||
LinkedListPointer& operator[] (int index) noexcept
|
LinkedListPointer& operator[] (int index) noexcept
|
||||||
{
|
{
|
||||||
LinkedListPointer* l = this;
|
auto* l = this;
|
||||||
|
|
||||||
while (--index >= 0 && l->item != nullptr)
|
while (--index >= 0 && l->item != nullptr)
|
||||||
l = &(l->item->nextListItem);
|
l = &(l->item->nextListItem);
|
||||||
|
|
@ -153,7 +153,7 @@ public:
|
||||||
*/
|
*/
|
||||||
const LinkedListPointer& operator[] (int index) const noexcept
|
const LinkedListPointer& operator[] (int index) const noexcept
|
||||||
{
|
{
|
||||||
const LinkedListPointer* l = this;
|
auto* l = this;
|
||||||
|
|
||||||
while (--index >= 0 && l->item != nullptr)
|
while (--index >= 0 && l->item != nullptr)
|
||||||
l = &(l->item->nextListItem);
|
l = &(l->item->nextListItem);
|
||||||
|
|
@ -164,7 +164,7 @@ public:
|
||||||
/** Returns true if the list contains the given item. */
|
/** Returns true if the list contains the given item. */
|
||||||
bool contains (const ObjectType* const itemToLookFor) const noexcept
|
bool contains (const ObjectType* const itemToLookFor) const noexcept
|
||||||
{
|
{
|
||||||
for (ObjectType* i = item; i != nullptr; i = i->nextListItem)
|
for (auto* i = item; i != nullptr; i = i->nextListItem)
|
||||||
if (itemToLookFor == i)
|
if (itemToLookFor == i)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
@ -190,7 +190,7 @@ public:
|
||||||
void insertAtIndex (int index, ObjectType* newItem)
|
void insertAtIndex (int index, ObjectType* newItem)
|
||||||
{
|
{
|
||||||
jassert (newItem != nullptr);
|
jassert (newItem != nullptr);
|
||||||
LinkedListPointer* l = this;
|
auto* l = this;
|
||||||
|
|
||||||
while (index != 0 && l->item != nullptr)
|
while (index != 0 && l->item != nullptr)
|
||||||
{
|
{
|
||||||
|
|
@ -209,7 +209,7 @@ public:
|
||||||
jassert (newItem != nullptr);
|
jassert (newItem != nullptr);
|
||||||
jassert (newItem->nextListItem == nullptr);
|
jassert (newItem->nextListItem == nullptr);
|
||||||
|
|
||||||
ObjectType* const oldItem = item;
|
auto oldItem = item;
|
||||||
item = newItem;
|
item = newItem;
|
||||||
item->nextListItem = oldItem->nextListItem.item;
|
item->nextListItem = oldItem->nextListItem.item;
|
||||||
oldItem->nextListItem.item = nullptr;
|
oldItem->nextListItem.item = nullptr;
|
||||||
|
|
@ -233,9 +233,9 @@ public:
|
||||||
*/
|
*/
|
||||||
void addCopyOfList (const LinkedListPointer& other)
|
void addCopyOfList (const LinkedListPointer& other)
|
||||||
{
|
{
|
||||||
LinkedListPointer* insertPoint = this;
|
auto* insertPoint = this;
|
||||||
|
|
||||||
for (ObjectType* i = other.item; i != nullptr; i = i->nextListItem)
|
for (auto* i = other.item; i != nullptr; i = i->nextListItem)
|
||||||
{
|
{
|
||||||
insertPoint->insertNext (new ObjectType (*i));
|
insertPoint->insertNext (new ObjectType (*i));
|
||||||
insertPoint = &(insertPoint->item->nextListItem);
|
insertPoint = &(insertPoint->item->nextListItem);
|
||||||
|
|
@ -248,7 +248,7 @@ public:
|
||||||
*/
|
*/
|
||||||
ObjectType* removeNext() noexcept
|
ObjectType* removeNext() noexcept
|
||||||
{
|
{
|
||||||
ObjectType* const oldItem = item;
|
auto oldItem = item;
|
||||||
|
|
||||||
if (oldItem != nullptr)
|
if (oldItem != nullptr)
|
||||||
{
|
{
|
||||||
|
|
@ -264,7 +264,7 @@ public:
|
||||||
*/
|
*/
|
||||||
void remove (ObjectType* const itemToRemove)
|
void remove (ObjectType* const itemToRemove)
|
||||||
{
|
{
|
||||||
if (LinkedListPointer* const l = findPointerTo (itemToRemove))
|
if (auto* l = findPointerTo (itemToRemove))
|
||||||
l->removeNext();
|
l->removeNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -275,7 +275,7 @@ public:
|
||||||
{
|
{
|
||||||
while (item != nullptr)
|
while (item != nullptr)
|
||||||
{
|
{
|
||||||
ObjectType* const oldItem = item;
|
auto oldItem = item;
|
||||||
item = oldItem->nextListItem;
|
item = oldItem->nextListItem;
|
||||||
delete oldItem;
|
delete oldItem;
|
||||||
}
|
}
|
||||||
|
|
@ -287,7 +287,7 @@ public:
|
||||||
*/
|
*/
|
||||||
LinkedListPointer* findPointerTo (ObjectType* const itemToLookFor) noexcept
|
LinkedListPointer* findPointerTo (ObjectType* const itemToLookFor) noexcept
|
||||||
{
|
{
|
||||||
LinkedListPointer* l = this;
|
auto* l = this;
|
||||||
|
|
||||||
while (l->item != nullptr)
|
while (l->item != nullptr)
|
||||||
{
|
{
|
||||||
|
|
@ -308,7 +308,7 @@ public:
|
||||||
{
|
{
|
||||||
jassert (destArray != nullptr);
|
jassert (destArray != nullptr);
|
||||||
|
|
||||||
for (ObjectType* i = item; i != nullptr; i = i->nextListItem)
|
for (auto* i = item; i != nullptr; i = i->nextListItem)
|
||||||
*destArray++ = i;
|
*destArray++ = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,9 +52,7 @@ int findHighestSetBit (uint32 n) noexcept
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
BigInteger::BigInteger()
|
BigInteger::BigInteger()
|
||||||
: allocatedSize (numPreallocatedInts),
|
: allocatedSize (numPreallocatedInts)
|
||||||
highestBit (-1),
|
|
||||||
negative (false)
|
|
||||||
{
|
{
|
||||||
for (int i = 0; i < numPreallocatedInts; ++i)
|
for (int i = 0; i < numPreallocatedInts; ++i)
|
||||||
preallocated[i] = 0;
|
preallocated[i] = 0;
|
||||||
|
|
@ -75,8 +73,7 @@ BigInteger::BigInteger (const int32 value)
|
||||||
|
|
||||||
BigInteger::BigInteger (const uint32 value)
|
BigInteger::BigInteger (const uint32 value)
|
||||||
: allocatedSize (numPreallocatedInts),
|
: allocatedSize (numPreallocatedInts),
|
||||||
highestBit (31),
|
highestBit (31)
|
||||||
negative (false)
|
|
||||||
{
|
{
|
||||||
preallocated[0] = value;
|
preallocated[0] = value;
|
||||||
|
|
||||||
|
|
@ -153,7 +150,7 @@ BigInteger& BigInteger::operator= (const BigInteger& other)
|
||||||
if (this != &other)
|
if (this != &other)
|
||||||
{
|
{
|
||||||
highestBit = other.getHighestBit();
|
highestBit = other.getHighestBit();
|
||||||
const size_t newAllocatedSize = (size_t) jmax ((size_t) numPreallocatedInts, sizeNeededToHold (highestBit));
|
auto newAllocatedSize = (size_t) jmax ((size_t) numPreallocatedInts, sizeNeededToHold (highestBit));
|
||||||
|
|
||||||
if (newAllocatedSize <= numPreallocatedInts)
|
if (newAllocatedSize <= numPreallocatedInts)
|
||||||
heapAllocation.free();
|
heapAllocation.free();
|
||||||
|
|
@ -181,7 +178,7 @@ uint32* BigInteger::ensureSize (const size_t numVals)
|
||||||
{
|
{
|
||||||
if (numVals > allocatedSize)
|
if (numVals > allocatedSize)
|
||||||
{
|
{
|
||||||
size_t oldSize = allocatedSize;
|
auto oldSize = allocatedSize;
|
||||||
allocatedSize = ((numVals + 2) * 3) / 2;
|
allocatedSize = ((numVals + 2) * 3) / 2;
|
||||||
|
|
||||||
if (heapAllocation == nullptr)
|
if (heapAllocation == nullptr)
|
||||||
|
|
@ -193,7 +190,7 @@ uint32* BigInteger::ensureSize (const size_t numVals)
|
||||||
{
|
{
|
||||||
heapAllocation.realloc (allocatedSize);
|
heapAllocation.realloc (allocatedSize);
|
||||||
|
|
||||||
for (uint32* values = getValues(); oldSize < allocatedSize; ++oldSize)
|
for (auto* values = getValues(); oldSize < allocatedSize; ++oldSize)
|
||||||
values[oldSize] = 0;
|
values[oldSize] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -210,14 +207,14 @@ bool BigInteger::operator[] (const int bit) const noexcept
|
||||||
|
|
||||||
int BigInteger::toInteger() const noexcept
|
int BigInteger::toInteger() const noexcept
|
||||||
{
|
{
|
||||||
const int n = (int) (getValues()[0] & 0x7fffffff);
|
auto n = (int) (getValues()[0] & 0x7fffffff);
|
||||||
return negative ? -n : n;
|
return negative ? -n : n;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64 BigInteger::toInt64() const noexcept
|
int64 BigInteger::toInt64() const noexcept
|
||||||
{
|
{
|
||||||
const uint32* values = getValues();
|
auto* values = getValues();
|
||||||
const int64 n = (((int64) (values[1] & 0x7fffffff)) << 32) | values[0];
|
auto n = (((int64) (values[1] & 0x7fffffff)) << 32) | values[0];
|
||||||
return negative ? -n : n;
|
return negative ? -n : n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -225,7 +222,7 @@ BigInteger BigInteger::getBitRange (int startBit, int numBits) const
|
||||||
{
|
{
|
||||||
BigInteger r;
|
BigInteger r;
|
||||||
numBits = jmin (numBits, getHighestBit() + 1 - startBit);
|
numBits = jmin (numBits, getHighestBit() + 1 - startBit);
|
||||||
uint32* const destValues = r.ensureSize (sizeNeededToHold (numBits));
|
auto* destValues = r.ensureSize (sizeNeededToHold (numBits));
|
||||||
r.highestBit = numBits;
|
r.highestBit = numBits;
|
||||||
|
|
||||||
for (int i = 0; numBits > 0;)
|
for (int i = 0; numBits > 0;)
|
||||||
|
|
@ -252,12 +249,12 @@ uint32 BigInteger::getBitRangeAsInt (const int startBit, int numBits) const noex
|
||||||
if (numBits <= 0)
|
if (numBits <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
const size_t pos = bitToIndex (startBit);
|
auto pos = bitToIndex (startBit);
|
||||||
const int offset = startBit & 31;
|
auto offset = startBit & 31;
|
||||||
const int endSpace = 32 - numBits;
|
auto endSpace = 32 - numBits;
|
||||||
const uint32* values = getValues();
|
auto* values = getValues();
|
||||||
|
|
||||||
uint32 n = ((uint32) values [pos]) >> offset;
|
auto n = ((uint32) values [pos]) >> offset;
|
||||||
|
|
||||||
if (offset > endSpace)
|
if (offset > endSpace)
|
||||||
n |= ((uint32) values [pos + 1]) << (32 - offset);
|
n |= ((uint32) values [pos + 1]) << (32 - offset);
|
||||||
|
|
@ -372,7 +369,7 @@ void BigInteger::negate() noexcept
|
||||||
int BigInteger::countNumberOfSetBits() const noexcept
|
int BigInteger::countNumberOfSetBits() const noexcept
|
||||||
{
|
{
|
||||||
int total = 0;
|
int total = 0;
|
||||||
const uint32* values = getValues();
|
auto* values = getValues();
|
||||||
|
|
||||||
for (int i = (int) sizeNeededToHold (highestBit); --i >= 0;)
|
for (int i = (int) sizeNeededToHold (highestBit); --i >= 0;)
|
||||||
total += countNumberOfBits (values[i]);
|
total += countNumberOfBits (values[i]);
|
||||||
|
|
@ -382,7 +379,7 @@ int BigInteger::countNumberOfSetBits() const noexcept
|
||||||
|
|
||||||
int BigInteger::getHighestBit() const noexcept
|
int BigInteger::getHighestBit() const noexcept
|
||||||
{
|
{
|
||||||
const uint32* values = getValues();
|
auto* values = getValues();
|
||||||
|
|
||||||
for (int i = (int) bitToIndex (highestBit); i >= 0; --i)
|
for (int i = (int) bitToIndex (highestBit); i >= 0; --i)
|
||||||
if (uint32 n = values[i])
|
if (uint32 n = values[i])
|
||||||
|
|
@ -393,7 +390,7 @@ int BigInteger::getHighestBit() const noexcept
|
||||||
|
|
||||||
int BigInteger::findNextSetBit (int i) const noexcept
|
int BigInteger::findNextSetBit (int i) const noexcept
|
||||||
{
|
{
|
||||||
const uint32* values = getValues();
|
auto* values = getValues();
|
||||||
|
|
||||||
for (; i <= highestBit; ++i)
|
for (; i <= highestBit; ++i)
|
||||||
if ((values [bitToIndex (i)] & bitToMask (i)) != 0)
|
if ((values [bitToIndex (i)] & bitToMask (i)) != 0)
|
||||||
|
|
@ -404,7 +401,7 @@ int BigInteger::findNextSetBit (int i) const noexcept
|
||||||
|
|
||||||
int BigInteger::findNextClearBit (int i) const noexcept
|
int BigInteger::findNextClearBit (int i) const noexcept
|
||||||
{
|
{
|
||||||
const uint32* values = getValues();
|
auto* values = getValues();
|
||||||
|
|
||||||
for (; i <= highestBit; ++i)
|
for (; i <= highestBit; ++i)
|
||||||
if ((values [bitToIndex (i)] & bitToMask (i)) == 0)
|
if ((values [bitToIndex (i)] & bitToMask (i)) == 0)
|
||||||
|
|
@ -426,7 +423,7 @@ BigInteger& BigInteger::operator+= (const BigInteger& other)
|
||||||
{
|
{
|
||||||
if (compareAbsolute (other) < 0)
|
if (compareAbsolute (other) < 0)
|
||||||
{
|
{
|
||||||
BigInteger temp (*this);
|
auto temp = *this;
|
||||||
temp.negate();
|
temp.negate();
|
||||||
*this = other;
|
*this = other;
|
||||||
*this -= temp;
|
*this -= temp;
|
||||||
|
|
@ -442,9 +439,9 @@ BigInteger& BigInteger::operator+= (const BigInteger& other)
|
||||||
{
|
{
|
||||||
highestBit = jmax (highestBit, other.highestBit) + 1;
|
highestBit = jmax (highestBit, other.highestBit) + 1;
|
||||||
|
|
||||||
const size_t numInts = sizeNeededToHold (highestBit);
|
auto numInts = sizeNeededToHold (highestBit);
|
||||||
uint32* const values = ensureSize (numInts);
|
auto* values = ensureSize (numInts);
|
||||||
const uint32* const otherValues = other.getValues();
|
auto* otherValues = other.getValues();
|
||||||
int64 remainder = 0;
|
int64 remainder = 0;
|
||||||
|
|
||||||
for (size_t i = 0; i < numInts; ++i)
|
for (size_t i = 0; i < numInts; ++i)
|
||||||
|
|
@ -486,18 +483,18 @@ BigInteger& BigInteger::operator-= (const BigInteger& other)
|
||||||
|
|
||||||
if (compareAbsolute (other) < 0)
|
if (compareAbsolute (other) < 0)
|
||||||
{
|
{
|
||||||
BigInteger temp (other);
|
auto temp = other;
|
||||||
swapWith (temp);
|
swapWith (temp);
|
||||||
*this -= temp;
|
*this -= temp;
|
||||||
negate();
|
negate();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t numInts = sizeNeededToHold (getHighestBit());
|
auto numInts = sizeNeededToHold (getHighestBit());
|
||||||
const size_t maxOtherInts = sizeNeededToHold (other.getHighestBit());
|
auto maxOtherInts = sizeNeededToHold (other.getHighestBit());
|
||||||
jassert (numInts >= maxOtherInts);
|
jassert (numInts >= maxOtherInts);
|
||||||
uint32* const values = getValues();
|
auto* values = getValues();
|
||||||
const uint32* const otherValues = other.getValues();
|
auto* otherValues = other.getValues();
|
||||||
int64 amountToSubtract = 0;
|
int64 amountToSubtract = 0;
|
||||||
|
|
||||||
for (size_t i = 0; i < numInts; ++i)
|
for (size_t i = 0; i < numInts; ++i)
|
||||||
|
|
@ -527,24 +524,24 @@ BigInteger& BigInteger::operator*= (const BigInteger& other)
|
||||||
if (this == &other)
|
if (this == &other)
|
||||||
return operator*= (BigInteger (other));
|
return operator*= (BigInteger (other));
|
||||||
|
|
||||||
int n = getHighestBit();
|
auto n = getHighestBit();
|
||||||
int t = other.getHighestBit();
|
auto t = other.getHighestBit();
|
||||||
|
|
||||||
const bool wasNegative = isNegative();
|
auto wasNegative = isNegative();
|
||||||
setNegative (false);
|
setNegative (false);
|
||||||
|
|
||||||
BigInteger total;
|
BigInteger total;
|
||||||
total.highestBit = n + t + 1;
|
total.highestBit = n + t + 1;
|
||||||
uint32* const totalValues = total.ensureSize (sizeNeededToHold (total.highestBit) + 1);
|
auto* totalValues = total.ensureSize (sizeNeededToHold (total.highestBit) + 1);
|
||||||
|
|
||||||
n >>= 5;
|
n >>= 5;
|
||||||
t >>= 5;
|
t >>= 5;
|
||||||
|
|
||||||
BigInteger m (other);
|
auto m = other;
|
||||||
m.setNegative (false);
|
m.setNegative (false);
|
||||||
|
|
||||||
const uint32* const mValues = m.getValues();
|
auto* mValues = m.getValues();
|
||||||
const uint32* const values = getValues();
|
auto* values = getValues();
|
||||||
|
|
||||||
for (int i = 0; i <= t; ++i)
|
for (int i = 0; i <= t; ++i)
|
||||||
{
|
{
|
||||||
|
|
@ -552,7 +549,7 @@ BigInteger& BigInteger::operator*= (const BigInteger& other)
|
||||||
|
|
||||||
for (int j = 0; j <= n; ++j)
|
for (int j = 0; j <= n; ++j)
|
||||||
{
|
{
|
||||||
uint64 uv = (uint64) totalValues[i + j] + (uint64) values[j] * (uint64) mValues[i] + (uint64) c;
|
auto uv = (uint64) totalValues[i + j] + (uint64) values[j] * (uint64) mValues[i] + (uint64) c;
|
||||||
totalValues[i + j] = (uint32) uv;
|
totalValues[i + j] = (uint32) uv;
|
||||||
c = uv >> 32;
|
c = uv >> 32;
|
||||||
}
|
}
|
||||||
|
|
@ -574,8 +571,8 @@ void BigInteger::divideBy (const BigInteger& divisor, BigInteger& remainder)
|
||||||
|
|
||||||
jassert (this != &remainder); // (can't handle passing itself in to get the remainder)
|
jassert (this != &remainder); // (can't handle passing itself in to get the remainder)
|
||||||
|
|
||||||
const int divHB = divisor.getHighestBit();
|
auto divHB = divisor.getHighestBit();
|
||||||
const int ourHB = getHighestBit();
|
auto ourHB = getHighestBit();
|
||||||
|
|
||||||
if (divHB < 0 || ourHB < 0)
|
if (divHB < 0 || ourHB < 0)
|
||||||
{
|
{
|
||||||
|
|
@ -585,7 +582,7 @@ void BigInteger::divideBy (const BigInteger& divisor, BigInteger& remainder)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const bool wasNegative = isNegative();
|
auto wasNegative = isNegative();
|
||||||
|
|
||||||
swapWith (remainder);
|
swapWith (remainder);
|
||||||
remainder.setNegative (false);
|
remainder.setNegative (false);
|
||||||
|
|
@ -594,7 +591,7 @@ void BigInteger::divideBy (const BigInteger& divisor, BigInteger& remainder)
|
||||||
BigInteger temp (divisor);
|
BigInteger temp (divisor);
|
||||||
temp.setNegative (false);
|
temp.setNegative (false);
|
||||||
|
|
||||||
int leftShift = ourHB - divHB;
|
auto leftShift = ourHB - divHB;
|
||||||
temp <<= leftShift;
|
temp <<= leftShift;
|
||||||
|
|
||||||
while (leftShift >= 0)
|
while (leftShift >= 0)
|
||||||
|
|
@ -631,10 +628,10 @@ BigInteger& BigInteger::operator|= (const BigInteger& other)
|
||||||
|
|
||||||
if (other.highestBit >= 0)
|
if (other.highestBit >= 0)
|
||||||
{
|
{
|
||||||
uint32* const values = ensureSize (sizeNeededToHold (other.highestBit));
|
auto* values = ensureSize (sizeNeededToHold (other.highestBit));
|
||||||
const uint32* const otherValues = other.getValues();
|
auto* otherValues = other.getValues();
|
||||||
|
|
||||||
int n = (int) bitToIndex (other.highestBit) + 1;
|
auto n = (int) bitToIndex (other.highestBit) + 1;
|
||||||
|
|
||||||
while (--n >= 0)
|
while (--n >= 0)
|
||||||
values[n] |= otherValues[n];
|
values[n] |= otherValues[n];
|
||||||
|
|
@ -656,10 +653,10 @@ BigInteger& BigInteger::operator&= (const BigInteger& other)
|
||||||
// this operation doesn't take into account negative values..
|
// this operation doesn't take into account negative values..
|
||||||
jassert (isNegative() == other.isNegative());
|
jassert (isNegative() == other.isNegative());
|
||||||
|
|
||||||
uint32* const values = getValues();
|
auto* values = getValues();
|
||||||
const uint32* const otherValues = other.getValues();
|
auto* otherValues = other.getValues();
|
||||||
|
|
||||||
int n = (int) allocatedSize;
|
auto n = (int) allocatedSize;
|
||||||
|
|
||||||
while (n > (int) other.allocatedSize)
|
while (n > (int) other.allocatedSize)
|
||||||
values[--n] = 0;
|
values[--n] = 0;
|
||||||
|
|
@ -687,10 +684,10 @@ BigInteger& BigInteger::operator^= (const BigInteger& other)
|
||||||
|
|
||||||
if (other.highestBit >= 0)
|
if (other.highestBit >= 0)
|
||||||
{
|
{
|
||||||
uint32* const values = ensureSize (sizeNeededToHold (other.highestBit));
|
auto* values = ensureSize (sizeNeededToHold (other.highestBit));
|
||||||
const uint32* const otherValues = other.getValues();
|
auto* otherValues = other.getValues();
|
||||||
|
|
||||||
int n = (int) bitToIndex (other.highestBit) + 1;
|
auto n = (int) bitToIndex (other.highestBit) + 1;
|
||||||
|
|
||||||
while (--n >= 0)
|
while (--n >= 0)
|
||||||
values[n] ^= otherValues[n];
|
values[n] ^= otherValues[n];
|
||||||
|
|
@ -714,31 +711,31 @@ BigInteger& BigInteger::operator%= (const BigInteger& divisor)
|
||||||
|
|
||||||
BigInteger& BigInteger::operator++() { return operator+= (1); }
|
BigInteger& BigInteger::operator++() { return operator+= (1); }
|
||||||
BigInteger& BigInteger::operator--() { return operator-= (1); }
|
BigInteger& BigInteger::operator--() { return operator-= (1); }
|
||||||
BigInteger BigInteger::operator++ (int) { const BigInteger old (*this); operator+= (1); return old; }
|
BigInteger BigInteger::operator++ (int) { const auto old (*this); operator+= (1); return old; }
|
||||||
BigInteger BigInteger::operator-- (int) { const BigInteger old (*this); operator-= (1); return old; }
|
BigInteger BigInteger::operator-- (int) { const auto old (*this); operator-= (1); return old; }
|
||||||
|
|
||||||
BigInteger BigInteger::operator-() const { BigInteger b (*this); b.negate(); return b; }
|
BigInteger BigInteger::operator-() const { auto b (*this); b.negate(); return b; }
|
||||||
BigInteger BigInteger::operator+ (const BigInteger& other) const { BigInteger b (*this); return b += other; }
|
BigInteger BigInteger::operator+ (const BigInteger& other) const { auto b (*this); return b += other; }
|
||||||
BigInteger BigInteger::operator- (const BigInteger& other) const { BigInteger b (*this); return b -= other; }
|
BigInteger BigInteger::operator- (const BigInteger& other) const { auto b (*this); return b -= other; }
|
||||||
BigInteger BigInteger::operator* (const BigInteger& other) const { BigInteger b (*this); return b *= other; }
|
BigInteger BigInteger::operator* (const BigInteger& other) const { auto b (*this); return b *= other; }
|
||||||
BigInteger BigInteger::operator/ (const BigInteger& other) const { BigInteger b (*this); return b /= other; }
|
BigInteger BigInteger::operator/ (const BigInteger& other) const { auto b (*this); return b /= other; }
|
||||||
BigInteger BigInteger::operator| (const BigInteger& other) const { BigInteger b (*this); return b |= other; }
|
BigInteger BigInteger::operator| (const BigInteger& other) const { auto b (*this); return b |= other; }
|
||||||
BigInteger BigInteger::operator& (const BigInteger& other) const { BigInteger b (*this); return b &= other; }
|
BigInteger BigInteger::operator& (const BigInteger& other) const { auto b (*this); return b &= other; }
|
||||||
BigInteger BigInteger::operator^ (const BigInteger& other) const { BigInteger b (*this); return b ^= other; }
|
BigInteger BigInteger::operator^ (const BigInteger& other) const { auto b (*this); return b ^= other; }
|
||||||
BigInteger BigInteger::operator% (const BigInteger& other) const { BigInteger b (*this); return b %= other; }
|
BigInteger BigInteger::operator% (const BigInteger& other) const { auto b (*this); return b %= other; }
|
||||||
BigInteger BigInteger::operator<< (const int numBits) const { BigInteger b (*this); return b <<= numBits; }
|
BigInteger BigInteger::operator<< (const int numBits) const { auto b (*this); return b <<= numBits; }
|
||||||
BigInteger BigInteger::operator>> (const int numBits) const { BigInteger b (*this); return b >>= numBits; }
|
BigInteger BigInteger::operator>> (const int numBits) const { auto b (*this); return b >>= numBits; }
|
||||||
BigInteger& BigInteger::operator<<= (const int numBits) { shiftBits (numBits, 0); return *this; }
|
BigInteger& BigInteger::operator<<= (const int numBits) { shiftBits (numBits, 0); return *this; }
|
||||||
BigInteger& BigInteger::operator>>= (const int numBits) { shiftBits (-numBits, 0); return *this; }
|
BigInteger& BigInteger::operator>>= (const int numBits) { shiftBits (-numBits, 0); return *this; }
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
int BigInteger::compare (const BigInteger& other) const noexcept
|
int BigInteger::compare (const BigInteger& other) const noexcept
|
||||||
{
|
{
|
||||||
const bool isNeg = isNegative();
|
auto isNeg = isNegative();
|
||||||
|
|
||||||
if (isNeg == other.isNegative())
|
if (isNeg == other.isNegative())
|
||||||
{
|
{
|
||||||
const int absComp = compareAbsolute (other);
|
auto absComp = compareAbsolute (other);
|
||||||
return isNeg ? -absComp : absComp;
|
return isNeg ? -absComp : absComp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -747,14 +744,14 @@ int BigInteger::compare (const BigInteger& other) const noexcept
|
||||||
|
|
||||||
int BigInteger::compareAbsolute (const BigInteger& other) const noexcept
|
int BigInteger::compareAbsolute (const BigInteger& other) const noexcept
|
||||||
{
|
{
|
||||||
const int h1 = getHighestBit();
|
auto h1 = getHighestBit();
|
||||||
const int h2 = other.getHighestBit();
|
auto h2 = other.getHighestBit();
|
||||||
|
|
||||||
if (h1 > h2) return 1;
|
if (h1 > h2) return 1;
|
||||||
if (h1 < h2) return -1;
|
if (h1 < h2) return -1;
|
||||||
|
|
||||||
const uint32* const values = getValues();
|
auto* values = getValues();
|
||||||
const uint32* const otherValues = other.getValues();
|
auto* otherValues = other.getValues();
|
||||||
|
|
||||||
for (int i = (int) bitToIndex (h1); i >= 0; --i)
|
for (int i = (int) bitToIndex (h1); i >= 0; --i)
|
||||||
if (values[i] != otherValues[i])
|
if (values[i] != otherValues[i])
|
||||||
|
|
@ -783,10 +780,9 @@ void BigInteger::shiftLeft (int bits, const int startBit)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uint32* const values = ensureSize (sizeNeededToHold (highestBit + bits));
|
auto* values = ensureSize (sizeNeededToHold (highestBit + bits));
|
||||||
|
auto wordsToMove = bitToIndex (bits);
|
||||||
const size_t wordsToMove = bitToIndex (bits);
|
auto numOriginalInts = bitToIndex (highestBit);
|
||||||
size_t numOriginalInts = bitToIndex (highestBit);
|
|
||||||
highestBit += bits;
|
highestBit += bits;
|
||||||
|
|
||||||
if (wordsToMove > 0)
|
if (wordsToMove > 0)
|
||||||
|
|
@ -802,7 +798,7 @@ void BigInteger::shiftLeft (int bits, const int startBit)
|
||||||
|
|
||||||
if (bits != 0)
|
if (bits != 0)
|
||||||
{
|
{
|
||||||
const int invBits = 32 - bits;
|
auto invBits = 32 - bits;
|
||||||
|
|
||||||
for (size_t i = bitToIndex (highestBit); i > wordsToMove; --i)
|
for (size_t i = bitToIndex (highestBit); i > wordsToMove; --i)
|
||||||
values[i] = (values[i] << bits) | (values[i - 1] >> invBits);
|
values[i] = (values[i] << bits) | (values[i - 1] >> invBits);
|
||||||
|
|
@ -831,18 +827,17 @@ void BigInteger::shiftRight (int bits, const int startBit)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const size_t wordsToMove = bitToIndex (bits);
|
auto wordsToMove = bitToIndex (bits);
|
||||||
size_t top = 1 + bitToIndex (highestBit) - wordsToMove;
|
auto top = 1 + bitToIndex (highestBit) - wordsToMove;
|
||||||
highestBit -= bits;
|
highestBit -= bits;
|
||||||
uint32* const values = getValues();
|
auto* values = getValues();
|
||||||
|
|
||||||
if (wordsToMove > 0)
|
if (wordsToMove > 0)
|
||||||
{
|
{
|
||||||
size_t i;
|
for (size_t i = 0; i < top; ++i)
|
||||||
for (i = 0; i < top; ++i)
|
|
||||||
values[i] = values[i + wordsToMove];
|
values[i] = values[i + wordsToMove];
|
||||||
|
|
||||||
for (i = 0; i < wordsToMove; ++i)
|
for (size_t i = 0; i < wordsToMove; ++i)
|
||||||
values[top + i] = 0;
|
values[top + i] = 0;
|
||||||
|
|
||||||
bits &= 31;
|
bits &= 31;
|
||||||
|
|
@ -850,7 +845,7 @@ void BigInteger::shiftRight (int bits, const int startBit)
|
||||||
|
|
||||||
if (bits != 0)
|
if (bits != 0)
|
||||||
{
|
{
|
||||||
const int invBits = 32 - bits;
|
auto invBits = 32 - bits;
|
||||||
--top;
|
--top;
|
||||||
|
|
||||||
for (size_t i = 0; i < top; ++i)
|
for (size_t i = 0; i < top; ++i)
|
||||||
|
|
@ -891,7 +886,7 @@ static BigInteger simpleGCD (BigInteger* m, BigInteger* n)
|
||||||
|
|
||||||
BigInteger BigInteger::findGreatestCommonDivisor (BigInteger n) const
|
BigInteger BigInteger::findGreatestCommonDivisor (BigInteger n) const
|
||||||
{
|
{
|
||||||
BigInteger m (*this);
|
auto m = *this;
|
||||||
|
|
||||||
while (! n.isZero())
|
while (! n.isZero())
|
||||||
{
|
{
|
||||||
|
|
@ -911,14 +906,13 @@ BigInteger BigInteger::findGreatestCommonDivisor (BigInteger n) const
|
||||||
void BigInteger::exponentModulo (const BigInteger& exponent, const BigInteger& modulus)
|
void BigInteger::exponentModulo (const BigInteger& exponent, const BigInteger& modulus)
|
||||||
{
|
{
|
||||||
*this %= modulus;
|
*this %= modulus;
|
||||||
BigInteger exp (exponent);
|
auto exp = exponent;
|
||||||
exp %= modulus;
|
exp %= modulus;
|
||||||
|
|
||||||
if (modulus.getHighestBit() <= 32 || modulus % 2 == 0)
|
if (modulus.getHighestBit() <= 32 || modulus % 2 == 0)
|
||||||
{
|
{
|
||||||
BigInteger a (*this);
|
auto a = *this;
|
||||||
|
auto n = exp.getHighestBit();
|
||||||
const int n = exp.getHighestBit();
|
|
||||||
|
|
||||||
for (int i = n; --i >= 0;)
|
for (int i = n; --i >= 0;)
|
||||||
{
|
{
|
||||||
|
|
@ -933,7 +927,7 @@ void BigInteger::exponentModulo (const BigInteger& exponent, const BigInteger& m
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const int Rfactor = modulus.getHighestBit() + 1;
|
auto Rfactor = modulus.getHighestBit() + 1;
|
||||||
BigInteger R (1);
|
BigInteger R (1);
|
||||||
R.shiftLeft (Rfactor, 0);
|
R.shiftLeft (Rfactor, 0);
|
||||||
|
|
||||||
|
|
@ -957,9 +951,9 @@ void BigInteger::exponentModulo (const BigInteger& exponent, const BigInteger& m
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
BigInteger am (((*this) * R) % modulus);
|
auto am = (*this * R) % modulus;
|
||||||
BigInteger xm (am);
|
auto xm = am;
|
||||||
BigInteger um (R % modulus);
|
auto um = R % modulus;
|
||||||
|
|
||||||
for (int i = exp.getHighestBit(); --i >= 0;)
|
for (int i = exp.getHighestBit(); --i >= 0;)
|
||||||
{
|
{
|
||||||
|
|
@ -979,8 +973,7 @@ void BigInteger::montgomeryMultiplication (const BigInteger& other, const BigInt
|
||||||
const BigInteger& modulusp, const int k)
|
const BigInteger& modulusp, const int k)
|
||||||
{
|
{
|
||||||
*this *= other;
|
*this *= other;
|
||||||
|
auto t = *this;
|
||||||
BigInteger t (*this);
|
|
||||||
|
|
||||||
setRange (k, highestBit - k + 1, false);
|
setRange (k, highestBit - k + 1, false);
|
||||||
*this *= modulusp;
|
*this *= modulusp;
|
||||||
|
|
@ -1000,7 +993,6 @@ void BigInteger::extendedEuclidean (const BigInteger& a, const BigInteger& b,
|
||||||
BigInteger& x, BigInteger& y)
|
BigInteger& x, BigInteger& y)
|
||||||
{
|
{
|
||||||
BigInteger p(a), q(b), gcd(1);
|
BigInteger p(a), q(b), gcd(1);
|
||||||
|
|
||||||
Array<BigInteger> tempValues;
|
Array<BigInteger> tempValues;
|
||||||
|
|
||||||
while (! q.isZero())
|
while (! q.isZero())
|
||||||
|
|
@ -1016,7 +1008,7 @@ void BigInteger::extendedEuclidean (const BigInteger& a, const BigInteger& b,
|
||||||
|
|
||||||
for (int i = 1; i < tempValues.size(); ++i)
|
for (int i = 1; i < tempValues.size(); ++i)
|
||||||
{
|
{
|
||||||
const BigInteger& v = tempValues.getReference (tempValues.size() - i - 1);
|
auto& v = tempValues.getReference (tempValues.size() - i - 1);
|
||||||
|
|
||||||
if ((i & 1) != 0)
|
if ((i & 1) != 0)
|
||||||
x += y * v;
|
x += y * v;
|
||||||
|
|
@ -1054,8 +1046,8 @@ void BigInteger::inverseModulo (const BigInteger& modulus)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BigInteger a1 (modulus), a2 (*this);
|
BigInteger a1 (modulus), a2 (*this),
|
||||||
BigInteger b1 (modulus), b2 (1);
|
b1 (modulus), b2 (1);
|
||||||
|
|
||||||
while (! a2.isOne())
|
while (! a2.isOne())
|
||||||
{
|
{
|
||||||
|
|
@ -1064,7 +1056,7 @@ void BigInteger::inverseModulo (const BigInteger& modulus)
|
||||||
|
|
||||||
temp1 = a2;
|
temp1 = a2;
|
||||||
temp1 *= multiplier;
|
temp1 *= multiplier;
|
||||||
BigInteger temp2 (a1);
|
auto temp2 = a1;
|
||||||
temp2 -= temp1;
|
temp2 -= temp1;
|
||||||
a1 = a2;
|
a1 = a2;
|
||||||
a2 = temp2;
|
a2 = temp2;
|
||||||
|
|
@ -1093,17 +1085,16 @@ OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const BigInteger&
|
||||||
String BigInteger::toString (const int base, const int minimumNumCharacters) const
|
String BigInteger::toString (const int base, const int minimumNumCharacters) const
|
||||||
{
|
{
|
||||||
String s;
|
String s;
|
||||||
BigInteger v (*this);
|
auto v = *this;
|
||||||
|
|
||||||
if (base == 2 || base == 8 || base == 16)
|
if (base == 2 || base == 8 || base == 16)
|
||||||
{
|
{
|
||||||
const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
|
auto bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
|
||||||
static const char hexDigits[] = "0123456789abcdef";
|
static const char hexDigits[] = "0123456789abcdef";
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
const uint32 remainder = v.getBitRangeAsInt (0, bits);
|
auto remainder = v.getBitRangeAsInt (0, bits);
|
||||||
|
|
||||||
v >>= bits;
|
v >>= bits;
|
||||||
|
|
||||||
if (remainder == 0 && v.isZero())
|
if (remainder == 0 && v.isZero())
|
||||||
|
|
@ -1141,18 +1132,18 @@ String BigInteger::toString (const int base, const int minimumNumCharacters) con
|
||||||
void BigInteger::parseString (StringRef text, const int base)
|
void BigInteger::parseString (StringRef text, const int base)
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
String::CharPointerType t (text.text.findEndOfWhitespace());
|
auto t = text.text.findEndOfWhitespace();
|
||||||
|
|
||||||
setNegative (*t == (juce_wchar) '-');
|
setNegative (*t == (juce_wchar) '-');
|
||||||
|
|
||||||
if (base == 2 || base == 8 || base == 16)
|
if (base == 2 || base == 8 || base == 16)
|
||||||
{
|
{
|
||||||
const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
|
auto bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
const juce_wchar c = t.getAndAdvance();
|
auto c = t.getAndAdvance();
|
||||||
const int digit = CharacterFunctions::getHexDigitValue (c);
|
auto digit = CharacterFunctions::getHexDigitValue (c);
|
||||||
|
|
||||||
if (((uint32) digit) < (uint32) base)
|
if (((uint32) digit) < (uint32) base)
|
||||||
{
|
{
|
||||||
|
|
@ -1171,7 +1162,7 @@ void BigInteger::parseString (StringRef text, const int base)
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
const juce_wchar c = t.getAndAdvance();
|
auto c = t.getAndAdvance();
|
||||||
|
|
||||||
if (c >= '0' && c <= '9')
|
if (c >= '0' && c <= '9')
|
||||||
{
|
{
|
||||||
|
|
@ -1188,9 +1179,9 @@ void BigInteger::parseString (StringRef text, const int base)
|
||||||
|
|
||||||
MemoryBlock BigInteger::toMemoryBlock() const
|
MemoryBlock BigInteger::toMemoryBlock() const
|
||||||
{
|
{
|
||||||
const int numBytes = (getHighestBit() + 8) >> 3;
|
auto numBytes = (getHighestBit() + 8) >> 3;
|
||||||
MemoryBlock mb ((size_t) numBytes);
|
MemoryBlock mb ((size_t) numBytes);
|
||||||
const uint32* const values = getValues();
|
auto* values = getValues();
|
||||||
|
|
||||||
for (int i = 0; i < numBytes; ++i)
|
for (int i = 0; i < numBytes; ++i)
|
||||||
mb[i] = (char) ((values[i / 4] >> ((i & 3) * 8)) & 0xff);
|
mb[i] = (char) ((values[i / 4] >> ((i & 3) * 8)) & 0xff);
|
||||||
|
|
@ -1200,9 +1191,9 @@ MemoryBlock BigInteger::toMemoryBlock() const
|
||||||
|
|
||||||
void BigInteger::loadFromMemoryBlock (const MemoryBlock& data)
|
void BigInteger::loadFromMemoryBlock (const MemoryBlock& data)
|
||||||
{
|
{
|
||||||
const size_t numBytes = data.getSize();
|
auto numBytes = data.getSize();
|
||||||
const size_t numInts = 1 + (numBytes / sizeof (uint32));
|
auto numInts = 1 + (numBytes / sizeof (uint32));
|
||||||
uint32* const values = ensureSize (numInts);
|
auto* values = ensureSize (numInts);
|
||||||
|
|
||||||
for (int i = 0; i < (int) numInts - 1; ++i)
|
for (int i = 0; i < (int) numInts - 1; ++i)
|
||||||
values[i] = (uint32) ByteOrder::littleEndianInt (addBytesToPointer (data.getData(), sizeof (uint32) * (size_t) i));
|
values[i] = (uint32) ByteOrder::littleEndianInt (addBytesToPointer (data.getData(), sizeof (uint32) * (size_t) i));
|
||||||
|
|
|
||||||
|
|
@ -323,8 +323,8 @@ private:
|
||||||
HeapBlock<uint32> heapAllocation;
|
HeapBlock<uint32> heapAllocation;
|
||||||
uint32 preallocated[numPreallocatedInts];
|
uint32 preallocated[numPreallocatedInts];
|
||||||
size_t allocatedSize;
|
size_t allocatedSize;
|
||||||
int highestBit;
|
int highestBit = -1;
|
||||||
bool negative;
|
bool negative = false;
|
||||||
|
|
||||||
uint32* getValues() const noexcept;
|
uint32* getValues() const noexcept;
|
||||||
uint32* ensureSize (size_t);
|
uint32* ensureSize (size_t);
|
||||||
|
|
|
||||||
|
|
@ -626,10 +626,10 @@ struct Expression::Helpers
|
||||||
class SymbolCheckVisitor : public Term::SymbolVisitor
|
class SymbolCheckVisitor : public Term::SymbolVisitor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SymbolCheckVisitor (const Symbol& symbol_) : wasFound (false), symbol (symbol_) {}
|
SymbolCheckVisitor (const Symbol& s) : symbol (s) {}
|
||||||
void useSymbol (const Symbol& s) { wasFound = wasFound || s == symbol; }
|
void useSymbol (const Symbol& s) { wasFound = wasFound || s == symbol; }
|
||||||
|
|
||||||
bool wasFound;
|
bool wasFound = false;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const Symbol& symbol;
|
const Symbol& symbol;
|
||||||
|
|
@ -725,7 +725,7 @@ struct Expression::Helpers
|
||||||
bool readIdentifier (String& identifier) noexcept
|
bool readIdentifier (String& identifier) noexcept
|
||||||
{
|
{
|
||||||
text = text.findEndOfWhitespace();
|
text = text.findEndOfWhitespace();
|
||||||
String::CharPointerType t (text);
|
auto t = text;
|
||||||
int numChars = 0;
|
int numChars = 0;
|
||||||
|
|
||||||
if (t.isLetter() || *t == '_')
|
if (t.isLetter() || *t == '_')
|
||||||
|
|
@ -753,9 +753,9 @@ struct Expression::Helpers
|
||||||
Term* readNumber() noexcept
|
Term* readNumber() noexcept
|
||||||
{
|
{
|
||||||
text = text.findEndOfWhitespace();
|
text = text.findEndOfWhitespace();
|
||||||
String::CharPointerType t (text);
|
auto t = text;
|
||||||
|
bool isResolutionTarget = (*t == '@');
|
||||||
|
|
||||||
const bool isResolutionTarget = (*t == '@');
|
|
||||||
if (isResolutionTarget)
|
if (isResolutionTarget)
|
||||||
{
|
{
|
||||||
++t;
|
++t;
|
||||||
|
|
@ -968,7 +968,7 @@ Expression& Expression::operator= (Expression&& other) noexcept
|
||||||
|
|
||||||
Expression::Expression (const String& stringToParse, String& parseError)
|
Expression::Expression (const String& stringToParse, String& parseError)
|
||||||
{
|
{
|
||||||
String::CharPointerType text (stringToParse.getCharPointer());
|
auto text = stringToParse.getCharPointer();
|
||||||
Helpers::Parser parser (text);
|
Helpers::Parser parser (text);
|
||||||
term = parser.readUpToComma();
|
term = parser.readUpToComma();
|
||||||
parseError = parser.error;
|
parseError = parser.error;
|
||||||
|
|
|
||||||
|
|
@ -26,24 +26,24 @@ namespace juce
|
||||||
bool Base64::convertToBase64 (OutputStream& base64Result, const void* sourceData, size_t sourceDataSize)
|
bool Base64::convertToBase64 (OutputStream& base64Result, const void* sourceData, size_t sourceDataSize)
|
||||||
{
|
{
|
||||||
static const char lookup[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
static const char lookup[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||||
const uint8* source = static_cast<const uint8*> (sourceData);
|
auto* source = static_cast<const uint8*> (sourceData);
|
||||||
|
|
||||||
while (sourceDataSize > 0)
|
while (sourceDataSize > 0)
|
||||||
{
|
{
|
||||||
char frame[4];
|
char frame[4];
|
||||||
const uint8 byte0 = *source++;
|
auto byte0 = *source++;
|
||||||
frame[0] = lookup [(byte0 & 0xfcu) >> 2];
|
frame[0] = lookup [(byte0 & 0xfcu) >> 2];
|
||||||
uint32 bits = (byte0 & 0x03u) << 4;
|
uint32 bits = (byte0 & 0x03u) << 4;
|
||||||
|
|
||||||
if (sourceDataSize > 1)
|
if (sourceDataSize > 1)
|
||||||
{
|
{
|
||||||
const uint8 byte1 = *source++;
|
auto byte1 = *source++;
|
||||||
frame[1] = lookup[bits | ((byte1 & 0xf0u) >> 4)];
|
frame[1] = lookup[bits | ((byte1 & 0xf0u) >> 4)];
|
||||||
bits = (byte1 & 0x0fu) << 2;
|
bits = (byte1 & 0x0fu) << 2;
|
||||||
|
|
||||||
if (sourceDataSize > 2)
|
if (sourceDataSize > 2)
|
||||||
{
|
{
|
||||||
const uint8 byte2 = *source++;
|
auto byte2 = *source++;
|
||||||
frame[2] = lookup[bits | ((byte2 & 0xc0u) >> 6)];
|
frame[2] = lookup[bits | ((byte2 & 0xc0u) >> 6)];
|
||||||
frame[3] = lookup[byte2 & 0x3fu];
|
frame[3] = lookup[byte2 & 0x3fu];
|
||||||
sourceDataSize -= 3;
|
sourceDataSize -= 3;
|
||||||
|
|
@ -72,13 +72,13 @@ bool Base64::convertToBase64 (OutputStream& base64Result, const void* sourceData
|
||||||
|
|
||||||
bool Base64::convertFromBase64 (OutputStream& binaryOutput, StringRef base64TextInput)
|
bool Base64::convertFromBase64 (OutputStream& binaryOutput, StringRef base64TextInput)
|
||||||
{
|
{
|
||||||
for (String::CharPointerType s = base64TextInput.text; ! s.isEmpty();)
|
for (auto s = base64TextInput.text; ! s.isEmpty();)
|
||||||
{
|
{
|
||||||
uint8 data[4];
|
uint8 data[4];
|
||||||
|
|
||||||
for (int i = 0; i < 4; ++i)
|
for (int i = 0; i < 4; ++i)
|
||||||
{
|
{
|
||||||
uint32 c = (uint32) s.getAndAdvance();
|
auto c = (uint32) s.getAndAdvance();
|
||||||
|
|
||||||
if (c >= 'A' && c <= 'Z') c -= 'A';
|
if (c >= 'A' && c <= 'Z') c -= 'A';
|
||||||
else if (c >= 'a' && c <= 'z') c -= 'a' - 26;
|
else if (c >= 'a' && c <= 'z') c -= 'a' - 26;
|
||||||
|
|
@ -143,15 +143,15 @@ public:
|
||||||
{
|
{
|
||||||
beginTest ("Base64");
|
beginTest ("Base64");
|
||||||
|
|
||||||
Random r = getRandom();
|
auto r = getRandom();
|
||||||
|
|
||||||
for (int i = 1000; --i >= 0;)
|
for (int i = 1000; --i >= 0;)
|
||||||
{
|
{
|
||||||
const MemoryBlock original (createRandomData (r));
|
auto original = createRandomData (r);
|
||||||
String asBase64 (Base64::toBase64 (original.getData(), original.getSize()));
|
auto asBase64 = Base64::toBase64 (original.getData(), original.getSize());
|
||||||
MemoryOutputStream out;
|
MemoryOutputStream out;
|
||||||
expect (Base64::convertFromBase64 (out, asBase64));
|
expect (Base64::convertFromBase64 (out, asBase64));
|
||||||
MemoryBlock result = out.getMemoryBlock();
|
auto result = out.getMemoryBlock();
|
||||||
expect (result == original);
|
expect (result == original);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -450,7 +450,7 @@ public:
|
||||||
template <typename DestCharPointerType, typename SrcCharPointerType>
|
template <typename DestCharPointerType, typename SrcCharPointerType>
|
||||||
static void copyAll (DestCharPointerType& dest, SrcCharPointerType src) noexcept
|
static void copyAll (DestCharPointerType& dest, SrcCharPointerType src) noexcept
|
||||||
{
|
{
|
||||||
while (juce_wchar c = src.getAndAdvance())
|
while (auto c = src.getAndAdvance())
|
||||||
dest.write (c);
|
dest.write (c);
|
||||||
|
|
||||||
dest.writeNull();
|
dest.writeNull();
|
||||||
|
|
|
||||||
|
|
@ -94,11 +94,11 @@ namespace
|
||||||
static int findCloseQuote (const String& text, int startPos)
|
static int findCloseQuote (const String& text, int startPos)
|
||||||
{
|
{
|
||||||
juce_wchar lastChar = 0;
|
juce_wchar lastChar = 0;
|
||||||
String::CharPointerType t (text.getCharPointer() + startPos);
|
auto t = text.getCharPointer() + startPos;
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
const juce_wchar c = t.getAndAdvance();
|
auto c = t.getAndAdvance();
|
||||||
|
|
||||||
if (c == 0 || (c == '"' && lastChar != '\\'))
|
if (c == 0 || (c == '"' && lastChar != '\\'))
|
||||||
break;
|
break;
|
||||||
|
|
@ -127,22 +127,20 @@ void LocalisedStrings::loadFromText (const String& fileContents, bool ignoreCase
|
||||||
StringArray lines;
|
StringArray lines;
|
||||||
lines.addLines (fileContents);
|
lines.addLines (fileContents);
|
||||||
|
|
||||||
for (int i = 0; i < lines.size(); ++i)
|
for (auto& l : lines)
|
||||||
{
|
{
|
||||||
String line (lines[i].trim());
|
auto line = l.trim();
|
||||||
|
|
||||||
if (line.startsWithChar ('"'))
|
if (line.startsWithChar ('"'))
|
||||||
{
|
{
|
||||||
int closeQuote = findCloseQuote (line, 1);
|
auto closeQuote = findCloseQuote (line, 1);
|
||||||
|
auto originalText = unescapeString (line.substring (1, closeQuote));
|
||||||
const String originalText (unescapeString (line.substring (1, closeQuote)));
|
|
||||||
|
|
||||||
if (originalText.isNotEmpty())
|
if (originalText.isNotEmpty())
|
||||||
{
|
{
|
||||||
const int openingQuote = findCloseQuote (line, closeQuote + 1);
|
auto openingQuote = findCloseQuote (line, closeQuote + 1);
|
||||||
closeQuote = findCloseQuote (line, openingQuote + 1);
|
closeQuote = findCloseQuote (line, openingQuote + 1);
|
||||||
|
auto newText = unescapeString (line.substring (openingQuote + 1, closeQuote));
|
||||||
const String newText (unescapeString (line.substring (openingQuote + 1, closeQuote)));
|
|
||||||
|
|
||||||
if (newText.isNotEmpty())
|
if (newText.isNotEmpty())
|
||||||
translations.set (originalText, newText);
|
translations.set (originalText, newText);
|
||||||
|
|
@ -199,7 +197,7 @@ JUCE_API String translate (const String& text, const String& resultIfNotFound)
|
||||||
{
|
{
|
||||||
const SpinLock::ScopedLockType sl (currentMappingsLock);
|
const SpinLock::ScopedLockType sl (currentMappingsLock);
|
||||||
|
|
||||||
if (const LocalisedStrings* const mappings = LocalisedStrings::getCurrentMappings())
|
if (auto* mappings = LocalisedStrings::getCurrentMappings())
|
||||||
return mappings->translate (text, resultIfNotFound);
|
return mappings->translate (text, resultIfNotFound);
|
||||||
|
|
||||||
return resultIfNotFound;
|
return resultIfNotFound;
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ struct TextDiffHelpers
|
||||||
StringRegion (const String& s) noexcept
|
StringRegion (const String& s) noexcept
|
||||||
: text (s.getCharPointer()), start (0), length (s.length()) {}
|
: text (s.getCharPointer()), start (0), length (s.length()) {}
|
||||||
|
|
||||||
StringRegion (const String::CharPointerType t, int s, int len) noexcept
|
StringRegion (String::CharPointerType t, int s, int len) noexcept
|
||||||
: text (t), start (s), length (len) {}
|
: text (t), start (s), length (len) {}
|
||||||
|
|
||||||
void incrementStart() noexcept { ++text; ++start; --length; }
|
void incrementStart() noexcept { ++text; ++start; --length; }
|
||||||
|
|
@ -42,7 +42,7 @@ struct TextDiffHelpers
|
||||||
int start, length;
|
int start, length;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void addInsertion (TextDiff& td, const String::CharPointerType text, int index, int length)
|
static void addInsertion (TextDiff& td, String::CharPointerType text, int index, int length)
|
||||||
{
|
{
|
||||||
TextDiff::Change c;
|
TextDiff::Change c;
|
||||||
c.insertedText = String (text, (size_t) length);
|
c.insertedText = String (text, (size_t) length);
|
||||||
|
|
@ -63,8 +63,8 @@ struct TextDiffHelpers
|
||||||
{
|
{
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
const juce_wchar ca = *a.text;
|
auto ca = *a.text;
|
||||||
const juce_wchar cb = *b.text;
|
auto cb = *b.text;
|
||||||
|
|
||||||
if (ca != cb || ca == 0)
|
if (ca != cb || ca == 0)
|
||||||
break;
|
break;
|
||||||
|
|
@ -79,8 +79,8 @@ struct TextDiffHelpers
|
||||||
static void diffRecursively (TextDiff& td, StringRegion a, StringRegion b)
|
static void diffRecursively (TextDiff& td, StringRegion a, StringRegion b)
|
||||||
{
|
{
|
||||||
int indexA = 0, indexB = 0;
|
int indexA = 0, indexB = 0;
|
||||||
const int len = findLongestCommonSubstring (a.text, a.length, indexA,
|
auto len = findLongestCommonSubstring (a.text, a.length, indexA,
|
||||||
b.text, b.length, indexB);
|
b.text, b.length, indexB);
|
||||||
|
|
||||||
if (len >= minLengthToMatch)
|
if (len >= minLengthToMatch)
|
||||||
{
|
{
|
||||||
|
|
@ -112,11 +112,11 @@ struct TextDiffHelpers
|
||||||
return findCommonSuffix (a, lenA, indexInA,
|
return findCommonSuffix (a, lenA, indexInA,
|
||||||
b, lenB, indexInB);
|
b, lenB, indexInB);
|
||||||
|
|
||||||
const size_t scratchSpace = sizeof (int) * (2 + 2 * (size_t) lenB);
|
auto scratchSpace = sizeof (int) * (2 + 2 * (size_t) lenB);
|
||||||
|
|
||||||
if (scratchSpace < 4096)
|
if (scratchSpace < 4096)
|
||||||
{
|
{
|
||||||
int* scratch = (int*) alloca (scratchSpace);
|
auto* scratch = (int*) alloca (scratchSpace);
|
||||||
return findLongestCommonSubstring (a, lenA, indexInA, b, lenB, indexInB, scratchSpace, scratch);
|
return findLongestCommonSubstring (a, lenA, indexInA, b, lenB, indexInB, scratchSpace, scratch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -130,16 +130,16 @@ struct TextDiffHelpers
|
||||||
{
|
{
|
||||||
zeromem (lines, scratchSpace);
|
zeromem (lines, scratchSpace);
|
||||||
|
|
||||||
int* l0 = lines;
|
auto* l0 = lines;
|
||||||
int* l1 = l0 + lenB + 1;
|
auto* l1 = l0 + lenB + 1;
|
||||||
|
|
||||||
int loopsWithoutImprovement = 0;
|
int loopsWithoutImprovement = 0;
|
||||||
int bestLength = 0;
|
int bestLength = 0;
|
||||||
|
|
||||||
for (int i = 0; i < lenA; ++i)
|
for (int i = 0; i < lenA; ++i)
|
||||||
{
|
{
|
||||||
const juce_wchar ca = a.getAndAdvance();
|
auto ca = a.getAndAdvance();
|
||||||
String::CharPointerType b2 (b);
|
auto b2 = b;
|
||||||
|
|
||||||
for (int j = 0; j < lenB; ++j)
|
for (int j = 0; j < lenB; ++j)
|
||||||
{
|
{
|
||||||
|
|
@ -149,7 +149,7 @@ struct TextDiffHelpers
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const int len = l0[j] + 1;
|
auto len = l0[j] + 1;
|
||||||
l1[j + 1] = len;
|
l1[j + 1] = len;
|
||||||
|
|
||||||
if (len > bestLength)
|
if (len > bestLength)
|
||||||
|
|
@ -173,8 +173,8 @@ struct TextDiffHelpers
|
||||||
return bestLength;
|
return bestLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int findCommonSuffix (String::CharPointerType a, const int lenA, int& indexInA,
|
static int findCommonSuffix (String::CharPointerType a, int lenA, int& indexInA,
|
||||||
String::CharPointerType b, const int lenB, int& indexInB) noexcept
|
String::CharPointerType b, int lenB, int& indexInB) noexcept
|
||||||
{
|
{
|
||||||
int length = 0;
|
int length = 0;
|
||||||
a += lenA - 1;
|
a += lenA - 1;
|
||||||
|
|
@ -200,8 +200,8 @@ TextDiff::TextDiff (const String& original, const String& target)
|
||||||
|
|
||||||
String TextDiff::appliedTo (String text) const
|
String TextDiff::appliedTo (String text) const
|
||||||
{
|
{
|
||||||
for (int i = 0; i < changes.size(); ++i)
|
for (auto& c : changes)
|
||||||
text = changes.getReference(i).appliedTo (text);
|
text = c.appliedTo (text);
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
@ -249,7 +249,7 @@ public:
|
||||||
void testDiff (const String& a, const String& b)
|
void testDiff (const String& a, const String& b)
|
||||||
{
|
{
|
||||||
TextDiff diff (a, b);
|
TextDiff diff (a, b);
|
||||||
const String result (diff.appliedTo (a));
|
auto result = diff.appliedTo (a);
|
||||||
expectEquals (result, b);
|
expectEquals (result, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -257,7 +257,7 @@ public:
|
||||||
{
|
{
|
||||||
beginTest ("TextDiff");
|
beginTest ("TextDiff");
|
||||||
|
|
||||||
Random r = getRandom();
|
auto r = getRandom();
|
||||||
|
|
||||||
testDiff (String(), String());
|
testDiff (String(), String());
|
||||||
testDiff ("x", String());
|
testDiff ("x", String());
|
||||||
|
|
@ -269,7 +269,7 @@ public:
|
||||||
|
|
||||||
for (int i = 1000; --i >= 0;)
|
for (int i = 1000; --i >= 0;)
|
||||||
{
|
{
|
||||||
String s (createString (r));
|
auto s = createString (r);
|
||||||
testDiff (s, createString (r));
|
testDiff (s, createString (r));
|
||||||
testDiff (s + createString (r), s + createString (r));
|
testDiff (s + createString (r), s + createString (r));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ namespace TimeHelpers
|
||||||
static std::tm millisToLocal (int64 millis) noexcept
|
static std::tm millisToLocal (int64 millis) noexcept
|
||||||
{
|
{
|
||||||
#if JUCE_WINDOWS && JUCE_MINGW
|
#if JUCE_WINDOWS && JUCE_MINGW
|
||||||
time_t now = (time_t) (millis / 1000);
|
auto now = (time_t) (millis / 1000);
|
||||||
return *localtime (&now);
|
return *localtime (&now);
|
||||||
|
|
||||||
#elif JUCE_WINDOWS
|
#elif JUCE_WINDOWS
|
||||||
|
|
@ -42,7 +42,7 @@ namespace TimeHelpers
|
||||||
|
|
||||||
#else
|
#else
|
||||||
std::tm result;
|
std::tm result;
|
||||||
time_t now = (time_t) (millis / 1000);
|
auto now = (time_t) (millis / 1000);
|
||||||
|
|
||||||
if (localtime_r (&now, &result) == nullptr)
|
if (localtime_r (&now, &result) == nullptr)
|
||||||
zerostruct (result);
|
zerostruct (result);
|
||||||
|
|
@ -54,7 +54,7 @@ namespace TimeHelpers
|
||||||
static std::tm millisToUTC (int64 millis) noexcept
|
static std::tm millisToUTC (int64 millis) noexcept
|
||||||
{
|
{
|
||||||
#if JUCE_WINDOWS && JUCE_MINGW
|
#if JUCE_WINDOWS && JUCE_MINGW
|
||||||
time_t now = (time_t) (millis / 1000);
|
auto now = (time_t) (millis / 1000);
|
||||||
return *gmtime (&now);
|
return *gmtime (&now);
|
||||||
|
|
||||||
#elif JUCE_WINDOWS
|
#elif JUCE_WINDOWS
|
||||||
|
|
@ -68,7 +68,7 @@ namespace TimeHelpers
|
||||||
|
|
||||||
#else
|
#else
|
||||||
std::tm result;
|
std::tm result;
|
||||||
time_t now = (time_t) (millis / 1000);
|
auto now = (time_t) (millis / 1000);
|
||||||
|
|
||||||
if (gmtime_r (&now, &result) == nullptr)
|
if (gmtime_r (&now, &result) == nullptr)
|
||||||
zerostruct (result);
|
zerostruct (result);
|
||||||
|
|
@ -79,7 +79,7 @@ namespace TimeHelpers
|
||||||
|
|
||||||
static int getUTCOffsetSeconds (const int64 millis) noexcept
|
static int getUTCOffsetSeconds (const int64 millis) noexcept
|
||||||
{
|
{
|
||||||
std::tm utc = millisToUTC (millis);
|
auto utc = millisToUTC (millis);
|
||||||
utc.tm_isdst = -1; // Treat this UTC time as local to find the offset
|
utc.tm_isdst = -1; // Treat this UTC time as local to find the offset
|
||||||
|
|
||||||
return (int) ((millis / 1000) - (int64) mktime (&utc));
|
return (int) ((millis / 1000) - (int64) mktime (&utc));
|
||||||
|
|
@ -110,14 +110,14 @@ namespace TimeHelpers
|
||||||
{
|
{
|
||||||
HeapBlock<StringType::CharType> buffer (bufferSize);
|
HeapBlock<StringType::CharType> buffer (bufferSize);
|
||||||
|
|
||||||
const size_t numChars =
|
auto numChars =
|
||||||
#if JUCE_ANDROID
|
#if JUCE_ANDROID
|
||||||
strftime (buffer, bufferSize - 1, format.toUTF8(), tm);
|
strftime (buffer, bufferSize - 1, format.toUTF8(), tm);
|
||||||
#elif JUCE_WINDOWS
|
#elif JUCE_WINDOWS
|
||||||
wcsftime (buffer, bufferSize - 1, format.toWideCharPointer(), tm);
|
wcsftime (buffer, bufferSize - 1, format.toWideCharPointer(), tm);
|
||||||
#else
|
#else
|
||||||
wcsftime (buffer, bufferSize - 1, format.toUTF32(), tm);
|
wcsftime (buffer, bufferSize - 1, format.toUTF32(), tm);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (numChars > 0 || format.isEmpty())
|
if (numChars > 0 || format.isEmpty())
|
||||||
return String (StringType (buffer),
|
return String (StringType (buffer),
|
||||||
|
|
@ -189,18 +189,13 @@ Time::Time (const Time& other) noexcept : millisSinceEpoch (other.millisSinceEp
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Time::Time (const int64 ms) noexcept : millisSinceEpoch (ms)
|
Time::Time (int64 ms) noexcept : millisSinceEpoch (ms)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Time::Time (const int year,
|
Time::Time (int year, int month, int day,
|
||||||
const int month,
|
int hours, int minutes, int seconds, int milliseconds,
|
||||||
const int day,
|
bool useLocalTime) noexcept
|
||||||
const int hours,
|
|
||||||
const int minutes,
|
|
||||||
const int seconds,
|
|
||||||
const int milliseconds,
|
|
||||||
const bool useLocalTime) noexcept
|
|
||||||
{
|
{
|
||||||
std::tm t;
|
std::tm t;
|
||||||
t.tm_year = year - 1900;
|
t.tm_year = year - 1900;
|
||||||
|
|
@ -250,7 +245,7 @@ uint32 juce_millisecondsSinceStartup() noexcept;
|
||||||
|
|
||||||
uint32 Time::getMillisecondCounter() noexcept
|
uint32 Time::getMillisecondCounter() noexcept
|
||||||
{
|
{
|
||||||
const uint32 now = juce_millisecondsSinceStartup();
|
auto now = juce_millisecondsSinceStartup();
|
||||||
|
|
||||||
if (now < TimeHelpers::lastMSCounterValue)
|
if (now < TimeHelpers::lastMSCounterValue)
|
||||||
{
|
{
|
||||||
|
|
@ -276,16 +271,16 @@ uint32 Time::getApproximateMillisecondCounter() noexcept
|
||||||
return TimeHelpers::lastMSCounterValue;
|
return TimeHelpers::lastMSCounterValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Time::waitForMillisecondCounter (const uint32 targetTime) noexcept
|
void Time::waitForMillisecondCounter (uint32 targetTime) noexcept
|
||||||
{
|
{
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
const uint32 now = getMillisecondCounter();
|
auto now = getMillisecondCounter();
|
||||||
|
|
||||||
if (now >= targetTime)
|
if (now >= targetTime)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
const int toWait = (int) (targetTime - now);
|
auto toWait = (int) (targetTime - now);
|
||||||
|
|
||||||
if (toWait > 2)
|
if (toWait > 2)
|
||||||
{
|
{
|
||||||
|
|
@ -332,14 +327,14 @@ String Time::toString (const bool includeDate,
|
||||||
|
|
||||||
if (includeTime)
|
if (includeTime)
|
||||||
{
|
{
|
||||||
const int mins = getMinutes();
|
auto mins = getMinutes();
|
||||||
|
|
||||||
result << (use24HourClock ? getHours() : getHoursInAmPmFormat())
|
result << (use24HourClock ? getHours() : getHoursInAmPmFormat())
|
||||||
<< (mins < 10 ? ":0" : ":") << mins;
|
<< (mins < 10 ? ":0" : ":") << mins;
|
||||||
|
|
||||||
if (includeSeconds)
|
if (includeSeconds)
|
||||||
{
|
{
|
||||||
const int secs = getSeconds();
|
auto secs = getSeconds();
|
||||||
result << (secs < 10 ? ":0" : ":") << secs;
|
result << (secs < 10 ? ":0" : ":") << secs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -369,7 +364,7 @@ int Time::getMilliseconds() const noexcept { return TimeHelpers::extendedModulo
|
||||||
|
|
||||||
int Time::getHoursInAmPmFormat() const noexcept
|
int Time::getHoursInAmPmFormat() const noexcept
|
||||||
{
|
{
|
||||||
const int hours = getHours();
|
auto hours = getHours();
|
||||||
|
|
||||||
if (hours == 0) return 12;
|
if (hours == 0) return 12;
|
||||||
if (hours <= 12) return hours;
|
if (hours <= 12) return hours;
|
||||||
|
|
@ -408,7 +403,7 @@ String Time::getTimeZone() const noexcept
|
||||||
#else
|
#else
|
||||||
tzset();
|
tzset();
|
||||||
|
|
||||||
const char** const zonePtr = (const char**) tzname;
|
auto zonePtr = (const char**) tzname;
|
||||||
zone[0] = zonePtr[0];
|
zone[0] = zonePtr[0];
|
||||||
zone[1] = zonePtr[1];
|
zone[1] = zonePtr[1];
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -482,17 +477,19 @@ static int parseFixedSizeIntAndSkip (String::CharPointerType& t, int numChars, c
|
||||||
|
|
||||||
Time Time::fromISO8601 (StringRef iso) noexcept
|
Time Time::fromISO8601 (StringRef iso) noexcept
|
||||||
{
|
{
|
||||||
String::CharPointerType t = iso.text;
|
auto t = iso.text;
|
||||||
|
auto year = parseFixedSizeIntAndSkip (t, 4, '-');
|
||||||
|
|
||||||
const int year = parseFixedSizeIntAndSkip (t, 4, '-');
|
|
||||||
if (year < 0)
|
if (year < 0)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
const int month = parseFixedSizeIntAndSkip (t, 2, '-');
|
auto month = parseFixedSizeIntAndSkip (t, 2, '-');
|
||||||
|
|
||||||
if (month < 0)
|
if (month < 0)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
const int day = parseFixedSizeIntAndSkip (t, 2, 0);
|
auto day = parseFixedSizeIntAndSkip (t, 2, 0);
|
||||||
|
|
||||||
if (day < 0)
|
if (day < 0)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
|
@ -502,14 +499,17 @@ Time Time::fromISO8601 (StringRef iso) noexcept
|
||||||
{
|
{
|
||||||
++t;
|
++t;
|
||||||
hours = parseFixedSizeIntAndSkip (t, 2, ':');
|
hours = parseFixedSizeIntAndSkip (t, 2, ':');
|
||||||
|
|
||||||
if (hours < 0)
|
if (hours < 0)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
minutes = parseFixedSizeIntAndSkip (t, 2, ':');
|
minutes = parseFixedSizeIntAndSkip (t, 2, ':');
|
||||||
|
|
||||||
if (minutes < 0)
|
if (minutes < 0)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
auto seconds = parseFixedSizeIntAndSkip (t, 2, 0);
|
auto seconds = parseFixedSizeIntAndSkip (t, 2, 0);
|
||||||
|
|
||||||
if (seconds < 0)
|
if (seconds < 0)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
|
@ -517,6 +517,7 @@ Time Time::fromISO8601 (StringRef iso) noexcept
|
||||||
{
|
{
|
||||||
++t;
|
++t;
|
||||||
milliseconds = parseFixedSizeIntAndSkip (t, 3, 0);
|
milliseconds = parseFixedSizeIntAndSkip (t, 3, 0);
|
||||||
|
|
||||||
if (milliseconds < 0)
|
if (milliseconds < 0)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
@ -524,19 +525,21 @@ Time Time::fromISO8601 (StringRef iso) noexcept
|
||||||
milliseconds += 1000 * seconds;
|
milliseconds += 1000 * seconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
const juce_wchar nextChar = t.getAndAdvance();
|
auto nextChar = t.getAndAdvance();
|
||||||
|
|
||||||
if (nextChar == '-' || nextChar == '+')
|
if (nextChar == '-' || nextChar == '+')
|
||||||
{
|
{
|
||||||
const int offsetHours = parseFixedSizeIntAndSkip (t, 2, ':');
|
auto offsetHours = parseFixedSizeIntAndSkip (t, 2, ':');
|
||||||
|
|
||||||
if (offsetHours < 0)
|
if (offsetHours < 0)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
const int offsetMinutes = parseFixedSizeIntAndSkip (t, 2, 0);
|
auto offsetMinutes = parseFixedSizeIntAndSkip (t, 2, 0);
|
||||||
|
|
||||||
if (offsetMinutes < 0)
|
if (offsetMinutes < 0)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
const int offsetMs = (offsetHours * 60 + offsetMinutes) * 60 * 1000;
|
auto offsetMs = (offsetHours * 60 + offsetMinutes) * 60 * 1000;
|
||||||
milliseconds += nextChar == '-' ? offsetMs : -offsetMs; // NB: this seems backwards but is correct!
|
milliseconds += nextChar == '-' ? offsetMs : -offsetMs; // NB: this seems backwards but is correct!
|
||||||
}
|
}
|
||||||
else if (nextChar != 0 && nextChar != 'Z')
|
else if (nextChar != 0 && nextChar != 'Z')
|
||||||
|
|
|
||||||
|
|
@ -212,11 +212,11 @@ namespace XmlOutputFunctions
|
||||||
|
|
||||||
static void escapeIllegalXmlChars (OutputStream& outputStream, const String& text, const bool changeNewLines)
|
static void escapeIllegalXmlChars (OutputStream& outputStream, const String& text, const bool changeNewLines)
|
||||||
{
|
{
|
||||||
String::CharPointerType t (text.getCharPointer());
|
auto t = text.getCharPointer();
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
const uint32 character = (uint32) t.getAndAdvance();
|
auto character = (uint32) t.getAndAdvance();
|
||||||
|
|
||||||
if (character == 0)
|
if (character == 0)
|
||||||
break;
|
break;
|
||||||
|
|
@ -229,22 +229,22 @@ namespace XmlOutputFunctions
|
||||||
{
|
{
|
||||||
switch (character)
|
switch (character)
|
||||||
{
|
{
|
||||||
case '&': outputStream << "&"; break;
|
case '&': outputStream << "&"; break;
|
||||||
case '"': outputStream << """; break;
|
case '"': outputStream << """; break;
|
||||||
case '>': outputStream << ">"; break;
|
case '>': outputStream << ">"; break;
|
||||||
case '<': outputStream << "<"; break;
|
case '<': outputStream << "<"; break;
|
||||||
|
|
||||||
case '\n':
|
case '\n':
|
||||||
case '\r':
|
case '\r':
|
||||||
if (! changeNewLines)
|
if (! changeNewLines)
|
||||||
{
|
{
|
||||||
outputStream << (char) character;
|
outputStream << (char) character;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Note: deliberate fall-through here!
|
||||||
|
default:
|
||||||
|
outputStream << "&#" << ((int) character) << ';';
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
// Note: deliberate fall-through here!
|
|
||||||
default:
|
|
||||||
outputStream << "&#" << ((int) character) << ';';
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -271,10 +271,10 @@ void XmlElement::writeElementAsText (OutputStream& outputStream,
|
||||||
outputStream << tagName;
|
outputStream << tagName;
|
||||||
|
|
||||||
{
|
{
|
||||||
const size_t attIndent = (size_t) (indentationLevel + tagName.length() + 1);
|
auto attIndent = (size_t) (indentationLevel + tagName.length() + 1);
|
||||||
int lineLen = 0;
|
int lineLen = 0;
|
||||||
|
|
||||||
for (const XmlAttributeNode* att = attributes; att != nullptr; att = att->nextListItem)
|
for (auto* att = attributes.get(); att != nullptr; att = att->nextListItem)
|
||||||
{
|
{
|
||||||
if (lineLen > lineWrapLength && indentationLevel >= 0)
|
if (lineLen > lineWrapLength && indentationLevel >= 0)
|
||||||
{
|
{
|
||||||
|
|
@ -283,7 +283,7 @@ void XmlElement::writeElementAsText (OutputStream& outputStream,
|
||||||
lineLen = 0;
|
lineLen = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int64 startPos = outputStream.getPosition();
|
auto startPos = outputStream.getPosition();
|
||||||
outputStream.writeByte (' ');
|
outputStream.writeByte (' ');
|
||||||
outputStream << att->name;
|
outputStream << att->name;
|
||||||
outputStream.write ("=\"", 2);
|
outputStream.write ("=\"", 2);
|
||||||
|
|
@ -293,13 +293,12 @@ void XmlElement::writeElementAsText (OutputStream& outputStream,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firstChildElement != nullptr)
|
if (auto* child = firstChildElement.get())
|
||||||
{
|
{
|
||||||
outputStream.writeByte ('>');
|
outputStream.writeByte ('>');
|
||||||
|
|
||||||
bool lastWasTextNode = false;
|
bool lastWasTextNode = false;
|
||||||
|
|
||||||
for (XmlElement* child = firstChildElement; child != nullptr; child = child->nextListItem)
|
for (; child != nullptr; child = child->nextListItem)
|
||||||
{
|
{
|
||||||
if (child->isTextElement())
|
if (child->isTextElement())
|
||||||
{
|
{
|
||||||
|
|
@ -350,12 +349,9 @@ String XmlElement::createDocument (StringRef dtdToUse,
|
||||||
return mem.toUTF8();
|
return mem.toUTF8();
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlElement::writeToStream (OutputStream& output,
|
void XmlElement::writeToStream (OutputStream& output, StringRef dtdToUse,
|
||||||
StringRef dtdToUse,
|
bool allOnOneLine, bool includeXmlHeader,
|
||||||
const bool allOnOneLine,
|
StringRef encodingType, int lineWrapLength) const
|
||||||
const bool includeXmlHeader,
|
|
||||||
StringRef encodingType,
|
|
||||||
const int lineWrapLength) const
|
|
||||||
{
|
{
|
||||||
using namespace XmlOutputFunctions;
|
using namespace XmlOutputFunctions;
|
||||||
|
|
||||||
|
|
@ -385,10 +381,8 @@ void XmlElement::writeToStream (OutputStream& output,
|
||||||
output << newLine;
|
output << newLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool XmlElement::writeToFile (const File& file,
|
bool XmlElement::writeToFile (const File& file, StringRef dtdToUse,
|
||||||
StringRef dtdToUse,
|
StringRef encodingType, int lineWrapLength) const
|
||||||
StringRef encodingType,
|
|
||||||
const int lineWrapLength) const
|
|
||||||
{
|
{
|
||||||
TemporaryFile tempFile (file);
|
TemporaryFile tempFile (file);
|
||||||
|
|
||||||
|
|
@ -399,7 +393,6 @@ bool XmlElement::writeToFile (const File& file,
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
writeToStream (out, dtdToUse, false, true, encodingType, lineWrapLength);
|
writeToStream (out, dtdToUse, false, true, encodingType, lineWrapLength);
|
||||||
|
|
||||||
out.flush(); // (called explicitly to force an fsync on posix)
|
out.flush(); // (called explicitly to force an fsync on posix)
|
||||||
|
|
||||||
if (out.getStatus().failed())
|
if (out.getStatus().failed())
|
||||||
|
|
@ -438,7 +431,7 @@ bool XmlElement::hasTagNameIgnoringNamespace (StringRef possibleTagName) const
|
||||||
|
|
||||||
XmlElement* XmlElement::getNextElementWithTagName (StringRef requiredTagName) const
|
XmlElement* XmlElement::getNextElementWithTagName (StringRef requiredTagName) const
|
||||||
{
|
{
|
||||||
XmlElement* e = nextListItem;
|
auto* e = nextListItem.get();
|
||||||
|
|
||||||
while (e != nullptr && ! e->hasTagName (requiredTagName))
|
while (e != nullptr && ! e->hasTagName (requiredTagName))
|
||||||
e = e->nextListItem;
|
e = e->nextListItem;
|
||||||
|
|
@ -464,7 +457,7 @@ static const String& getEmptyStringRef() noexcept
|
||||||
|
|
||||||
const String& XmlElement::getAttributeName (const int index) const noexcept
|
const String& XmlElement::getAttributeName (const int index) const noexcept
|
||||||
{
|
{
|
||||||
if (const XmlAttributeNode* const att = attributes [index])
|
if (auto* att = attributes[index].get())
|
||||||
return att->name.toString();
|
return att->name.toString();
|
||||||
|
|
||||||
return getEmptyStringRef();
|
return getEmptyStringRef();
|
||||||
|
|
@ -472,7 +465,7 @@ const String& XmlElement::getAttributeName (const int index) const noexcept
|
||||||
|
|
||||||
const String& XmlElement::getAttributeValue (const int index) const noexcept
|
const String& XmlElement::getAttributeValue (const int index) const noexcept
|
||||||
{
|
{
|
||||||
if (const XmlAttributeNode* const att = attributes [index])
|
if (auto* att = attributes[index].get())
|
||||||
return att->value;
|
return att->value;
|
||||||
|
|
||||||
return getEmptyStringRef();
|
return getEmptyStringRef();
|
||||||
|
|
@ -480,7 +473,7 @@ const String& XmlElement::getAttributeValue (const int index) const noexcept
|
||||||
|
|
||||||
XmlElement::XmlAttributeNode* XmlElement::getAttribute (StringRef attributeName) const noexcept
|
XmlElement::XmlAttributeNode* XmlElement::getAttribute (StringRef attributeName) const noexcept
|
||||||
{
|
{
|
||||||
for (XmlAttributeNode* att = attributes; att != nullptr; att = att->nextListItem)
|
for (auto* att = attributes.get(); att != nullptr; att = att->nextListItem)
|
||||||
if (att->name == attributeName)
|
if (att->name == attributeName)
|
||||||
return att;
|
return att;
|
||||||
|
|
||||||
|
|
@ -495,7 +488,7 @@ bool XmlElement::hasAttribute (StringRef attributeName) const noexcept
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
const String& XmlElement::getStringAttribute (StringRef attributeName) const noexcept
|
const String& XmlElement::getStringAttribute (StringRef attributeName) const noexcept
|
||||||
{
|
{
|
||||||
if (const XmlAttributeNode* att = getAttribute (attributeName))
|
if (auto* att = getAttribute (attributeName))
|
||||||
return att->value;
|
return att->value;
|
||||||
|
|
||||||
return getEmptyStringRef();
|
return getEmptyStringRef();
|
||||||
|
|
@ -503,7 +496,7 @@ const String& XmlElement::getStringAttribute (StringRef attributeName) const noe
|
||||||
|
|
||||||
String XmlElement::getStringAttribute (StringRef attributeName, const String& defaultReturnValue) const
|
String XmlElement::getStringAttribute (StringRef attributeName, const String& defaultReturnValue) const
|
||||||
{
|
{
|
||||||
if (const XmlAttributeNode* att = getAttribute (attributeName))
|
if (auto* att = getAttribute (attributeName))
|
||||||
return att->value;
|
return att->value;
|
||||||
|
|
||||||
return defaultReturnValue;
|
return defaultReturnValue;
|
||||||
|
|
@ -511,7 +504,7 @@ String XmlElement::getStringAttribute (StringRef attributeName, const String& de
|
||||||
|
|
||||||
int XmlElement::getIntAttribute (StringRef attributeName, const int defaultReturnValue) const
|
int XmlElement::getIntAttribute (StringRef attributeName, const int defaultReturnValue) const
|
||||||
{
|
{
|
||||||
if (const XmlAttributeNode* att = getAttribute (attributeName))
|
if (auto* att = getAttribute (attributeName))
|
||||||
return att->value.getIntValue();
|
return att->value.getIntValue();
|
||||||
|
|
||||||
return defaultReturnValue;
|
return defaultReturnValue;
|
||||||
|
|
@ -519,7 +512,7 @@ int XmlElement::getIntAttribute (StringRef attributeName, const int defaultRetur
|
||||||
|
|
||||||
double XmlElement::getDoubleAttribute (StringRef attributeName, const double defaultReturnValue) const
|
double XmlElement::getDoubleAttribute (StringRef attributeName, const double defaultReturnValue) const
|
||||||
{
|
{
|
||||||
if (const XmlAttributeNode* att = getAttribute (attributeName))
|
if (auto* att = getAttribute (attributeName))
|
||||||
return att->value.getDoubleValue();
|
return att->value.getDoubleValue();
|
||||||
|
|
||||||
return defaultReturnValue;
|
return defaultReturnValue;
|
||||||
|
|
@ -527,9 +520,9 @@ double XmlElement::getDoubleAttribute (StringRef attributeName, const double def
|
||||||
|
|
||||||
bool XmlElement::getBoolAttribute (StringRef attributeName, const bool defaultReturnValue) const
|
bool XmlElement::getBoolAttribute (StringRef attributeName, const bool defaultReturnValue) const
|
||||||
{
|
{
|
||||||
if (const XmlAttributeNode* att = getAttribute (attributeName))
|
if (auto* att = getAttribute (attributeName))
|
||||||
{
|
{
|
||||||
const juce_wchar firstChar = *(att->value.getCharPointer().findEndOfWhitespace());
|
auto firstChar = *(att->value.getCharPointer().findEndOfWhitespace());
|
||||||
|
|
||||||
return firstChar == '1'
|
return firstChar == '1'
|
||||||
|| firstChar == 't'
|
|| firstChar == 't'
|
||||||
|
|
@ -545,7 +538,7 @@ bool XmlElement::compareAttribute (StringRef attributeName,
|
||||||
StringRef stringToCompareAgainst,
|
StringRef stringToCompareAgainst,
|
||||||
const bool ignoreCase) const noexcept
|
const bool ignoreCase) const noexcept
|
||||||
{
|
{
|
||||||
if (const XmlAttributeNode* att = getAttribute (attributeName))
|
if (auto* att = getAttribute (attributeName))
|
||||||
return ignoreCase ? att->value.equalsIgnoreCase (stringToCompareAgainst)
|
return ignoreCase ? att->value.equalsIgnoreCase (stringToCompareAgainst)
|
||||||
: att->value == stringToCompareAgainst;
|
: att->value == stringToCompareAgainst;
|
||||||
|
|
||||||
|
|
@ -561,7 +554,7 @@ void XmlElement::setAttribute (const Identifier& attributeName, const String& va
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (XmlAttributeNode* att = attributes; ; att = att->nextListItem)
|
for (auto* att = attributes.get(); ; att = att->nextListItem)
|
||||||
{
|
{
|
||||||
if (att->name == attributeName)
|
if (att->name == attributeName)
|
||||||
{
|
{
|
||||||
|
|
@ -590,9 +583,7 @@ void XmlElement::setAttribute (const Identifier& attributeName, const double num
|
||||||
|
|
||||||
void XmlElement::removeAttribute (const Identifier& attributeName) noexcept
|
void XmlElement::removeAttribute (const Identifier& attributeName) noexcept
|
||||||
{
|
{
|
||||||
for (LinkedListPointer<XmlAttributeNode>* att = &attributes;
|
for (auto* att = &attributes; att->get() != nullptr; att = &(att->get()->nextListItem))
|
||||||
att->get() != nullptr;
|
|
||||||
att = &(att->get()->nextListItem))
|
|
||||||
{
|
{
|
||||||
if (att->get()->name == attributeName)
|
if (att->get()->name == attributeName)
|
||||||
{
|
{
|
||||||
|
|
@ -622,7 +613,7 @@ XmlElement* XmlElement::getChildByName (StringRef childName) const noexcept
|
||||||
{
|
{
|
||||||
jassert (! childName.isEmpty());
|
jassert (! childName.isEmpty());
|
||||||
|
|
||||||
for (XmlElement* child = firstChildElement; child != nullptr; child = child->nextListItem)
|
for (auto* child = firstChildElement.get(); child != nullptr; child = child->nextListItem)
|
||||||
if (child->hasTagName (childName))
|
if (child->hasTagName (childName))
|
||||||
return child;
|
return child;
|
||||||
|
|
||||||
|
|
@ -633,7 +624,7 @@ XmlElement* XmlElement::getChildByAttribute (StringRef attributeName, StringRef
|
||||||
{
|
{
|
||||||
jassert (! attributeName.isEmpty());
|
jassert (! attributeName.isEmpty());
|
||||||
|
|
||||||
for (XmlElement* child = firstChildElement; child != nullptr; child = child->nextListItem)
|
for (auto* child = firstChildElement.get(); child != nullptr; child = child->nextListItem)
|
||||||
if (child->compareAttribute (attributeName, attributeValue))
|
if (child->compareAttribute (attributeName, attributeValue))
|
||||||
return child;
|
return child;
|
||||||
|
|
||||||
|
|
@ -675,7 +666,7 @@ void XmlElement::prependChildElement (XmlElement* newNode) noexcept
|
||||||
|
|
||||||
XmlElement* XmlElement::createNewChildElement (StringRef childTagName)
|
XmlElement* XmlElement::createNewChildElement (StringRef childTagName)
|
||||||
{
|
{
|
||||||
XmlElement* const newElement = new XmlElement (childTagName);
|
auto newElement = new XmlElement (childTagName);
|
||||||
addChildElement (newElement);
|
addChildElement (newElement);
|
||||||
return newElement;
|
return newElement;
|
||||||
}
|
}
|
||||||
|
|
@ -685,7 +676,7 @@ bool XmlElement::replaceChildElement (XmlElement* const currentChildElement,
|
||||||
{
|
{
|
||||||
if (newNode != nullptr)
|
if (newNode != nullptr)
|
||||||
{
|
{
|
||||||
if (LinkedListPointer<XmlElement>* const p = firstChildElement.findPointerTo (currentChildElement))
|
if (auto* p = firstChildElement.findPointerTo (currentChildElement))
|
||||||
{
|
{
|
||||||
if (currentChildElement != newNode)
|
if (currentChildElement != newNode)
|
||||||
delete p->replaceNext (newNode);
|
delete p->replaceNext (newNode);
|
||||||
|
|
@ -721,7 +712,7 @@ bool XmlElement::isEquivalentTo (const XmlElement* const other,
|
||||||
{
|
{
|
||||||
int totalAtts = 0;
|
int totalAtts = 0;
|
||||||
|
|
||||||
for (const XmlAttributeNode* att = attributes; att != nullptr; att = att->nextListItem)
|
for (auto* att = attributes.get(); att != nullptr; att = att->nextListItem)
|
||||||
{
|
{
|
||||||
if (! other->compareAttribute (att->name, att->value))
|
if (! other->compareAttribute (att->name, att->value))
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -734,8 +725,8 @@ bool XmlElement::isEquivalentTo (const XmlElement* const other,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const XmlAttributeNode* thisAtt = attributes;
|
auto* thisAtt = attributes.get();
|
||||||
const XmlAttributeNode* otherAtt = other->attributes;
|
auto* otherAtt = other->attributes.get();
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
|
@ -758,8 +749,8 @@ bool XmlElement::isEquivalentTo (const XmlElement* const other,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const XmlElement* thisChild = firstChildElement;
|
auto* thisChild = firstChildElement.get();
|
||||||
const XmlElement* otherChild = other->firstChildElement;
|
auto* otherChild = other->firstChildElement.get();
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
|
@ -789,9 +780,9 @@ void XmlElement::deleteAllChildElements() noexcept
|
||||||
|
|
||||||
void XmlElement::deleteAllChildElementsWithTagName (StringRef name) noexcept
|
void XmlElement::deleteAllChildElementsWithTagName (StringRef name) noexcept
|
||||||
{
|
{
|
||||||
for (XmlElement* child = firstChildElement; child != nullptr;)
|
for (auto* child = firstChildElement.get(); child != nullptr;)
|
||||||
{
|
{
|
||||||
XmlElement* const nextChild = child->nextListItem;
|
auto* nextChild = child->nextListItem.get();
|
||||||
|
|
||||||
if (child->hasTagName (name))
|
if (child->hasTagName (name))
|
||||||
removeChildElement (child, true);
|
removeChildElement (child, true);
|
||||||
|
|
@ -810,12 +801,12 @@ XmlElement* XmlElement::findParentElementOf (const XmlElement* const elementToLo
|
||||||
if (this == elementToLookFor || elementToLookFor == nullptr)
|
if (this == elementToLookFor || elementToLookFor == nullptr)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
for (XmlElement* child = firstChildElement; child != nullptr; child = child->nextListItem)
|
for (auto* child = firstChildElement.get(); child != nullptr; child = child->nextListItem)
|
||||||
{
|
{
|
||||||
if (elementToLookFor == child)
|
if (elementToLookFor == child)
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
if (XmlElement* const found = child->findParentElementOf (elementToLookFor))
|
if (auto* found = child->findParentElementOf (elementToLookFor))
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -827,9 +818,10 @@ void XmlElement::getChildElementsAsArray (XmlElement** elems) const noexcept
|
||||||
firstChildElement.copyToArray (elems);
|
firstChildElement.copyToArray (elems);
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlElement::reorderChildElements (XmlElement** const elems, const int num) noexcept
|
void XmlElement::reorderChildElements (XmlElement** elems, int num) noexcept
|
||||||
{
|
{
|
||||||
XmlElement* e = firstChildElement = elems[0];
|
auto* e = elems[0];
|
||||||
|
firstChildElement = e;
|
||||||
|
|
||||||
for (int i = 1; i < num; ++i)
|
for (int i = 1; i < num; ++i)
|
||||||
{
|
{
|
||||||
|
|
@ -875,7 +867,7 @@ String XmlElement::getAllSubText() const
|
||||||
|
|
||||||
MemoryOutputStream mem (1024);
|
MemoryOutputStream mem (1024);
|
||||||
|
|
||||||
for (const XmlElement* child = firstChildElement; child != nullptr; child = child->nextListItem)
|
for (auto* child = firstChildElement.get(); child != nullptr; child = child->nextListItem)
|
||||||
mem << child->getAllSubText();
|
mem << child->getAllSubText();
|
||||||
|
|
||||||
return mem.toUTF8();
|
return mem.toUTF8();
|
||||||
|
|
@ -883,7 +875,7 @@ String XmlElement::getAllSubText() const
|
||||||
|
|
||||||
String XmlElement::getChildElementAllSubText (StringRef childTagName, const String& defaultReturnValue) const
|
String XmlElement::getChildElementAllSubText (StringRef childTagName, const String& defaultReturnValue) const
|
||||||
{
|
{
|
||||||
if (const XmlElement* const child = getChildByName (childTagName))
|
if (auto* child = getChildByName (childTagName))
|
||||||
return child->getAllSubText();
|
return child->getAllSubText();
|
||||||
|
|
||||||
return defaultReturnValue;
|
return defaultReturnValue;
|
||||||
|
|
@ -891,7 +883,7 @@ String XmlElement::getChildElementAllSubText (StringRef childTagName, const Stri
|
||||||
|
|
||||||
XmlElement* XmlElement::createTextElement (const String& text)
|
XmlElement* XmlElement::createTextElement (const String& text)
|
||||||
{
|
{
|
||||||
XmlElement* const e = new XmlElement ((int) 0);
|
auto e = new XmlElement ((int) 0);
|
||||||
e->setAttribute (juce_xmltextContentAttributeName, text);
|
e->setAttribute (juce_xmltextContentAttributeName, text);
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
@ -918,9 +910,9 @@ void XmlElement::addTextElement (const String& text)
|
||||||
|
|
||||||
void XmlElement::deleteAllTextElements() noexcept
|
void XmlElement::deleteAllTextElements() noexcept
|
||||||
{
|
{
|
||||||
for (XmlElement* child = firstChildElement; child != nullptr;)
|
for (auto* child = firstChildElement.get(); child != nullptr;)
|
||||||
{
|
{
|
||||||
XmlElement* const next = child->nextListItem;
|
auto* next = child->nextListItem.get();
|
||||||
|
|
||||||
if (child->isTextElement())
|
if (child->isTextElement())
|
||||||
removeChildElement (child, true);
|
removeChildElement (child, true);
|
||||||
|
|
|
||||||
|
|
@ -229,11 +229,11 @@ MD5::MD5 (CharPointer_UTF8 utf8) noexcept
|
||||||
MD5 MD5::fromUTF32 (StringRef text)
|
MD5 MD5::fromUTF32 (StringRef text)
|
||||||
{
|
{
|
||||||
MD5Generator generator;
|
MD5Generator generator;
|
||||||
String::CharPointerType t (text.text);
|
auto t = text.text;
|
||||||
|
|
||||||
while (! t.isEmpty())
|
while (! t.isEmpty())
|
||||||
{
|
{
|
||||||
uint32 unicodeChar = ByteOrder::swapIfBigEndian ((uint32) t.getAndAdvance());
|
auto unicodeChar = ByteOrder::swapIfBigEndian ((uint32) t.getAndAdvance());
|
||||||
generator.processBlock (&unicodeChar, sizeof (unicodeChar));
|
generator.processBlock (&unicodeChar, sizeof (unicodeChar));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -276,7 +276,7 @@ void MD5::processStream (InputStream& input, int64 numBytesToRead)
|
||||||
while (numBytesToRead > 0)
|
while (numBytesToRead > 0)
|
||||||
{
|
{
|
||||||
uint8 tempBuffer [512];
|
uint8 tempBuffer [512];
|
||||||
const int bytesRead = input.read (tempBuffer, (int) jmin (numBytesToRead, (int64) sizeof (tempBuffer)));
|
auto bytesRead = input.read (tempBuffer, (int) jmin (numBytesToRead, (int64) sizeof (tempBuffer)));
|
||||||
|
|
||||||
if (bytesRead <= 0)
|
if (bytesRead <= 0)
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -235,7 +235,7 @@ public:
|
||||||
env->GetFloatArrayRegion (widths, 0, numDone, localWidths);
|
env->GetFloatArrayRegion (widths, 0, numDone, localWidths);
|
||||||
env->DeleteLocalRef (widths);
|
env->DeleteLocalRef (widths);
|
||||||
|
|
||||||
String::CharPointerType s (text.getCharPointer());
|
auto s = text.getCharPointer();
|
||||||
|
|
||||||
xOffsets.add (0);
|
xOffsets.add (0);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1265,10 +1265,10 @@ private:
|
||||||
|
|
||||||
if (len > 2)
|
if (len > 2)
|
||||||
{
|
{
|
||||||
const float dpi = 96.0f;
|
auto dpi = 96.0f;
|
||||||
|
|
||||||
const juce_wchar n1 = s [len - 2];
|
auto n1 = s[len - 2];
|
||||||
const juce_wchar n2 = s [len - 1];
|
auto n2 = s[len - 1];
|
||||||
|
|
||||||
if (n1 == 'i' && n2 == 'n') n *= dpi;
|
if (n1 == 'i' && n2 == 'n') n *= dpi;
|
||||||
else if (n1 == 'm' && n2 == 'm') n *= dpi / 25.4f;
|
else if (n1 == 'm' && n2 == 'm') n *= dpi / 25.4f;
|
||||||
|
|
@ -1400,7 +1400,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
static bool isIdentifierChar (const juce_wchar c)
|
static bool isIdentifierChar (juce_wchar c)
|
||||||
{
|
{
|
||||||
return CharacterFunctions::isLetter (c) || c == '-';
|
return CharacterFunctions::isLetter (c) || c == '-';
|
||||||
}
|
}
|
||||||
|
|
@ -1446,7 +1446,7 @@ private:
|
||||||
|
|
||||||
static bool parseNextNumber (String::CharPointerType& text, String& value, const bool allowUnits)
|
static bool parseNextNumber (String::CharPointerType& text, String& value, const bool allowUnits)
|
||||||
{
|
{
|
||||||
String::CharPointerType s (text);
|
auto s = text;
|
||||||
|
|
||||||
while (s.isWhitespace() || *s == ',')
|
while (s.isWhitespace() || *s == ',')
|
||||||
++s;
|
++s;
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ namespace juce
|
||||||
{
|
{
|
||||||
|
|
||||||
KeyPress::KeyPress() noexcept
|
KeyPress::KeyPress() noexcept
|
||||||
: keyCode (0), textCharacter (0)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -37,14 +36,12 @@ KeyPress::KeyPress (int code, ModifierKeys m, juce_wchar textChar) noexcept
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyPress::KeyPress (const int code) noexcept
|
KeyPress::KeyPress (const int code) noexcept : keyCode (code)
|
||||||
: keyCode (code), textCharacter (0)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyPress::KeyPress (const KeyPress& other) noexcept
|
KeyPress::KeyPress (const KeyPress& other) noexcept
|
||||||
: keyCode (other.keyCode), mods (other.mods),
|
: keyCode (other.keyCode), mods (other.mods), textCharacter (other.textCharacter)
|
||||||
textCharacter (other.textCharacter)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -53,7 +50,6 @@ KeyPress& KeyPress::operator= (const KeyPress& other) noexcept
|
||||||
keyCode = other.keyCode;
|
keyCode = other.keyCode;
|
||||||
mods = other.mods;
|
mods = other.mods;
|
||||||
textCharacter = other.textCharacter;
|
textCharacter = other.textCharacter;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -75,15 +71,8 @@ bool KeyPress::operator== (const KeyPress& other) const noexcept
|
||||||
== CharacterFunctions::toLowerCase ((juce_wchar) other.keyCode)));
|
== CharacterFunctions::toLowerCase ((juce_wchar) other.keyCode)));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KeyPress::operator!= (const KeyPress& other) const noexcept
|
bool KeyPress::operator!= (const KeyPress& other) const noexcept { return ! operator== (other); }
|
||||||
{
|
bool KeyPress::operator!= (int otherKeyCode) const noexcept { return ! operator== (otherKeyCode); }
|
||||||
return ! operator== (other);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool KeyPress::operator!= (int otherKeyCode) const noexcept
|
|
||||||
{
|
|
||||||
return ! operator== (otherKeyCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool KeyPress::isCurrentlyDown() const
|
bool KeyPress::isCurrentlyDown() const
|
||||||
{
|
{
|
||||||
|
|
@ -149,7 +138,7 @@ namespace KeyPressHelpers
|
||||||
{
|
{
|
||||||
if (desc.containsIgnoreCase (numberPadPrefix()))
|
if (desc.containsIgnoreCase (numberPadPrefix()))
|
||||||
{
|
{
|
||||||
const juce_wchar lastChar = desc.trimEnd().getLastCharacter();
|
auto lastChar = desc.trimEnd().getLastCharacter();
|
||||||
|
|
||||||
switch (lastChar)
|
switch (lastChar)
|
||||||
{
|
{
|
||||||
|
|
@ -241,9 +230,9 @@ KeyPress KeyPress::createFromDescription (const String& desc)
|
||||||
if (key == 0)
|
if (key == 0)
|
||||||
{
|
{
|
||||||
// give up and use the hex code..
|
// give up and use the hex code..
|
||||||
const int hexCode = desc.fromFirstOccurrenceOf ("#", false, false)
|
auto hexCode = desc.fromFirstOccurrenceOf ("#", false, false)
|
||||||
.retainCharacters ("0123456789abcdefABCDEF")
|
.retainCharacters ("0123456789abcdefABCDEF")
|
||||||
.getHexValue32();
|
.getHexValue32();
|
||||||
|
|
||||||
if (hexCode > 0)
|
if (hexCode > 0)
|
||||||
key = hexCode;
|
key = hexCode;
|
||||||
|
|
@ -302,7 +291,7 @@ String KeyPress::getTextDescription() const
|
||||||
String KeyPress::getTextDescriptionWithIcons() const
|
String KeyPress::getTextDescriptionWithIcons() const
|
||||||
{
|
{
|
||||||
#if JUCE_MAC
|
#if JUCE_MAC
|
||||||
String s (getTextDescription());
|
auto s = getTextDescription();
|
||||||
|
|
||||||
for (int i = 0; i < numElementsInArray (KeyPressHelpers::osxSymbols); ++i)
|
for (int i = 0; i < numElementsInArray (KeyPressHelpers::osxSymbols); ++i)
|
||||||
s = s.replace (KeyPressHelpers::osxSymbols[i].text,
|
s = s.replace (KeyPressHelpers::osxSymbols[i].text,
|
||||||
|
|
|
||||||
|
|
@ -263,9 +263,9 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
int keyCode;
|
int keyCode = 0;
|
||||||
ModifierKeys mods;
|
ModifierKeys mods;
|
||||||
juce_wchar textCharacter;
|
juce_wchar textCharacter = 0;
|
||||||
|
|
||||||
JUCE_LEAK_DETECTOR (KeyPress)
|
JUCE_LEAK_DETECTOR (KeyPress)
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -2654,8 +2654,7 @@ private:
|
||||||
{
|
{
|
||||||
updateKeyModifiers();
|
updateKeyModifiers();
|
||||||
|
|
||||||
juce_wchar textChar = (juce_wchar) key;
|
auto textChar = (juce_wchar) key;
|
||||||
|
|
||||||
const int virtualScanCode = (flags >> 16) & 0xff;
|
const int virtualScanCode = (flags >> 16) & 0xff;
|
||||||
|
|
||||||
if (key >= '0' && key <= '9')
|
if (key >= '0' && key <= '9')
|
||||||
|
|
|
||||||
|
|
@ -110,12 +110,12 @@ struct CppTokeniserFunctions
|
||||||
static int parseIdentifier (Iterator& source) noexcept
|
static int parseIdentifier (Iterator& source) noexcept
|
||||||
{
|
{
|
||||||
int tokenLength = 0;
|
int tokenLength = 0;
|
||||||
String::CharPointerType::CharType possibleIdentifier [100];
|
String::CharPointerType::CharType possibleIdentifier[100];
|
||||||
String::CharPointerType possible (possibleIdentifier);
|
String::CharPointerType possible (possibleIdentifier);
|
||||||
|
|
||||||
while (isIdentifierBody (source.peekNextChar()))
|
while (isIdentifierBody (source.peekNextChar()))
|
||||||
{
|
{
|
||||||
const juce_wchar c = source.nextChar();
|
auto c = source.nextChar();
|
||||||
|
|
||||||
if (tokenLength < 20)
|
if (tokenLength < 20)
|
||||||
possible.write (c);
|
possible.write (c);
|
||||||
|
|
@ -137,7 +137,8 @@ struct CppTokeniserFunctions
|
||||||
template <typename Iterator>
|
template <typename Iterator>
|
||||||
static bool skipNumberSuffix (Iterator& source)
|
static bool skipNumberSuffix (Iterator& source)
|
||||||
{
|
{
|
||||||
const juce_wchar c = source.peekNextChar();
|
auto c = source.peekNextChar();
|
||||||
|
|
||||||
if (c == 'l' || c == 'L' || c == 'u' || c == 'U')
|
if (c == 'l' || c == 'L' || c == 'u' || c == 'U')
|
||||||
source.skip();
|
source.skip();
|
||||||
|
|
||||||
|
|
@ -163,11 +164,13 @@ struct CppTokeniserFunctions
|
||||||
if (source.nextChar() != '0')
|
if (source.nextChar() != '0')
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
juce_wchar c = source.nextChar();
|
auto c = source.nextChar();
|
||||||
|
|
||||||
if (c != 'x' && c != 'X')
|
if (c != 'x' && c != 'X')
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
int numDigits = 0;
|
int numDigits = 0;
|
||||||
|
|
||||||
while (isHexDigit (source.peekNextChar()))
|
while (isHexDigit (source.peekNextChar()))
|
||||||
{
|
{
|
||||||
++numDigits;
|
++numDigits;
|
||||||
|
|
@ -257,18 +260,19 @@ struct CppTokeniserFunctions
|
||||||
if (numDigits == 0)
|
if (numDigits == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
juce_wchar c = source.peekNextChar();
|
auto c = source.peekNextChar();
|
||||||
const bool hasExponent = (c == 'e' || c == 'E');
|
bool hasExponent = (c == 'e' || c == 'E');
|
||||||
|
|
||||||
if (hasExponent)
|
if (hasExponent)
|
||||||
{
|
{
|
||||||
source.skip();
|
source.skip();
|
||||||
|
|
||||||
c = source.peekNextChar();
|
c = source.peekNextChar();
|
||||||
|
|
||||||
if (c == '+' || c == '-')
|
if (c == '+' || c == '-')
|
||||||
source.skip();
|
source.skip();
|
||||||
|
|
||||||
int numExpDigits = 0;
|
int numExpDigits = 0;
|
||||||
|
|
||||||
while (isDecimalDigit (source.peekNextChar()))
|
while (isDecimalDigit (source.peekNextChar()))
|
||||||
{
|
{
|
||||||
source.skip();
|
source.skip();
|
||||||
|
|
@ -280,6 +284,7 @@ struct CppTokeniserFunctions
|
||||||
}
|
}
|
||||||
|
|
||||||
c = source.peekNextChar();
|
c = source.peekNextChar();
|
||||||
|
|
||||||
if (c == 'f' || c == 'F')
|
if (c == 'f' || c == 'F')
|
||||||
source.skip();
|
source.skip();
|
||||||
else if (! (hasExponent || hasPoint))
|
else if (! (hasExponent || hasPoint))
|
||||||
|
|
@ -311,11 +316,11 @@ struct CppTokeniserFunctions
|
||||||
template <typename Iterator>
|
template <typename Iterator>
|
||||||
static void skipQuotedString (Iterator& source) noexcept
|
static void skipQuotedString (Iterator& source) noexcept
|
||||||
{
|
{
|
||||||
const juce_wchar quote = source.nextChar();
|
auto quote = source.nextChar();
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
const juce_wchar c = source.nextChar();
|
auto c = source.nextChar();
|
||||||
|
|
||||||
if (c == quote || c == 0)
|
if (c == quote || c == 0)
|
||||||
break;
|
break;
|
||||||
|
|
@ -332,7 +337,7 @@ struct CppTokeniserFunctions
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
const juce_wchar c = source.nextChar();
|
auto c = source.nextChar();
|
||||||
|
|
||||||
if (c == 0 || (c == '/' && lastWasStar))
|
if (c == 0 || (c == '/' && lastWasStar))
|
||||||
break;
|
break;
|
||||||
|
|
@ -348,7 +353,7 @@ struct CppTokeniserFunctions
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
const juce_wchar c = source.peekNextChar();
|
auto c = source.peekNextChar();
|
||||||
|
|
||||||
if (c == '"')
|
if (c == '"')
|
||||||
{
|
{
|
||||||
|
|
@ -360,7 +365,7 @@ struct CppTokeniserFunctions
|
||||||
{
|
{
|
||||||
Iterator next (source);
|
Iterator next (source);
|
||||||
next.skip();
|
next.skip();
|
||||||
const juce_wchar c2 = next.peekNextChar();
|
auto c2 = next.peekNextChar();
|
||||||
|
|
||||||
if (c2 == '/' || c2 == '*')
|
if (c2 == '/' || c2 == '*')
|
||||||
return;
|
return;
|
||||||
|
|
@ -394,7 +399,7 @@ struct CppTokeniserFunctions
|
||||||
template <typename Iterator>
|
template <typename Iterator>
|
||||||
static void skipIfNextCharMatches (Iterator& source, const juce_wchar c1, const juce_wchar c2) noexcept
|
static void skipIfNextCharMatches (Iterator& source, const juce_wchar c1, const juce_wchar c2) noexcept
|
||||||
{
|
{
|
||||||
const juce_wchar c = source.peekNextChar();
|
auto c = source.peekNextChar();
|
||||||
|
|
||||||
if (c == c1 || c == c2)
|
if (c == c1 || c == c2)
|
||||||
source.skip();
|
source.skip();
|
||||||
|
|
@ -404,8 +409,7 @@ struct CppTokeniserFunctions
|
||||||
static int readNextToken (Iterator& source)
|
static int readNextToken (Iterator& source)
|
||||||
{
|
{
|
||||||
source.skipWhitespace();
|
source.skipWhitespace();
|
||||||
|
auto firstChar = source.peekNextChar();
|
||||||
const juce_wchar firstChar = source.peekNextChar();
|
|
||||||
|
|
||||||
switch (firstChar)
|
switch (firstChar)
|
||||||
{
|
{
|
||||||
|
|
@ -416,7 +420,7 @@ struct CppTokeniserFunctions
|
||||||
case '5': case '6': case '7': case '8': case '9':
|
case '5': case '6': case '7': case '8': case '9':
|
||||||
case '.':
|
case '.':
|
||||||
{
|
{
|
||||||
int result = parseNumber (source);
|
auto result = parseNumber (source);
|
||||||
|
|
||||||
if (result == CPlusPlusCodeTokeniser::tokenType_error)
|
if (result == CPlusPlusCodeTokeniser::tokenType_error)
|
||||||
{
|
{
|
||||||
|
|
@ -454,7 +458,7 @@ struct CppTokeniserFunctions
|
||||||
case '-':
|
case '-':
|
||||||
{
|
{
|
||||||
source.skip();
|
source.skip();
|
||||||
int result = parseNumber (source);
|
auto result = parseNumber (source);
|
||||||
|
|
||||||
if (result == CPlusPlusCodeTokeniser::tokenType_error)
|
if (result == CPlusPlusCodeTokeniser::tokenType_error)
|
||||||
{
|
{
|
||||||
|
|
@ -474,7 +478,7 @@ struct CppTokeniserFunctions
|
||||||
case '/':
|
case '/':
|
||||||
{
|
{
|
||||||
source.skip();
|
source.skip();
|
||||||
juce_wchar nextChar = source.peekNextChar();
|
auto nextChar = source.peekNextChar();
|
||||||
|
|
||||||
if (nextChar == '/')
|
if (nextChar == '/')
|
||||||
{
|
{
|
||||||
|
|
@ -527,8 +531,8 @@ struct CppTokeniserFunctions
|
||||||
*/
|
*/
|
||||||
struct StringIterator
|
struct StringIterator
|
||||||
{
|
{
|
||||||
StringIterator (const String& s) noexcept : t (s.getCharPointer()), numChars (0) {}
|
StringIterator (const String& s) noexcept : t (s.getCharPointer()) {}
|
||||||
StringIterator (String::CharPointerType s) noexcept : t (s), numChars (0) {}
|
StringIterator (String::CharPointerType s) noexcept : t (s) {}
|
||||||
|
|
||||||
juce_wchar nextChar() noexcept { if (isEOF()) return 0; ++numChars; return t.getAndAdvance(); }
|
juce_wchar nextChar() noexcept { if (isEOF()) return 0; ++numChars; return t.getAndAdvance(); }
|
||||||
juce_wchar peekNextChar()noexcept { return *t; }
|
juce_wchar peekNextChar()noexcept { return *t; }
|
||||||
|
|
@ -538,7 +542,7 @@ struct CppTokeniserFunctions
|
||||||
bool isEOF() const noexcept { return t.isEmpty(); }
|
bool isEOF() const noexcept { return t.isEmpty(); }
|
||||||
|
|
||||||
String::CharPointerType t;
|
String::CharPointerType t;
|
||||||
int numChars;
|
int numChars = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
@ -562,7 +566,7 @@ struct CppTokeniserFunctions
|
||||||
|
|
||||||
for (int i = 0; i < numBytesToRead || numBytesToRead < 0; ++i)
|
for (int i = 0; i < numBytesToRead || numBytesToRead < 0; ++i)
|
||||||
{
|
{
|
||||||
const unsigned char c = (unsigned char) utf8[i];
|
auto c = (unsigned char) utf8[i];
|
||||||
bool startNewLine = false;
|
bool startNewLine = false;
|
||||||
|
|
||||||
switch (c)
|
switch (c)
|
||||||
|
|
|
||||||
|
|
@ -195,8 +195,9 @@ private:
|
||||||
{
|
{
|
||||||
jassert (index <= line.length());
|
jassert (index <= line.length());
|
||||||
|
|
||||||
String::CharPointerType t (line.getCharPointer());
|
auto t = line.getCharPointer();
|
||||||
int col = 0;
|
int col = 0;
|
||||||
|
|
||||||
for (int i = 0; i < index; ++i)
|
for (int i = 0; i < index; ++i)
|
||||||
{
|
{
|
||||||
if (t.getAndAdvance() != '\t')
|
if (t.getAndAdvance() != '\t')
|
||||||
|
|
@ -208,8 +209,7 @@ private:
|
||||||
return col;
|
return col;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void addToken (Array<SyntaxToken>& dest, const String& text,
|
static void addToken (Array<SyntaxToken>& dest, const String& text, int length, int type)
|
||||||
const int length, const int type)
|
|
||||||
{
|
{
|
||||||
if (length > 1000)
|
if (length > 1000)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ struct LuaTokeniserFunctions
|
||||||
static int parseIdentifier (Iterator& source) noexcept
|
static int parseIdentifier (Iterator& source) noexcept
|
||||||
{
|
{
|
||||||
int tokenLength = 0;
|
int tokenLength = 0;
|
||||||
String::CharPointerType::CharType possibleIdentifier [100];
|
String::CharPointerType::CharType possibleIdentifier[100];
|
||||||
String::CharPointerType possible (possibleIdentifier);
|
String::CharPointerType possible (possibleIdentifier);
|
||||||
|
|
||||||
while (CppTokeniserFunctions::isIdentifierBody (source.peekNextChar()))
|
while (CppTokeniserFunctions::isIdentifierBody (source.peekNextChar()))
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ namespace
|
||||||
if (pattern == patternEnd)
|
if (pattern == patternEnd)
|
||||||
return matchTerminator (target, targetEnd);
|
return matchTerminator (target, targetEnd);
|
||||||
|
|
||||||
const juce_wchar c = pattern.getAndAdvance();
|
auto c = pattern.getAndAdvance();
|
||||||
|
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
|
|
@ -105,7 +105,7 @@ namespace
|
||||||
|
|
||||||
while (pattern != patternEnd)
|
while (pattern != patternEnd)
|
||||||
{
|
{
|
||||||
const juce_wchar c = pattern.getAndAdvance();
|
auto c = pattern.getAndAdvance();
|
||||||
|
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
|
|
@ -135,9 +135,9 @@ namespace
|
||||||
if (set.size() == 0)
|
if (set.size() == 0)
|
||||||
return match (pattern, patternEnd, target, targetEnd);
|
return match (pattern, patternEnd, target, targetEnd);
|
||||||
|
|
||||||
for (const String* str = set.begin(); str != set.end(); ++str)
|
for (auto& str : set)
|
||||||
if (str->getCharPointer().compareUpTo (target, str->length()) == 0)
|
if (str.getCharPointer().compareUpTo (target, str.length()) == 0)
|
||||||
if (match (pattern, patternEnd, target + str->length(), targetEnd))
|
if (match (pattern, patternEnd, target + str.length(), targetEnd))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -155,7 +155,7 @@ namespace
|
||||||
|
|
||||||
while (pattern != patternEnd)
|
while (pattern != patternEnd)
|
||||||
{
|
{
|
||||||
const juce_wchar c = pattern.getAndAdvance();
|
auto c = pattern.getAndAdvance();
|
||||||
|
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
|
|
@ -203,8 +203,8 @@ namespace
|
||||||
static bool matchCharSetNegated (const Array<juce_wchar>& set, CharPtr pattern,
|
static bool matchCharSetNegated (const Array<juce_wchar>& set, CharPtr pattern,
|
||||||
CharPtr patternEnd, CharPtr target, CharPtr targetEnd)
|
CharPtr patternEnd, CharPtr target, CharPtr targetEnd)
|
||||||
{
|
{
|
||||||
for (juce_wchar* c = set.begin(); c != set.end(); ++c)
|
for (auto c : set)
|
||||||
if (*target == *c)
|
if (*target == c)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return match (pattern, patternEnd, target + 1, targetEnd);
|
return match (pattern, patternEnd, target + 1, targetEnd);
|
||||||
|
|
@ -214,8 +214,8 @@ namespace
|
||||||
static bool matchCharSetNotNegated (const Array<juce_wchar>& set, CharPtr pattern,
|
static bool matchCharSetNotNegated (const Array<juce_wchar>& set, CharPtr pattern,
|
||||||
CharPtr patternEnd, CharPtr target, CharPtr targetEnd)
|
CharPtr patternEnd, CharPtr target, CharPtr targetEnd)
|
||||||
{
|
{
|
||||||
for (juce_wchar* c = set.begin(); c != set.end(); ++c)
|
for (auto c : set)
|
||||||
if (*target == *c)
|
if (*target == c)
|
||||||
if (match (pattern, patternEnd, target + 1, targetEnd))
|
if (match (pattern, patternEnd, target + 1, targetEnd))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
@ -229,8 +229,8 @@ namespace
|
||||||
if (target == targetEnd)
|
if (target == targetEnd)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
juce_wchar rangeStart = set.getLast();
|
auto rangeStart = set.getLast();
|
||||||
juce_wchar rangeEnd = pattern.getAndAdvance();
|
auto rangeEnd = pattern.getAndAdvance();
|
||||||
|
|
||||||
if (rangeEnd == ']')
|
if (rangeEnd == ']')
|
||||||
{
|
{
|
||||||
|
|
@ -281,9 +281,10 @@ namespace
|
||||||
|
|
||||||
static bool containsOnlyAllowedPrintableASCIIChars (const String& string) noexcept
|
static bool containsOnlyAllowedPrintableASCIIChars (const String& string) noexcept
|
||||||
{
|
{
|
||||||
for (String::CharPointerType charPtr (string.getCharPointer()); ! charPtr.isEmpty();)
|
for (auto charPtr = string.getCharPointer(); ! charPtr.isEmpty();)
|
||||||
{
|
{
|
||||||
juce_wchar c = charPtr.getAndAdvance();
|
auto c = charPtr.getAndAdvance();
|
||||||
|
|
||||||
if (! isPrintableASCIIChar (c) || isDisallowedChar (c))
|
if (! isPrintableASCIIChar (c) || isDisallowedChar (c))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -304,8 +305,8 @@ namespace
|
||||||
oscSymbols.addTokens (address, "/", StringRef());
|
oscSymbols.addTokens (address, "/", StringRef());
|
||||||
oscSymbols.removeEmptyStrings (false);
|
oscSymbols.removeEmptyStrings (false);
|
||||||
|
|
||||||
for (String* token = oscSymbols.begin(); token != oscSymbols.end(); ++token)
|
for (auto& token : oscSymbols)
|
||||||
if (! containsOnlyAllowedPrintableASCIIChars (*token))
|
if (! containsOnlyAllowedPrintableASCIIChars (token))
|
||||||
throw OSCFormatError ("OSC format error: encountered characters not allowed in address string.");
|
throw OSCFormatError ("OSC format error: encountered characters not allowed in address string.");
|
||||||
|
|
||||||
return oscSymbols;
|
return oscSymbols;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue