@@ -16,44 +16,23 @@ public LivelinessExpression(IExpression isAlive, IExpression code)
16
16
17
17
public override IValue Evaluate ( )
18
18
{
19
- bool isAlive = _isAlive . Evaluate ( ) . AsBool ;
19
+ var isAlive = _isAlive . Evaluate ( ) . AsBool ;
20
20
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 ) ) ;
29
22
}
30
23
31
24
private string MarkAsDead ( string code )
32
25
{
33
- bool hasNewLine = false ;
34
- if ( code . EndsWith ( Environment . NewLine ) )
35
- {
36
- hasNewLine = true ;
37
- }
26
+ var hasNewLine = code . EndsWith ( Environment . NewLine ) ;
38
27
// 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 ) ;
41
30
var result = string . Join ( Environment . NewLine , lines . Select ( _ => string . Empty ) ) ;
42
31
if ( hasNewLine )
43
32
{
44
33
result += Environment . NewLine ;
45
34
}
46
35
return result ;
47
36
}
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
- }
58
37
}
59
38
}
0 commit comments