Skip to content

Commit

Permalink
Replace explicit line terminators with LineTerminator const.
Browse files Browse the repository at this point in the history
  • Loading branch information
davebronson committed Nov 7, 2021
1 parent 88b5837 commit 4187d29
Show file tree
Hide file tree
Showing 19 changed files with 63 additions and 65 deletions.
7 changes: 0 additions & 7 deletions src/ClearHl7/ClearHl7.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,4 @@
<LangVersion>latest</LangVersion>
<DocumentationFile>bin\Release\netstandard2.0\ClearHl7.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Folder Include="Extensions\" />
<Folder Include="Serialization\" />
</ItemGroup>
<ItemGroup>
<None Remove="Serialization\" />
</ItemGroup>
</Project>
5 changes: 5 additions & 0 deletions src/ClearHl7/Consts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
/// </summary>
public static class Consts
{
/// <summary>
/// Standard Message line terminator.
/// </summary>
public const char LineTerminator = (char)13;

/// <summary>
/// Default field separator.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/ClearHl7/Helpers/MessageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static Hl7Version DetectVersion(string delimitedString)
startPosition++;

// Find the ending position of the version identifier
int endPosition = delimitedString.IndexOfAny(new[] { fieldSeparator, delimitedString[4], (char)13 }, startPosition);
int endPosition = delimitedString.IndexOfAny(new[] { fieldSeparator, delimitedString[4], Consts.LineTerminator }, startPosition);

if (endPosition == -1)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ClearHl7/Serialization/MessageSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static T Deserialize<T>(string delimitedString) where T : class, IMessage
CultureInfo culture = CultureInfo.CurrentCulture;
string[] segments = delimitedString == null
? Array.Empty<string>()
: delimitedString.Split(new char[] { (char)13 }, StringSplitOptions.RemoveEmptyEntries);
: delimitedString.Split(new char[] { Consts.LineTerminator }, StringSplitOptions.RemoveEmptyEntries);
List<ISegment> list = new();
Type messageClass = item.GetType();

Expand Down
2 changes: 1 addition & 1 deletion src/ClearHl7/V230/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public string ToDelimitedString()
}

output.Append(item.ToDelimitedString());
output.Append((char)13);
output.Append(Consts.LineTerminator);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ClearHl7/V231/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public string ToDelimitedString()
}

output.Append(item.ToDelimitedString());
output.Append((char)13);
output.Append(Consts.LineTerminator);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ClearHl7/V240/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public string ToDelimitedString()
}

output.Append(item.ToDelimitedString());
output.Append((char)13);
output.Append(Consts.LineTerminator);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ClearHl7/V250/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public string ToDelimitedString()
}

output.Append(item.ToDelimitedString());
output.Append((char)13);
output.Append(Consts.LineTerminator);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ClearHl7/V251/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public string ToDelimitedString()
}

output.Append(item.ToDelimitedString());
output.Append((char)13);
output.Append(Consts.LineTerminator);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ClearHl7/V260/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public string ToDelimitedString()
}

output.Append(item.ToDelimitedString());
output.Append((char)13);
output.Append(Consts.LineTerminator);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ClearHl7/V270/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public string ToDelimitedString()
}

output.Append(item.ToDelimitedString());
output.Append((char)13);
output.Append(Consts.LineTerminator);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ClearHl7/V271/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public string ToDelimitedString()
}

output.Append(item.ToDelimitedString());
output.Append((char)13);
output.Append(Consts.LineTerminator);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ClearHl7/V280/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public string ToDelimitedString()
}

output.Append(item.ToDelimitedString());
output.Append((char)13);
output.Append(Consts.LineTerminator);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ClearHl7/V281/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public string ToDelimitedString()
}

output.Append(item.ToDelimitedString());
output.Append((char)13);
output.Append(Consts.LineTerminator);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ClearHl7/V282/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public string ToDelimitedString()
}

output.Append(item.ToDelimitedString());
output.Append((char)13);
output.Append(Consts.LineTerminator);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ClearHl7/V290/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public string ToDelimitedString()
}

output.Append(item.ToDelimitedString());
output.Append((char)13);
output.Append(Consts.LineTerminator);
}
}

Expand Down
50 changes: 25 additions & 25 deletions test/ClearHl7.Tests/HelpersTests/MessageHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class MessageHelperTests
[Fact]
public void DetectVersion_With23Specified_ReturnsCorrectHl7Version()
{
Assert.True(MessageHelper.DetectVersion(@"MSH|^~\&||||||||||2.3||") == Hl7Version.V230);
Assert.True(MessageHelper.DetectVersion($"{ @"MSH|^~\&||||||||||2.3||" }{ Consts.LineTerminator }") == Hl7Version.V230);
}

