Skip to content

Commit

Permalink
Merge branch 'next' into DeclarationFinderForCustomDeclarations
Browse files Browse the repository at this point in the history
  • Loading branch information
retailcoder committed Jan 24, 2017
2 parents 5f27c3c + e8061aa commit f2edd01
Showing 1 changed file with 5 additions and 26 deletions.
31 changes: 5 additions & 26 deletions Rubberduck.Parsing/Preprocessing/LivelinessExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,23 @@ public LivelinessExpression(IExpression isAlive, IExpression code)

public override IValue Evaluate()
{
bool isAlive = _isAlive.Evaluate().AsBool;
var isAlive = _isAlive.Evaluate().AsBool;
var code = _code.Evaluate().AsString;
if (isAlive)
{
return new StringValue(code);
}
else
{
return new StringValue(MarkAsDead(code));
}
return isAlive ? new StringValue(code) : new StringValue(MarkAsDead(code));
}

private string MarkAsDead(string code)
{
bool hasNewLine = false;
if (code.EndsWith(Environment.NewLine))
{
hasNewLine = true;
}
var hasNewLine = code.EndsWith(Environment.NewLine);
// Remove parsed new line.
code = code.TrimEnd('\r', '\n');
var lines = code.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
code = code.Substring(0, code.Length - Environment.NewLine.Length);
var lines = code.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
var result = string.Join(Environment.NewLine, lines.Select(_ => string.Empty));
if (hasNewLine)
{
result += Environment.NewLine;
}
return result;
}

private string MarkLineAsDead(string line)
{
var result = string.Empty;
if (line.EndsWith(Environment.NewLine))
{
result += Environment.NewLine;
}
return result;
}
}
}

0 comments on commit f2edd01

Please sign in to comment.