[DEV] better condition
This commit is contained in:
parent
9c051cd9ed
commit
258a6766c8
@ -133,17 +133,11 @@ estyle::Generator::Generator():
|
||||
propertyBrace.set("catch", etk::move(estyle::GroupProperty(this, "brace", "catch", false)));
|
||||
|
||||
propertyParenthese.set("if", etk::move(estyle::GroupProperty(this, "parenthese", "if")));
|
||||
propertyParenthese["if"].oneLineMaxSize.set(2000);
|
||||
propertyParenthese.set("for", etk::move(estyle::GroupProperty(this, "parenthese", "for")));
|
||||
propertyParenthese["for"].oneLineMaxSize.set(2000);
|
||||
propertyParenthese.set("while", etk::move(estyle::GroupProperty(this, "parenthese", "while")));
|
||||
propertyParenthese["while"].oneLineMaxSize.set(2000);
|
||||
propertyParenthese.set("do-while", etk::move(estyle::GroupProperty(this, "parenthese", "do-while")));
|
||||
propertyParenthese["do-while"].oneLineMaxSize.set(2000);
|
||||
propertyParenthese.set("switch", etk::move(estyle::GroupProperty(this, "parenthese", "switch")));
|
||||
propertyParenthese["switch"].oneLineMaxSize.set(2000);
|
||||
propertyParenthese.set("block", etk::move(estyle::GroupProperty(this, "parenthese", "block")));
|
||||
propertyParenthese["block"].oneLineMaxSize.set(2000);
|
||||
|
||||
}
|
||||
|
||||
@ -587,7 +581,8 @@ int32_t estyle::Generator::process(int32_t _startId,
|
||||
process(jjj+1, endSectionA);
|
||||
m_output += ";";
|
||||
ESTYLE_WARNING("big size: " << propertyParenthese[m_type].oneLineMaxSize.get() << " <= " << rawSize);
|
||||
if (propertyParenthese[m_type].oneLineMaxSize.get() <= rawSize) {
|
||||
if ( propertyParenthese[m_type].oneLineMaxSize.get() <= rawSize
|
||||
|| propertyParenthese[m_type].oneLineMaxSize.get() == -1) {
|
||||
addNewLine();
|
||||
addIndent();
|
||||
} else {
|
||||
@ -596,7 +591,8 @@ int32_t estyle::Generator::process(int32_t _startId,
|
||||
// write section B
|
||||
process(endSectionA+1, endSectionB);
|
||||
m_output += ";";
|
||||
if (propertyParenthese[m_type].oneLineMaxSize.get() <= rawSize) {
|
||||
if ( propertyParenthese[m_type].oneLineMaxSize.get() <= rawSize
|
||||
|| propertyParenthese[m_type].oneLineMaxSize.get() == -1) {
|
||||
addNewLine();
|
||||
addIndent();
|
||||
} else {
|
||||
@ -1048,31 +1044,67 @@ bool estyle::Generator::nextIs(int64_t _pos, enum estyle::lexer::tocken _nextTyp
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
eproperty::Value<bool> inSpaceBefore;
|
||||
eproperty::Value<bool> inSpaceAfter;
|
||||
eproperty::Value<bool> outSpaceBefore;
|
||||
eproperty::Value<bool> outSpaceAfter;
|
||||
eproperty::Value<int32_t> oneLineMaxSize;
|
||||
*/
|
||||
|
||||
int64_t estyle::Generator::generateCondition(int64_t _pos) {
|
||||
ESTYLE_INFO(" single " << propertyParenthese[m_type].single.get());
|
||||
ESTYLE_INFO(" inNewLineBefore " << propertyParenthese[m_type].inNewLineBefore.get());
|
||||
ESTYLE_INFO(" inNewLineAfter " << propertyParenthese[m_type].inNewLineAfter.get());
|
||||
ESTYLE_INFO(" inSpaceBefore " << propertyParenthese[m_type].inSpaceBefore.get());
|
||||
ESTYLE_INFO(" inSpaceAfter " << propertyParenthese[m_type].inSpaceAfter.get());
|
||||
ESTYLE_INFO(" inIndentBefore " << propertyParenthese[m_type].inIndentBefore.get());
|
||||
ESTYLE_INFO(" inIndentAfter " << propertyParenthese[m_type].inIndentAfter.get());
|
||||
|
||||
ESTYLE_INFO(" outNewLineBefore " << propertyParenthese[m_type].outNewLineBefore.get());
|
||||
ESTYLE_INFO(" outNewLineAfter " << propertyParenthese[m_type].outNewLineAfter.get());
|
||||
ESTYLE_INFO(" outSpaceBefore " << propertyParenthese[m_type].outSpaceBefore.get());
|
||||
ESTYLE_INFO(" outSpaceAfter " << propertyParenthese[m_type].outSpaceAfter.get());
|
||||
ESTYLE_INFO(" outUnIndentBefore " << propertyParenthese[m_type].outUnIndentBefore.get());
|
||||
ESTYLE_INFO(" outUnIndentAfter " << propertyParenthese[m_type].outUnIndentAfter.get());
|
||||
|
||||
int32_t sectionEnd = endOfSection(_pos);
|
||||
|
||||
int32_t nbCondition = countCurrentLevelCondition(_pos);
|
||||
int32_t rawSize = countRawSize(_pos, sectionEnd);
|
||||
bool onOneLine = propertyParenthese[m_type].oneLineMaxSize.get() >= rawSize;
|
||||
|
||||
if (propertyParenthese[m_type].inSpaceBefore.get() == true) {
|
||||
bool removeNewLine = propertyParenthese[m_type].oneLineMaxSize.get() >= rawSize;
|
||||
if (propertyParenthese[m_type].oneLineMaxSize.get() == -1) {
|
||||
removeNewLine = false;
|
||||
}
|
||||
if (propertyParenthese[m_type].inIndentBefore.get() == true) {
|
||||
ESTYLE_INFO(" ==> indent Before");
|
||||
indentationPush();
|
||||
addIndent();
|
||||
}
|
||||
if ( propertyParenthese[m_type].inNewLineBefore.get() == true
|
||||
&& removeNewLine == false) {
|
||||
addNewLine();
|
||||
addSpace();
|
||||
} else if (propertyParenthese[m_type].inSpaceBefore.get() == true) {
|
||||
addSpace();
|
||||
}
|
||||
m_output += "(";
|
||||
if (propertyParenthese[m_type].inSpaceAfter.get() == true) {
|
||||
if (propertyParenthese[m_type].inIndentAfter.get() == true) {
|
||||
ESTYLE_INFO(" ==> indent After");
|
||||
indentationPush();
|
||||
}
|
||||
if ( propertyParenthese[m_type].inNewLineAfter.get() == true
|
||||
&& removeNewLine == false) {
|
||||
addNewLine();
|
||||
} else if ( propertyParenthese[m_type].inSpaceAfter.get() == true
|
||||
&& rawSize != 0) {
|
||||
addSpace();
|
||||
}
|
||||
|
||||
|
||||
int32_t nbCondition = countCurrentLevelCondition(_pos);
|
||||
if (rawSize == 0) {
|
||||
if ( m_output.back() == '\n'
|
||||
|| m_output.back() == '\r') {
|
||||
if (propertyParenthese[m_type].emptyIndent.get() == true) {
|
||||
addIndent();
|
||||
addNewLine(true);
|
||||
}
|
||||
} else if (propertyParenthese[m_type].emptySpace.get() == true) {
|
||||
addSpace();
|
||||
}
|
||||
}
|
||||
if ( nbCondition == 0
|
||||
|| onOneLine == true) {
|
||||
|| removeNewLine == true) {
|
||||
ESTYLE_WARNING("==> only one element");
|
||||
process(_pos+1, sectionEnd);
|
||||
} else {
|
||||
@ -1096,13 +1128,29 @@ int64_t estyle::Generator::generateCondition(int64_t _pos) {
|
||||
}
|
||||
offsetPop();
|
||||
}
|
||||
if (propertyParenthese[m_type].outSpaceBefore.get() == true) {
|
||||
if (propertyParenthese[m_type].outUnIndentBefore.get() == true) {
|
||||
indentationPop();
|
||||
}
|
||||
if ( propertyParenthese[m_type].outNewLineBefore.get() == true
|
||||
&& removeNewLine == false) {
|
||||
addNewLine();
|
||||
addSpace();
|
||||
} else if ( propertyParenthese[m_type].outSpaceBefore.get() == true
|
||||
&& rawSize != 0) {
|
||||
addSpace();
|
||||
}
|
||||
m_output += ")";
|
||||
if (propertyParenthese[m_type].outSpaceAfter.get() == true) {
|
||||
if (propertyParenthese[m_type].outUnIndentAfter.get() == true) {
|
||||
indentationPop();
|
||||
}
|
||||
if ( propertyParenthese[m_type].outSpaceAfter.get() == true
|
||||
&& propertyParenthese[m_type].outNewLineAfter.get() == false) {
|
||||
// add 1 space if needed
|
||||
addSpace();
|
||||
}
|
||||
if (propertyParenthese[m_type].outNewLineAfter.get() == true) {
|
||||
addNewLine();
|
||||
}
|
||||
return sectionEnd;
|
||||
}
|
||||
|
||||
|
2531
test/testIf.cpp
2531
test/testIf.cpp
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user