Make regexes in LaurisItem static and readonly.

In order to speed parsing up a little bit.
This commit is contained in:
Daniel Kraus 2015-08-28 17:21:19 +02:00
parent 66ad3886da
commit 6e969dacd9

View File

@ -103,19 +103,15 @@ namespace zaaReloaded2.Importer.ZaaImporter
// "HBs-Antigen: neg. ;" // "HBs-Antigen: neg. ;"
// "Erythrozyten (U): + [negativ]" // "Erythrozyten (U): + [negativ]"
Match match; Match match;
Regex numericalRegex = new Regex( if (_numericalRegex.IsMatch(LaurisText))
@"(?<name>[^:]+):\s*(?<value>[\d,.]+)\s*(?<limits>\[[^\]]+])?\s*(?<unit>[^;]+)?");
Regex categoricalRegex = new Regex(
@"(?<name>[^:]+):\s*(?<value>[^[;]+)\s*(\[(?<normal>[^\]]+)])?");
if (numericalRegex.IsMatch(LaurisText))
{ {
match = numericalRegex.Match(LaurisText); match = _numericalRegex.Match(LaurisText);
ParseLimits(match); ParseLimits(match);
Value = match.Groups["value"].Value.Trim().Replace(',', '.'); Value = match.Groups["value"].Value.Trim().Replace(',', '.');
} }
else else
{ {
match = categoricalRegex.Match(LaurisText); match = _categoricalRegex.Match(LaurisText);
Normal = match.Groups["normal"].Value.Trim(); Normal = match.Groups["normal"].Value.Trim();
Value = match.Groups["value"].Value.Trim(); Value = match.Groups["value"].Value.Trim();
} }
@ -136,8 +132,7 @@ namespace zaaReloaded2.Importer.ZaaImporter
{ {
if (match.Groups["limits"].Success) if (match.Groups["limits"].Success)
{ {
Regex limitRegex = new Regex(@"\[(?<limit1>[-\d,.]+)?\s*(?<operator>\S+)\s*(?<limit2>[-\d,.]+)?]"); Match limitMatch = _limitRegex.Match(match.Groups["limits"].Value);
Match limitMatch = limitRegex.Match(match.Groups["limits"].Value);
if (limitMatch.Groups["limit1"].Success && limitMatch.Groups["limit2"].Success) if (limitMatch.Groups["limit1"].Success && limitMatch.Groups["limit2"].Success)
{ {
// Use InvariantCulture because Lauris always outputs dots as decimal separator // Use InvariantCulture because Lauris always outputs dots as decimal separator
@ -203,6 +198,11 @@ namespace zaaReloaded2.Importer.ZaaImporter
#region Fields #region Fields
static readonly Regex _numericalRegex = new Regex(
@"(?<name>[^:]+):\s*(?<value>[\d,.]+)\s*(?<limits>\[[^\]]+])?\s*(?<unit>[^;]+)?");
static readonly Regex _categoricalRegex = new Regex(
@"(?<name>[^:]+):\s*(?<value>[^[;]+)\s*(\[(?<normal>[^\]]+)])?");
static readonly Regex _limitRegex = new Regex(@"\[(?<limit1>[-\d,.]+)?\s*(?<operator>\S+)\s*(?<limit2>[-\d,.]+)?]");
static readonly Regex _materialRegex = new Regex(@"\((?<material>(SU|PU))\)"); static readonly Regex _materialRegex = new Regex(@"\((?<material>(SU|PU))\)");
#endregion #endregion