1
0
Fork 0
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:
jules 2017-10-19 16:50:02 +01:00
parent d346d6ef50
commit f0ef700e46
27 changed files with 356 additions and 379 deletions

View file

@ -110,12 +110,12 @@ struct CppTokeniserFunctions
static int parseIdentifier (Iterator& source) noexcept
{
int tokenLength = 0;
String::CharPointerType::CharType possibleIdentifier [100];
String::CharPointerType::CharType possibleIdentifier[100];
String::CharPointerType possible (possibleIdentifier);
while (isIdentifierBody (source.peekNextChar()))
{
const juce_wchar c = source.nextChar();
auto c = source.nextChar();
if (tokenLength < 20)
possible.write (c);
@ -137,7 +137,8 @@ struct CppTokeniserFunctions
template <typename Iterator>
static bool skipNumberSuffix (Iterator& source)
{
const juce_wchar c = source.peekNextChar();
auto c = source.peekNextChar();
if (c == 'l' || c == 'L' || c == 'u' || c == 'U')
source.skip();
@ -163,11 +164,13 @@ struct CppTokeniserFunctions
if (source.nextChar() != '0')
return false;
juce_wchar c = source.nextChar();
auto c = source.nextChar();
if (c != 'x' && c != 'X')
return false;
int numDigits = 0;
while (isHexDigit (source.peekNextChar()))
{
++numDigits;
@ -257,18 +260,19 @@ struct CppTokeniserFunctions
if (numDigits == 0)
return false;
juce_wchar c = source.peekNextChar();
const bool hasExponent = (c == 'e' || c == 'E');
auto c = source.peekNextChar();
bool hasExponent = (c == 'e' || c == 'E');
if (hasExponent)
{
source.skip();
c = source.peekNextChar();
if (c == '+' || c == '-')
source.skip();
int numExpDigits = 0;
while (isDecimalDigit (source.peekNextChar()))
{
source.skip();
@ -280,6 +284,7 @@ struct CppTokeniserFunctions
}
c = source.peekNextChar();
if (c == 'f' || c == 'F')
source.skip();
else if (! (hasExponent || hasPoint))
@ -311,11 +316,11 @@ struct CppTokeniserFunctions
template <typename Iterator>
static void skipQuotedString (Iterator& source) noexcept
{
const juce_wchar quote = source.nextChar();
auto quote = source.nextChar();
for (;;)
{
const juce_wchar c = source.nextChar();
auto c = source.nextChar();
if (c == quote || c == 0)
break;
@ -332,7 +337,7 @@ struct CppTokeniserFunctions
for (;;)
{
const juce_wchar c = source.nextChar();
auto c = source.nextChar();
if (c == 0 || (c == '/' && lastWasStar))
break;
@ -348,7 +353,7 @@ struct CppTokeniserFunctions
for (;;)
{
const juce_wchar c = source.peekNextChar();
auto c = source.peekNextChar();
if (c == '"')
{
@ -360,7 +365,7 @@ struct CppTokeniserFunctions
{
Iterator next (source);
next.skip();
const juce_wchar c2 = next.peekNextChar();
auto c2 = next.peekNextChar();
if (c2 == '/' || c2 == '*')
return;
@ -394,7 +399,7 @@ struct CppTokeniserFunctions
template <typename Iterator>
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)
source.skip();
@ -404,8 +409,7 @@ struct CppTokeniserFunctions
static int readNextToken (Iterator& source)
{
source.skipWhitespace();
const juce_wchar firstChar = source.peekNextChar();
auto firstChar = source.peekNextChar();
switch (firstChar)
{
@ -416,7 +420,7 @@ struct CppTokeniserFunctions
case '5': case '6': case '7': case '8': case '9':
case '.':
{
int result = parseNumber (source);
auto result = parseNumber (source);
if (result == CPlusPlusCodeTokeniser::tokenType_error)
{
@ -454,7 +458,7 @@ struct CppTokeniserFunctions
case '-':
{
source.skip();
int result = parseNumber (source);
auto result = parseNumber (source);
if (result == CPlusPlusCodeTokeniser::tokenType_error)
{
@ -474,7 +478,7 @@ struct CppTokeniserFunctions
case '/':
{
source.skip();
juce_wchar nextChar = source.peekNextChar();
auto nextChar = source.peekNextChar();
if (nextChar == '/')
{
@ -527,8 +531,8 @@ struct CppTokeniserFunctions
*/
struct StringIterator
{
StringIterator (const String& s) noexcept : t (s.getCharPointer()), numChars (0) {}
StringIterator (String::CharPointerType s) noexcept : t (s), numChars (0) {}
StringIterator (const String& s) noexcept : t (s.getCharPointer()) {}
StringIterator (String::CharPointerType s) noexcept : t (s) {}
juce_wchar nextChar() noexcept { if (isEOF()) return 0; ++numChars; return t.getAndAdvance(); }
juce_wchar peekNextChar()noexcept { return *t; }
@ -538,7 +542,7 @@ struct CppTokeniserFunctions
bool isEOF() const noexcept { return t.isEmpty(); }
String::CharPointerType t;
int numChars;
int numChars = 0;
};
//==============================================================================
@ -562,7 +566,7 @@ struct CppTokeniserFunctions
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;
switch (c)

View file

@ -195,8 +195,9 @@ private:
{
jassert (index <= line.length());
String::CharPointerType t (line.getCharPointer());
auto t = line.getCharPointer();
int col = 0;
for (int i = 0; i < index; ++i)
{
if (t.getAndAdvance() != '\t')
@ -208,8 +209,7 @@ private:
return col;
}
static void addToken (Array<SyntaxToken>& dest, const String& text,
const int length, const int type)
static void addToken (Array<SyntaxToken>& dest, const String& text, int length, int type)
{
if (length > 1000)
{

View file

@ -79,7 +79,7 @@ struct LuaTokeniserFunctions
static int parseIdentifier (Iterator& source) noexcept
{
int tokenLength = 0;
String::CharPointerType::CharType possibleIdentifier [100];
String::CharPointerType::CharType possibleIdentifier[100];
String::CharPointerType possible (possibleIdentifier);
while (CppTokeniserFunctions::isIdentifierBody (source.peekNextChar()))