/// <summary>
Expand All @@ -21,7 +21,7 @@ public void DetectVersion_With23Specified_ReturnsCorrectHl7Version()
[Fact]
public void DetectVersion_With230Specified_ReturnsCorrectHl7Version()
{
Assert.True(MessageHelper.DetectVersion(@"MSH|^~\&||||||||||2.3.0||") == Hl7Version.V230);
Assert.True(MessageHelper.DetectVersion($"{ @"MSH|^~\&||||||||||2.3.0||" }{ Consts.LineTerminator }") == Hl7Version.V230);
}

/// <summary>
Expand All @@ -30,7 +30,7 @@ public void DetectVersion_With230Specified_ReturnsCorrectHl7Version()
[Fact]
public void DetectVersion_With231Specified_ReturnsCorrectHl7Version()
{
Assert.True(MessageHelper.DetectVersion(@"MSH|^~\&||||||||||2.3.1||") == Hl7Version.V231);
Assert.True(MessageHelper.DetectVersion($"{ @"MSH|^~\&||||||||||2.3.1||" }{ Consts.LineTerminator }") == Hl7Version.V231);
}

/// <summary>
Expand All @@ -39,7 +39,7 @@ public void DetectVersion_With231Specified_ReturnsCorrectHl7Version()
[Fact]
public void DetectVersion_With24Specified_ReturnsCorrectHl7Version()
{
Assert.True(MessageHelper.DetectVersion(@"MSH|^~\&||||||||||2.4||") == Hl7Version.V240);
Assert.True(MessageHelper.DetectVersion($"{ @"MSH|^~\&||||||||||2.4||" }{ Consts.LineTerminator }") == Hl7Version.V240);
}

/// <summary>
Expand All @@ -48,7 +48,7 @@ public void DetectVersion_With24Specified_ReturnsCorrectHl7Version()
[Fact]
public void DetectVersion_With240Specified_ReturnsCorrectHl7Version()
{
Assert.True(MessageHelper.DetectVersion(@"MSH|^~\&||||||||||2.4.0||") == Hl7Version.V240);
Assert.True(MessageHelper.DetectVersion($"{ @"MSH|^~\&||||||||||2.4.0||" }{ Consts.LineTerminator }") == Hl7Version.V240);
}

/// <summary>
Expand All @@ -57,7 +57,7 @@ public void DetectVersion_With240Specified_ReturnsCorrectHl7Version()
[Fact]
public void DetectVersion_With25Specified_ReturnsCorrectHl7Version()
{
Assert.True(MessageHelper.DetectVersion(@"MSH|^~\&||||||||||2.5||") == Hl7Version.V250);
Assert.True(MessageHelper.DetectVersion($"{ @"MSH|^~\&||||||||||2.5||" }{ Consts.LineTerminator }") == Hl7Version.V250);
}

/// <summary>
Expand All @@ -66,7 +66,7 @@ public void DetectVersion_With25Specified_ReturnsCorrectHl7Version()
[Fact]
public void DetectVersion_With250Specified_ReturnsCorrectHl7Version()
{
Assert.True(MessageHelper.DetectVersion(@"MSH|^~\&||||||||||2.5.0||") == Hl7Version.V250);
Assert.True(MessageHelper.DetectVersion($"{ @"MSH|^~\&||||||||||2.5.0||" }{ Consts.LineTerminator }") == Hl7Version.V250);
}

/// <summary>
Expand All @@ -75,7 +75,7 @@ public void DetectVersion_With250Specified_ReturnsCorrectHl7Version()
[Fact]
public void DetectVersion_With251Specified_ReturnsCorrectHl7Version()
{
Assert.True(MessageHelper.DetectVersion(@"MSH|^~\&||||||||||2.5.1||") == Hl7Version.V251);
Assert.True(MessageHelper.DetectVersion($"{ @"MSH|^~\&||||||||||2.5.1||" }{ Consts.LineTerminator }") == Hl7Version.V251);
}

/// <summary>
Expand All @@ -84,7 +84,7 @@ public void DetectVersion_With251Specified_ReturnsCorrectHl7Version()
[Fact]
public void DetectVersion_With26Specified_ReturnsCorrectHl7Version()
{
Assert.True(MessageHelper.DetectVersion(@"MSH|^~\&||||||||||2.6||") == Hl7Version.V260);
Assert.True(MessageHelper.DetectVersion($"{ @"MSH|^~\&||||||||||2.6||" }{ Consts.LineTerminator }") == Hl7Version.V260);
}

