| | | 1 | | using System.Text.RegularExpressions; |
| | | 2 | | |
| | | 3 | | namespace TeleFlow.Telegram.Internal.Handlers; |
| | | 4 | | |
| | | 5 | | internal sealed class TelegramRouteMatcher |
| | | 6 | | { |
| | | 7 | | private TelegramRouteMatcher(Regex? regex) |
| | | 8 | | { |
| | | 9 | | Regex = regex; |
| | 1152 | 10 | | } |
| | | 11 | | |
| | | 12 | | public Regex? Regex { get; } |
| | | 13 | | |
| | | 14 | | public static TelegramRouteMatcher Create( |
| | | 15 | | TelegramRouteKind routeKind, |
| | | 16 | | string? pattern, |
| | | 17 | | bool ignoreCase) |
| | | 18 | | { |
| | 1152 | 19 | | if (string.IsNullOrWhiteSpace(pattern)) |
| | | 20 | | { |
| | 595 | 21 | | return new TelegramRouteMatcher(regex: null); |
| | | 22 | | } |
| | | 23 | | |
| | 557 | 24 | | return routeKind switch |
| | 557 | 25 | | { |
| | 557 | 26 | | TelegramRouteKind.TextTemplate or TelegramRouteKind.CommandTemplate => |
| | 100 | 27 | | new TelegramRouteMatcher(TelegramTemplateRouteParser.BuildRegex(pattern, ignoreCase)), |
| | 557 | 28 | | TelegramRouteKind.TextRegex or TelegramRouteKind.CommandRegex => |
| | 7 | 29 | | new TelegramRouteMatcher(new Regex(pattern, TelegramTemplateRouteParser.GetRegexOptions(ignoreCase))), |
| | 450 | 30 | | _ => new TelegramRouteMatcher(regex: null) |
| | 557 | 31 | | }; |
| | | 32 | | } |
| | | 33 | | } |