Skip to content

Commit e8061aa

Browse files
authored
Merge pull request #2574 from comintern/next
Fix MarkAsDead so it doesn't eat too extra NewLines. Closes #2022
2 parents 18568e5 + fe83950 commit e8061aa

File tree

1 file changed

+5
-26
lines changed

1 file changed

+5
-26
lines changed

Rubberduck.Parsing/Preprocessing/LivelinessExpression.cs

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,23 @@ public LivelinessExpression(IExpression isAlive, IExpression code)
1616

1717
public override IValue Evaluate()
1818
{
19-
bool isAlive = _isAlive.Evaluate().AsBool;
19+
var isAlive = _isAlive.Evaluate().AsBool;
2020
var code = _code.Evaluate().AsString;
21-
if (isAlive)
22-
{
23-
return new StringValue(code);
24-
}
25-
else
26-
{
27-
return new StringValue(MarkAsDead(code));
28-
}
21+
return isAlive ? new StringValue(code) : new StringValue(MarkAsDead(code));
2922
}
3023

3124
private string MarkAsDead(string code)
3225
{
33-
bool hasNewLine = false;
34-
if (code.EndsWith(Environment.NewLine))
35-
{
36-
hasNewLine = true;
37-
}
26+
var hasNewLine = code.EndsWith(Environment.NewLine);
3827
// Remove parsed new line.
39-
code = code.TrimEnd('\r', '\n');
40-
var lines = code.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
28+
code = code.Substring(0, code.Length - Environment.NewLine.Length);
29+
var lines = code.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
4130
var result = string.Join(Environment.NewLine, lines.Select(_ => string.Empty));
4231
if (hasNewLine)
4332
{
4433
result += Environment.NewLine;
4534
}
4635
return result;
4736
}
48-
49-
private string MarkLineAsDead(string line)
50-
{
51-
var result = string.Empty;
52-
if (line.EndsWith(Environment.NewLine))
53-
{
54-
result += Environment.NewLine;
55-
}
56-
return result;
57-
}
5837
}
5938
}

0 commit comments

Comments
 (0)