Readonly readers in readers, update CMP reader

This commit is contained in:
Matt Nadareski
2020-09-21 13:20:58 -07:00
parent db0c50bd3a
commit 83d67c7ac1
3 changed files with 16 additions and 18 deletions

View File

@@ -14,7 +14,7 @@ namespace SabreTools.Library.IO
/// <summary> /// <summary>
/// Internal stream reader for inputting /// Internal stream reader for inputting
/// </summary> /// </summary>
private StreamReader sr; private readonly StreamReader sr;
/// <summary> /// <summary>
/// Contents of the current line, unprocessed /// Contents of the current line, unprocessed
@@ -104,26 +104,24 @@ namespace SabreTools.Library.IO
CurrentLine = sr.ReadLine().Trim(); CurrentLine = sr.ReadLine().Trim();
LineNumber++; LineNumber++;
ProcessLine();
// TODO: Act like IniReader here
ProcessLine(CurrentLine);
return true; return true;
} }
/// <summary> /// <summary>
/// Process the current line and extract out values /// Process the current line and extract out values
/// </summary> /// </summary>
private void ProcessLine(string line) private void ProcessLine()
{ {
// Standalone (special case for DC dats) // Standalone (special case for DC dats)
if (line.StartsWith("Name:")) if (CurrentLine.StartsWith("Name:"))
{ {
string temp = line.Substring("Name:".Length).Trim(); string temp = CurrentLine.Substring("Name:".Length).Trim();
line = $"Name: {temp}"; CurrentLine = $"Name: {temp}";
} }
// Comment // Comment
if (line.StartsWith("#")) if (CurrentLine.StartsWith("#"))
{ {
Internal = null; Internal = null;
InternalName = null; InternalName = null;
@@ -132,9 +130,9 @@ namespace SabreTools.Library.IO
} }
// Top-level // Top-level
else if (Regex.IsMatch(line, Constants.HeaderPatternCMP)) else if (Regex.IsMatch(CurrentLine, Constants.HeaderPatternCMP))
{ {
GroupCollection gc = Regex.Match(line, Constants.HeaderPatternCMP).Groups; GroupCollection gc = Regex.Match(CurrentLine, Constants.HeaderPatternCMP).Groups;
string normalizedValue = gc[1].Value.ToLowerInvariant(); string normalizedValue = gc[1].Value.ToLowerInvariant();
Internal = null; Internal = null;
@@ -145,9 +143,9 @@ namespace SabreTools.Library.IO
} }
// Internal // Internal
else if (Regex.IsMatch(line, Constants.InternalPatternCMP)) else if (Regex.IsMatch(CurrentLine, Constants.InternalPatternCMP))
{ {
GroupCollection gc = Regex.Match(line, Constants.InternalPatternCMP).Groups; GroupCollection gc = Regex.Match(CurrentLine, Constants.InternalPatternCMP).Groups;
string normalizedValue = gc[1].Value.ToLowerInvariant(); string normalizedValue = gc[1].Value.ToLowerInvariant();
string[] linegc = SplitLineAsCMP(gc[2].Value); string[] linegc = SplitLineAsCMP(gc[2].Value);
@@ -234,9 +232,9 @@ namespace SabreTools.Library.IO
} }
// Standalone // Standalone
else if (Regex.IsMatch(line, Constants.ItemPatternCMP)) else if (Regex.IsMatch(CurrentLine, Constants.ItemPatternCMP))
{ {
GroupCollection gc = Regex.Match(line, Constants.ItemPatternCMP).Groups; GroupCollection gc = Regex.Match(CurrentLine, Constants.ItemPatternCMP).Groups;
string itemval = gc[2].Value.Replace("\"", string.Empty); string itemval = gc[2].Value.Replace("\"", string.Empty);
Internal = null; Internal = null;
@@ -246,7 +244,7 @@ namespace SabreTools.Library.IO
} }
// End section // End section
else if (Regex.IsMatch(line, Constants.EndPatternCMP)) else if (Regex.IsMatch(CurrentLine, Constants.EndPatternCMP))
{ {
Internal = null; Internal = null;
InternalName = null; InternalName = null;

View File

@@ -11,7 +11,7 @@ namespace SabreTools.Library.IO
/// <summary> /// <summary>
/// Internal stream reader for inputting /// Internal stream reader for inputting
/// </summary> /// </summary>
private StreamReader sr; private readonly StreamReader sr;
/// <summary> /// <summary>
/// Get if at end of stream /// Get if at end of stream

View File

@@ -12,7 +12,7 @@ namespace SabreTools.Library.IO
/// <summary> /// <summary>
/// Internal stream reader for inputting /// Internal stream reader for inputting
/// </summary> /// </summary>
private StreamReader sr; private readonly StreamReader sr;
/// <summary> /// <summary>
/// Internal value to say how many fields should be written /// Internal value to say how many fields should be written