| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="InflectionRule.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System.Text.RegularExpressions; |
| | | 8 | | |
| | | 9 | | namespace MyNet.Globalization.Inflection; |
| | | 10 | | |
| | | 11 | | /// <summary> |
| | | 12 | | /// Represents a single inflection rule, consisting of a regular expression pattern and a replacement string. The rule c |
| | | 13 | | /// </summary> |
| | | 14 | | /// <param name="Regex">The regular expression pattern to match.</param> |
| | | 15 | | /// <param name="Replacement">The replacement string to use when the pattern matches.</param> |
| | | 16 | | public sealed record InflectionRule(Regex Regex, string Replacement) |
| | | 17 | | { |
| | | 18 | | /// <summary> |
| | | 19 | | /// Applies the inflection rule to the specified word. If the regular expression pattern matches the word, it return |
| | | 20 | | /// </summary> |
| | | 21 | | /// <param name="word">The word to which the inflection rule will be applied.</param> |
| | | 22 | | /// <returns>The transformed word if the pattern matches; otherwise, null.</returns> |
| | 149181 | 23 | | public string? Apply(string word) => !Regex.IsMatch(word) ? null : Regex.Replace(word, Replacement); |
| | | 24 | | } |
| | | 25 | | |