Skip to content

Commit

Permalink
Made FixHBSJsonCommas regex precompiled.
Browse files Browse the repository at this point in the history
  • Loading branch information
CptMoore committed Dec 6, 2024
1 parent 7c9defc commit dae0aef
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ModTek/Util/HBSJsonUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ internal static JObject ParseGameJSON(string content, bool log = false)
return JObject.Parse(commasAdded);
}

private static readonly Regex s_fixMissingCommasInJson = new(
"""(\]|\}|"|[A-Za-z0-9])\s*\n\s*(\[|\{|")""",
RegexOptions.Singleline|RegexOptions.Compiled
);
private static string FixHBSJsonCommas(string json)
{
// add missing commas, this only fixes if there is a newline
var rgx = new Regex(@"(\]|\}|""|[A-Za-z0-9])\s*\n\s*(\[|\{|"")", RegexOptions.Singleline);
return rgx.Replace(json, "$1,\n$2");
return s_fixMissingCommasInJson.Replace(json, "$1,\n$2");
}
}

0 comments on commit dae0aef

Please sign in to comment.