-
-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing nil, blank, empty comparisons (#282)
- Loading branch information
1 parent
0ef19d3
commit 4c351d1
Showing
13 changed files
with
278 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System.Globalization; | ||
using System.IO; | ||
using System.Text.Encodings.Web; | ||
|
||
namespace Fluid.Values | ||
{ | ||
public sealed class BlankValue : FluidValue | ||
{ | ||
public static readonly BlankValue Instance = new BlankValue(); | ||
|
||
private BlankValue() | ||
{ | ||
} | ||
|
||
public override FluidValues Type => FluidValues.Empty; | ||
|
||
public override bool Equals(FluidValue other) | ||
{ | ||
if (other == this) return true; | ||
if (other == BooleanValue.False) return true; | ||
if (other == EmptyValue.Instance) return true; | ||
if (other.ToObjectValue() == null) return true; | ||
if (other.Type == FluidValues.String && string.IsNullOrWhiteSpace(other.ToStringValue())) return true; | ||
|
||
return false; | ||
} | ||
|
||
public override bool ToBooleanValue() | ||
{ | ||
return true; | ||
} | ||
|
||
public override decimal ToNumberValue() | ||
{ | ||
return 0; | ||
} | ||
|
||
public override object ToObjectValue() | ||
{ | ||
return ""; | ||
} | ||
|
||
public override string ToStringValue() | ||
{ | ||
return ""; | ||
} | ||
|
||
public override bool IsNil() | ||
{ | ||
return true; | ||
} | ||
|
||
public override void WriteTo(TextWriter writer, TextEncoder encoder, CultureInfo cultureInfo) | ||
{ | ||
} | ||
|
||
public override bool Equals(object other) | ||
{ | ||
// The is operator will return false if null | ||
return other is NilValue; | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return GetType().GetHashCode(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System.Globalization; | ||
using System.IO; | ||
using System.Text.Encodings.Web; | ||
|
||
namespace Fluid.Values | ||
{ | ||
public sealed class EmptyValue : FluidValue | ||
{ | ||
public static readonly EmptyValue Instance = new EmptyValue(); | ||
|
||
private EmptyValue() | ||
{ | ||
} | ||
|
||
public override FluidValues Type => FluidValues.Empty; | ||
|
||
public override bool Equals(FluidValue other) | ||
{ | ||
if (other.Type == FluidValues.String && other.ToStringValue() == "") return true; | ||
if (other.Type == FluidValues.Array && other.ToNumberValue() == 0) return true; | ||
if (other == BlankValue.Instance) return true; | ||
if (other == EmptyValue.Instance) return true; | ||
if (other == NilValue.Instance) return false; | ||
|
||
return false; | ||
} | ||
|
||
public override bool ToBooleanValue() | ||
{ | ||
return true; | ||
} | ||
|
||
public override decimal ToNumberValue() | ||
{ | ||
return 0; | ||
} | ||
|
||
public override object ToObjectValue() | ||
{ | ||
return ""; | ||
} | ||
|
||
public override string ToStringValue() | ||
{ | ||
return ""; | ||
} | ||
|
||
public override bool IsNil() | ||
{ | ||
return true; | ||
} | ||
|
||
public override void WriteTo(TextWriter writer, TextEncoder encoder, CultureInfo cultureInfo) | ||
{ | ||
} | ||
|
||
public override bool Equals(object other) | ||
{ | ||
// The is operator will return false if null | ||
return other is NilValue; | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return GetType().GetHashCode(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
public enum FluidValues | ||
{ | ||
Nil, | ||
Empty, | ||
Blank, | ||
Array, | ||
Boolean, | ||
Dictionary, | ||
|
Oops, something went wrong.