-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added parser and removed useless factory (#22)
- Loading branch information
Showing
9 changed files
with
309 additions
and
199 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Infrastructure.IO; | ||
|
||
namespace Implementation.IO | ||
{ | ||
internal class DefaultDataParser : IDataParser | ||
{ | ||
public T TryParse<T>(string input, IDataParser.TryParseHandler<T> handler, out bool isOkay) | ||
{ | ||
isOkay = handler(input, out var result); | ||
return result; | ||
} | ||
|
||
public IEnumerable<T> TryParse<T>(string input, IDataParser.TryParseHandler<T> handler, out bool isOkay, char separator, params char[] separators) | ||
{ | ||
isOkay = false; | ||
separators = new[] | ||
{ | ||
separator | ||
}.Concat(separators).ToArray(); | ||
|
||
var lines = input.Split(separators, StringSplitOptions.RemoveEmptyEntries).ToList(); | ||
lines.RemoveAll(c => c is "\r\n" or "\n" or "\r" or "\n\r"); | ||
|
||
var convertedLines = new List<T>(); | ||
foreach (var line in lines) | ||
{ | ||
isOkay = handler(line, out var result); | ||
if (isOkay) | ||
{ | ||
convertedLines.Add(result); | ||
} | ||
} | ||
|
||
return convertedLines; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,17 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Infrastructure.IO | ||
{ | ||
public interface IDataParser | ||
{ | ||
/// <summary> | ||
/// Used to specify the parser method for the <c>ReadLine()</c> method. | ||
/// </summary> | ||
/// <typeparam name="T">Can be any ValueType.</typeparam> | ||
delegate bool TryParseHandler<T>(string value, out T result); | ||
|
||
T? TryParse<T>(string input, TryParseHandler<T> handler, out bool isOkay); | ||
|
||
IEnumerable<T> TryParse<T>(string input, TryParseHandler<T> handler, out bool isOkay, char separator, params char[] separators); | ||
} | ||
} |
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
Oops, something went wrong.