| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="TextSanitizationExtensions.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 MyNet.Primitives; |
| | | 10 | | using MyNet.Text.Sanitization; |
| | | 11 | | |
| | | 12 | | #pragma warning disable IDE0130 // Namespace does not match folder structure |
| | | 13 | | namespace MyNet.Text; |
| | | 14 | | #pragma warning restore IDE0130 // Namespace does not match folder structure |
| | | 15 | | |
| | | 16 | | public static class TextSanitizationExtensions |
| | | 17 | | { |
| | | 18 | | extension(TextPipeline pipeline) |
| | | 19 | | { |
| | | 20 | | /// <summary> |
| | | 21 | | /// Applies a sanitization transform to the pipeline. |
| | | 22 | | /// </summary> |
| | | 23 | | public TextPipeline Sanitize(ITextSanitizerTransform transform) |
| | | 24 | | { |
| | 0 | 25 | | ArgumentNullException.ThrowIfNull(transform); |
| | 0 | 26 | | return pipeline.Apply(transform); |
| | | 27 | | } |
| | | 28 | | } |
| | | 29 | | |
| | | 30 | | extension(string input) |
| | | 31 | | { |
| | | 32 | | /// <summary> |
| | | 33 | | /// Applies a sanitization transform. |
| | | 34 | | /// </summary> |
| | | 35 | | public string Sanitize(ITextSanitizerTransform transform, CultureInfo? culture = null) |
| | | 36 | | { |
| | 15 | 37 | | ArgumentNullException.ThrowIfNull(transform); |
| | 15 | 38 | | return transform.Apply(input, culture.OrCurrent()); |
| | | 39 | | } |
| | | 40 | | |
| | | 41 | | /// <summary> |
| | | 42 | | /// Sanitizes text so it can be used as a file name. |
| | | 43 | | /// </summary> |
| | | 44 | | public string SanitizeFileName(CultureInfo? culture = null) |
| | 3 | 45 | | => input.Sanitize(Sanitizer.FileName, culture); |
| | | 46 | | } |
| | | 47 | | } |
| | | 48 | | |