Skip to content

Commit

Permalink
Implemented InternalParse() method of the ConfigEntryParser class.
Browse files Browse the repository at this point in the history
  • Loading branch information
xvitaly committed May 6, 2024
1 parent 7d984e9 commit 275f488
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/corelib/ConfigEntryParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,34 @@ public sealed class ConfigEntryParser
/// <returns>Returns the ConfigEntryParser object, or null if exceptions are disabled.</returns>
private static ConfigEntryParser InternalParse(string Value, bool TryParse)
{
throw new NotImplementedException();
// Checking the source string for null...
if (string.IsNullOrWhiteSpace(Value))
{
if (TryParse) { return null; } else { throw new ArgumentException("Game config entry string cannot be null, empty or contain only spaces.", nameof(Value)); }
}

// Calculating the indices of the first space and the double slash character...
int SpaceIndex = Value.IndexOf(" ", StringComparison.InvariantCulture);
int CommentIndex = Value.IndexOf("//", StringComparison.InvariantCulture);

// If the source string contains no spaces, return it as is...
if ((SpaceIndex == -1) && (CommentIndex == -1))
{
return new ConfigEntryParser(Value, string.Empty, string.Empty);
}

// Parsing the source string...
try
{
string NameStr = Value.Substring(0, SpaceIndex);
string ValueStr = CommentIndex > SpaceIndex ? Value.Substring(SpaceIndex + 1, CommentIndex - SpaceIndex - 1) : Value.Remove(0, SpaceIndex + 1);
string CommentStr = CommentIndex > 0 ? Value.Substring(CommentIndex + 2).Trim() : string.Empty;
return new ConfigEntryParser(NameStr, ValueStr, CommentStr);
}
catch
{
if (TryParse) { return null; } else { throw; }
}
}

/// <summary>
Expand Down

0 comments on commit 275f488

Please sign in to comment.