1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-16 00:34:19 +00:00

Made SortedSet::add() return a bool. Improvements to code editor indents.

This commit is contained in:
jules 2012-08-04 14:31:23 +01:00
parent 19e304bc6f
commit 8149502c8b
2 changed files with 29 additions and 33 deletions

View file

@ -176,6 +176,24 @@ namespace CppUtils
return String (line.getCharPointer(), endOfLeadingWS);
}
static int getBraceCount (String::CharPointerType line)
{
int braces = 0;
for (;;)
{
const juce_wchar c = line.getAndAdvance();
if (c == 0) break;
else if (c == '{') ++braces;
else if (c == '}') --braces;
else if (c == '/') { if (*line == '/') break; }
else if (c == '"' || c == '\'') { while (! (line.isEmpty() || line.getAndAdvance() == c)) {} }
}
return braces;
}
static bool getIndentForCurrentBlock (CodeDocument::Position pos, String& whitespace)
{
int braceCount = 0;
@ -187,35 +205,12 @@ namespace CppUtils
const String line (pos.getLineText());
const String trimmedLine (line.trimStart());
String::CharPointerType l (trimmedLine.getCharPointer());
braceCount += getBraceCount (trimmedLine.getCharPointer());
for (;;)
if (braceCount > 0)
{
const juce_wchar c = l.getAndAdvance();
if (c == 0)
break;
if (c == '}')
++braceCount;
if (c == '{')
{
if (--braceCount < 0)
{
whitespace = getLeadingWhitespace (line);
return true;
}
}
if (c == '"' || c == '\'')
{
while (! (l.isEmpty() || l.getAndAdvance() == c))
{}
}
if (c == '/' && *l == '/')
break;
whitespace = getLeadingWhitespace (line);
return true;
}
}
@ -254,11 +249,10 @@ void CppCodeEditorComponent::handleReturnKey()
while (pos.getLineNumber() > 0)
{
pos = pos.movedByLines (-1);
const String leadingWhitespace (CppUtils::getLeadingWhitespace (pos.getLineText()));
if (leadingWhitespace.isNotEmpty())
if (pos.getLineText().trimStart().isNotEmpty())
{
insertTextAtCaret (leadingWhitespace);
insertTextAtCaret (CppUtils::getLeadingWhitespace (pos.getLineText()));
break;
}
}