/// <summary>
Expand All @@ -93,7 +93,7 @@ public void DetectVersion_With26Specified_ReturnsCorrectHl7Version()
[Fact]
public void DetectVersion_With260Specified_ReturnsCorrectHl7Version()
{
Assert.True(MessageHelper.DetectVersion(@"MSH|^~\&||||||||||2.6.0||") == Hl7Version.V260);
Assert.True(MessageHelper.DetectVersion($"{ @"MSH|^~\&||||||||||2.6.0||" }{ Consts.LineTerminator }") == Hl7Version.V260);
}

/// <summary>
Expand All @@ -102,7 +102,7 @@ public void DetectVersion_With260Specified_ReturnsCorrectHl7Version()
[Fact]
public void DetectVersion_With27Specified_ReturnsCorrectHl7Version()
{
Assert.True(MessageHelper.DetectVersion(@"MSH|^~\&||||||||||2.7||") == Hl7Version.V270);
Assert.True(MessageHelper.DetectVersion($"{ @"MSH|^~\&||||||||||2.7||" }{ Consts.LineTerminator }") == Hl7Version.V270);
}

/// <summary>
Expand All @@ -111,7 +111,7 @@ public void DetectVersion_With27Specified_ReturnsCorrectHl7Version()
[Fact]
public void DetectVersion_With270Specified_ReturnsCorrectHl7Version()
{
Assert.True(MessageHelper.DetectVersion(@"MSH|^~\&||||||||||2.7.0||") == Hl7Version.V270);
Assert.True(MessageHelper.DetectVersion($"{ @"MSH|^~\&||||||||||2.7.0||" }{ Consts.LineTerminator }") == Hl7Version.V270);
}

/// <summary>
Expand All @@ -120,7 +120,7 @@ public void DetectVersion_With270Specified_ReturnsCorrectHl7Version()
[Fact]
public void DetectVersion_With271Specified_ReturnsCorrectHl7Version()
{
Assert.True(MessageHelper.DetectVersion(@"MSH|^~\&||||||||||2.7.1||") == Hl7Version.V271);
Assert.True(MessageHelper.DetectVersion($"{ @"MSH|^~\&||||||||||2.7.1||" }{ Consts.LineTerminator }") == Hl7Version.V271);
}

/// <summary>
Expand All @@ -129,7 +129,7 @@ public void DetectVersion_With271Specified_ReturnsCorrectHl7Version()
[Fact]
public void DetectVersion_With28Specified_ReturnsCorrectHl7Version()
{
Assert.True(MessageHelper.DetectVersion(@"MSH|^~\&||||||||||2.8||") == Hl7Version.V280);
Assert.True(MessageHelper.DetectVersion($"{ @"MSH|^~\&||||||||||2.8||" }{ Consts.LineTerminator }") == Hl7Version.V280);
}

/// <summary>
Expand All @@ -138,7 +138,7 @@ public void DetectVersion_With28Specified_ReturnsCorrectHl7Version()
[Fact]
public void DetectVersion_With280Specified_ReturnsCorrectHl7Version()
{
Assert.True(MessageHelper.DetectVersion(@"MSH|^~\&||||||||||2.8.0||") == Hl7Version.V280);
Assert.True(MessageHelper.DetectVersion($"{ @"MSH|^~\&||||||||||2.8.0||" }{ Consts.LineTerminator }") == Hl7Version.V280);
}

/// <summary>
Expand All @@ -147,7 +147,7 @@ public void DetectVersion_With280Specified_ReturnsCorrectHl7Version()
[Fact]
public void DetectVersion_With281Specified_ReturnsCorrectHl7Version()
{
Assert.True(MessageHelper.DetectVersion(@"MSH|^~\&||||||||||2.8.1||") == Hl7Version.V281);
Assert.True(MessageHelper.DetectVersion($"{ @"MSH|^~\&||||||||||2.8.1||" }{ Consts.LineTerminator }") == Hl7Version.V281);
}

/// <summary>
Expand All @@ -156,7 +156,7 @@ public void DetectVersion_With281Specified_ReturnsCorrectHl7Version()
[Fact]
public void DetectVersion_With282Specified_ReturnsCorrectHl7Version()
{
Assert.True(MessageHelper.DetectVersion(@"MSH|^~\&||||||||||2.8.2||") == Hl7Version.V282);
Assert.True(MessageHelper.DetectVersion($"{ @"MSH|^~\&||||||||||2.8.2||" }{ Consts.LineTerminator }") == Hl7Version.V282);
}

