From 4668d7782e1a270e379ee37c1f7963f78f31c0a6 Mon Sep 17 00:00:00 2001 From: Serghei Cebotari Date: Sun, 20 Apr 2025 11:55:06 +0300 Subject: Update regex patterns for diameter handling and add test cases for pipes --- .../DrinkingWaterHeatingFitting.cs | 59 +++++++++++----------- 1 file changed, 30 insertions(+), 29 deletions(-) (limited to 'RhSolutions.Parsers/DrinkingWaterHeatingFittings') diff --git a/RhSolutions.Parsers/DrinkingWaterHeatingFittings/DrinkingWaterHeatingFitting.cs b/RhSolutions.Parsers/DrinkingWaterHeatingFittings/DrinkingWaterHeatingFitting.cs index 7dba12c..867e886 100644 --- a/RhSolutions.Parsers/DrinkingWaterHeatingFittings/DrinkingWaterHeatingFitting.cs +++ b/RhSolutions.Parsers/DrinkingWaterHeatingFittings/DrinkingWaterHeatingFitting.cs @@ -4,35 +4,36 @@ namespace RhSolutions.Parsers.Fittings; public abstract class DrinkingWaterHeatingFitting : IProductParser { - protected static readonly Regex _diameter = - new(@"(?16|20|25|32|40|50|63|15|26)[\b\D]?"); - protected static readonly Regex _angle = - new(@"(?45|90)([\b\D]|$)"); - protected static readonly Regex _thread = - new(@"(?1\s+1/4|1\s+1/2|1/2|3/4|2|1)([\b\D]|$)"); + protected static readonly Regex _diameter = + new(@"(?16|20|25|32|40|50|63|14|15|26)(?!\d)"); + protected static readonly Regex _angle = + new(@"(?45|90)(?!\d)"); + protected static readonly Regex _thread = + new(@"(?1\s+1/4|1\s+1/2|1/2|3/4|2|1)(?!\d)"); - protected virtual string _title { get; } = string.Empty; + protected virtual string _title { get; } = string.Empty; - public virtual bool TryParse(string input, out string output) - { - var match = _diameter.Match(input); - if (match.Success) - { - output = $"{_title} {match.Groups["Diameter"]}"; - return true; - } - else - { - output = string.Empty; - return false; - } - } - protected string NormalizeDiameter(string diameter) - { - return diameter switch - { - "26" => "25", - _ => diameter - }; - } + public virtual bool TryParse(string input, out string output) + { + var match = _diameter.Match(input); + if (match.Success) + { + output = $"{_title} {match.Groups["Diameter"]}"; + return true; + } + else + { + output = string.Empty; + return false; + } + } + protected string NormalizeDiameter(string diameter) + { + return diameter switch + { + "14" => "16", + "26" => "25", + _ => diameter + }; + } } -- cgit v1.2.3