Browse Source

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

tags/2021-05-28
jules 13 years ago
parent
commit
8149502c8b
2 changed files with 29 additions and 33 deletions
  1. +24
    -30
      extras/Introjucer/Source/Code Editor/jucer_SourceCodeEditor.cpp
  2. +5
    -3
      modules/juce_core/containers/juce_SortedSet.h

+ 24
- 30
extras/Introjucer/Source/Code Editor/jucer_SourceCodeEditor.cpp 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;
}
}


+ 5
- 3
modules/juce_core/containers/juce_SortedSet.h View File

@@ -269,10 +269,11 @@ public:
the objects which were not recognised by the object's operator==, then the
set will always contain a copy of the most recently added one.
@param newElement the new object to add to the set
@param newElement the new object to add to the set
@returns true if the value was added, or false if it already existed
@see set, insert, addIfNotAlreadyThere, addSorted, addSet, addArray
*/
void add (const ElementType& newElement) noexcept
bool add (const ElementType& newElement) noexcept
{
const ScopedLockType lock (getLock());
@@ -285,7 +286,7 @@ public:
if (newElement == elem)
{
elem = newElement; // force an update in case operator== permits differences.
return;
return false;
}
const int halfway = (s + e) / 2;
@@ -305,6 +306,7 @@ public:
}
data.insert (s, newElement);
return true;
}
/** Adds elements from an array to this set.


Loading…
Cancel
Save