/// <summary>
Expand All @@ -165,7 +165,7 @@ public void DetectVersion_With282Specified_ReturnsCorrectHl7Version()
[Fact]
public void DetectVersion_With29Specified_ReturnsCorrectHl7Version()
{
Assert.True(MessageHelper.DetectVersion(@"MSH|^~\&||||||||||2.9||") == Hl7Version.V290);
Assert.True(MessageHelper.DetectVersion($"{ @"MSH|^~\&||||||||||2.9||" }{ Consts.LineTerminator }") == Hl7Version.V290);
}

/// <summary>
Expand All @@ -174,7 +174,7 @@ public void DetectVersion_With29Specified_ReturnsCorrectHl7Version()
[Fact]
public void DetectVersion_With290Specified_ReturnsCorrectHl7Version()
{
Assert.True(MessageHelper.DetectVersion(@"MSH|^~\&||||||||||2.9.0||") == Hl7Version.V290);
Assert.True(MessageHelper.DetectVersion($"{ @"MSH|^~\&||||||||||2.9.0||" }{ Consts.LineTerminator }") == Hl7Version.V290);
}

/// <summary>
Expand All @@ -183,7 +183,7 @@ public void DetectVersion_With290Specified_ReturnsCorrectHl7Version()
[Fact]
public void DetectVersion_WithMultipleComponentsInPositionTwelve_ReturnsCorrectHl7Version()
{
Assert.True(MessageHelper.DetectVersion(@"MSH|^~\&||||||||||2.5.1^something else||") == Hl7Version.V251);
Assert.True(MessageHelper.DetectVersion($"{ @"MSH|^~\&||||||||||2.5.1^something else||" }{ Consts.LineTerminator }") == Hl7Version.V251);
}

/// <summary>
Expand All @@ -192,7 +192,7 @@ public void DetectVersion_WithMultipleComponentsInPositionTwelve_ReturnsCorrectH
[Fact]
public void DetectVersion_WithCustomComponentSeparator_ReturnsCorrectHl7Version()
{
Assert.True(MessageHelper.DetectVersion(@"MSH|$~\&||||||||||2.5.1$something else||") == Hl7Version.V251);
Assert.True(MessageHelper.DetectVersion($"{ @"MSH|$~\&||||||||||2.5.1$something else||" }{ Consts.LineTerminator }") == Hl7Version.V251);
}

/// <summary>
Expand All @@ -201,7 +201,7 @@ public void DetectVersion_WithCustomComponentSeparator_ReturnsCorrectHl7Version(
[Fact]
public void DetectVersion_WithCustomFieldSeparator_ReturnsCorrectHl7Version()
{
Assert.True(MessageHelper.DetectVersion(@"MSH$^~\&$$$$$$$$$$2.5.1$$") == Hl7Version.V251);
Assert.True(MessageHelper.DetectVersion($"{ @"MSH$^~\&$$$$$$$$$$2.5.1$$" }{ Consts.LineTerminator }") == Hl7Version.V251);
}

/// <summary>
Expand All @@ -210,7 +210,7 @@ public void DetectVersion_WithCustomFieldSeparator_ReturnsCorrectHl7Version()
[Fact]
public void DetectVersion_WithExactly12Positions_ReturnsCorrectHl7Version()
{
Assert.True(MessageHelper.DetectVersion($"{ @"MSH|^~\&||||||||||2.5.1" }{ (char)13 }") == Hl7Version.V251);
Assert.True(MessageHelper.DetectVersion($"{ @"MSH|^~\&||||||||||2.5.1" }{ Consts.LineTerminator }") == Hl7Version.V251);
}

/// <summary>
Expand All @@ -219,7 +219,7 @@ public void DetectVersion_WithExactly12Positions_ReturnsCorrectHl7Version()
[Fact]
public void DetectVersion_WithLessThan12Positions_ReturnsCorrectHl7Version()
{
Assert.True(MessageHelper.DetectVersion(@"MSH|^~\&||||||") == Hl7Version.None);
Assert.True(MessageHelper.DetectVersion($"{ @"MSH|^~\&||||||" }{ Consts.LineTerminator }") == Hl7Version.None);
}

/// <summary>
Expand Down Expand Up @@ -254,7 +254,7 @@ public void DetectVersion_WithInvalidFirstSegment_ThrowsArgumentException()
{
Assert.Throws<ArgumentException>(() =>
{
MessageHelper.DetectVersion(@"ABC|^~\&||||||||||2.8.0||");
MessageHelper.DetectVersion($"{ @"ABC|^~\&||||||||||2.8.0||" }{ Consts.LineTerminator }");
});
}

Expand Down
Loading

1 comment on commit 4187d29

@davebronson
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolves #35

Please sign in to comment.