| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="TransformExtensions.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using System.Globalization; |
| | | 9 | | using System.Linq; |
| | | 10 | | |
| | | 11 | | #pragma warning disable IDE0130 // Namespace does not match folder structure |
| | | 12 | | namespace MyNet.Text; |
| | | 13 | | #pragma warning restore IDE0130 // Namespace does not match folder structure |
| | | 14 | | |
| | | 15 | | public static class TransformExtensions |
| | | 16 | | { |
| | | 17 | | extension(TextPipeline pipeline) |
| | | 18 | | { |
| | | 19 | | /// <summary> |
| | | 20 | | /// Transforms the text in the pipeline using the provided transformers. Transformations are applied in the prov |
| | | 21 | | /// </summary> |
| | | 22 | | /// <param name="transformers">The transformers to apply.</param> |
| | | 23 | | /// <returns>The transformed text.</returns> |
| | 3 | 24 | | public string Transform(params ITextTransform[] transformers) => pipeline.Apply(transformers).Value; |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Applies the provided transformers to the pipeline. Transformations are applied in the provided order. |
| | | 28 | | /// </summary> |
| | | 29 | | /// <param name="transformers">The transformers to apply.</param> |
| | | 30 | | /// <returns>The transformed TextPipeline instance.</returns> |
| | 6 | 31 | | public TextPipeline Apply(params ITextTransform[] transformers) => transformers.Aggregate(pipeline, (current, tr |
| | | 32 | | } |
| | | 33 | | |
| | | 34 | | extension(string input) |
| | | 35 | | { |
| | | 36 | | /// <summary> |
| | | 37 | | /// Transforms a string using the provided transformers. Transformations are applied in the provided order. |
| | | 38 | | /// </summary> |
| | | 39 | | public string Apply(CultureInfo culture, params ITextTransform[] transformers) |
| | | 40 | | { |
| | 252 | 41 | | ArgumentNullException.ThrowIfNull(input); |
| | 252 | 42 | | ArgumentNullException.ThrowIfNull(culture); |
| | | 43 | | |
| | 252 | 44 | | return transformers.Aggregate(input, (current, transform) => transform.Apply(current, culture)); |
| | | 45 | | } |
| | | 46 | | |
| | | 47 | | /// <summary> |
| | | 48 | | /// Transforms a string using the provided transformers. Transformations are applied in the provided order. The |
| | | 49 | | /// </summary> |
| | | 50 | | /// <param name="transformers">The transformers to apply.</param> |
| | | 51 | | /// <returns>The transformed string.</returns> |
| | 0 | 52 | | public string Apply(params ITextTransform[] transformers) => input.Apply(CultureInfo.CurrentCulture, transformer |
| | | 53 | | } |
| | | 54 | | } |
| | | 55 | | |