Skip to content

Commit

Permalink
Add & Apply clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
skapix committed Dec 25, 2017
1 parent dd9cb69 commit b50ef94
Show file tree
Hide file tree
Showing 10 changed files with 331 additions and 247 deletions.
103 changes: 103 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
Language: Cpp
BasedOnStyle: llvm
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: false
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
# AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeBinaryOperators: None
BreakBeforeInheritanceComma: true
BreakBeforeTernaryOperators: false
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
FixNamespaceComments: true
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
# IncludeBlocks: Merge
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '$'
IndentCaseLabels: false
# IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: true
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 2
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 10
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: false
SortUsingDeclarations: false
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 2
UseTab: Never

175 changes: 88 additions & 87 deletions cohbcalc/ConsoleHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ void handleChar(char c)

string getExpression()
{
if (!all_of(g_currentExpression.begin(), g_currentExpression.end(),
[](char c){
return std::isspace(c); }))
if (!all_of(g_currentExpression.begin(), g_currentExpression.end(), [](char c) { return std::isspace(c); }))
{
g_expressionHistory.push_back(g_currentExpression);
}
Expand Down Expand Up @@ -76,96 +74,99 @@ void updateStringView()

const int g_pgCount = 5;

void handleSpecialKey(const SpecialKey key) {
switch (key) {
case SpecialKey::Up:
g_expressionHistory.getElement(-1);
updateStringView();
break;
case SpecialKey::Down:
g_expressionHistory.getElement(1);
updateStringView();
break;
case SpecialKey::PageUp:
g_expressionHistory.getElement(-g_pgCount);
updateStringView();
break;
case SpecialKey::PageDown:
g_expressionHistory.getElement(g_pgCount);
updateStringView();
break;
case SpecialKey::Left:
if (g_currentPosition != g_currentExpression.begin())
{
--g_currentPosition;
cursorLeft();
}
break;
case SpecialKey::Right:
if (g_currentPosition != g_currentExpression.end())
{
++g_currentPosition;
cursorRight();
}
break;
case SpecialKey::CtrlLeft:
do
{
handleSpecialKey(SpecialKey::Left);
} while(g_currentPosition != g_currentExpression.begin() && isalnum(*g_currentPosition));
break;
case SpecialKey::CtrlRight:
do
{
handleSpecialKey(SpecialKey::Right);
} while(g_currentPosition != g_currentExpression.end() && isalnum(*g_currentPosition));
break;
case SpecialKey::Home:
while (g_currentPosition != g_currentExpression.begin())
{
handleSpecialKey(SpecialKey::Left);
}
break;
case SpecialKey::End:
while (g_currentPosition != g_currentExpression.end())
{
handleSpecialKey(SpecialKey::Right);
}
break;
case SpecialKey::Delete:
if (g_currentPosition == g_currentExpression.end())
{
break;
}
void handleSpecialKey(const SpecialKey key)
{
switch (key)
{
case SpecialKey::Up:
g_expressionHistory.getElement(-1);
updateStringView();
break;
case SpecialKey::Down:
g_expressionHistory.getElement(1);
updateStringView();
break;
case SpecialKey::PageUp:
g_expressionHistory.getElement(-g_pgCount);
updateStringView();
break;
case SpecialKey::PageDown:
g_expressionHistory.getElement(g_pgCount);
updateStringView();
break;
case SpecialKey::Left:
if (g_currentPosition != g_currentExpression.begin())
{
--g_currentPosition;
cursorLeft();
}
break;
case SpecialKey::Right:
if (g_currentPosition != g_currentExpression.end())
{
++g_currentPosition;
cursorRight();
}
break;
case SpecialKey::CtrlLeft:
do
{
handleSpecialKey(SpecialKey::Left);
} while (g_currentPosition != g_currentExpression.begin() && isalnum(*g_currentPosition));
break;
case SpecialKey::CtrlRight:
do
{
handleSpecialKey(SpecialKey::Right);
} while (g_currentPosition != g_currentExpression.end() && isalnum(*g_currentPosition));
break;
case SpecialKey::Home:
while (g_currentPosition != g_currentExpression.begin())
{
handleSpecialKey(SpecialKey::Left);
}
break;
case SpecialKey::End:
while (g_currentPosition != g_currentExpression.end())
{
handleSpecialKey(SpecialKey::Right);
// go forward
case SpecialKey::BackSpace:
if (g_currentPosition != g_currentExpression.begin())
}
break;
case SpecialKey::Delete:
if (g_currentPosition == g_currentExpression.end())
{
break;
}
handleSpecialKey(SpecialKey::Right);
// go forward
case SpecialKey::BackSpace:
if (g_currentPosition != g_currentExpression.begin())
{
backspace();
g_currentPosition = g_currentExpression.erase(std::prev(g_currentPosition));

int goBack = 0;
for (auto it = g_currentPosition; it != g_currentExpression.end(); ++it, ++goBack)
{
backspace();
g_currentPosition = g_currentExpression.erase(std::prev(g_currentPosition));

int goBack = 0;
for (auto it = g_currentPosition; it != g_currentExpression.end(); ++it, ++goBack)
{
putchar(*it);
}
putchar(' ');
++goBack;
for (int i = 0; i < goBack; ++i)
cursorLeft();
putchar(*it);
}
break;
case SpecialKey::EndLine:
putchar('\n');
break;
case SpecialKey::Undefined:
// do nothing
break;
putchar(' ');
++goBack;
for (int i = 0; i < goBack; ++i)
cursorLeft();
}
break;
case SpecialKey::EndLine:
putchar('\n');
break;
case SpecialKey::Undefined:
// do nothing
break;
}
}

void markError(size_t pos) {
void markError(size_t pos)
{
for (size_t i = 0; i < pos; ++i)
{
putchar(' ');
Expand Down
9 changes: 5 additions & 4 deletions cohbcalc/ExpressionHistory.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "ExpressionHistory.h"

ExpressionHistory::ExpressionHistory() : m_it(m_history.cend())
{
}
ExpressionHistory::ExpressionHistory()
: m_it(m_history.cend())
{}


const std::string *ExpressionHistory::getElement(int relPos)
Expand Down Expand Up @@ -35,7 +35,8 @@ const std::string *ExpressionHistory::getElement(int relPos)
return m_it == m_history.cend() ? nullptr : &*m_it;
}

void ExpressionHistory::push_back(std::string value) {
void ExpressionHistory::push_back(std::string value)
{
m_history.push_back(std::move(value));
m_it = m_history.end();
}
Loading

0 comments on commit b50ef94

Please sign in to comment.