< Summary

Information
Class: MyNet.Text.TextRedactionExtensions
Assembly: MyNet.Text
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Text/Extensions/TextRedactionExtensions.cs
Tag: 323_28699572109
Line coverage
83%
Covered lines: 10
Uncovered lines: 2
Coverable lines: 12
Total lines: 60
Line coverage: 83.3%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Redact(...)100%210%
Redact(...)100%11100%
Redact(...)100%11100%
Redact(...)100%11100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Text/Extensions/TextRedactionExtensions.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="TextRedactionExtensions.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Globalization;
 9using System.Text.RegularExpressions;
 10using MyNet.Primitives;
 11using MyNet.Text.Redaction;
 12
 13#pragma warning disable IDE0130 // Namespace does not match folder structure
 14namespace MyNet.Text;
 15#pragma warning restore IDE0130 // Namespace does not match folder structure
 16
 17public static class TextRedactionExtensions
 18{
 19    extension(TextPipeline pipeline)
 20    {
 21        /// <summary>
 22        /// Applies a redaction transform to the pipeline.
 23        /// </summary>
 24        public TextPipeline Redact(ITextRedactorTransform transform)
 25        {
 026            ArgumentNullException.ThrowIfNull(transform);
 027            return pipeline.Apply(transform);
 28        }
 29    }
 30
 31    extension(string input)
 32    {
 33        /// <summary>
 34        /// Applies a redaction transform.
 35        /// </summary>
 36        public string Redact(ITextRedactorTransform transform, CultureInfo? culture = null)
 37        {
 1538            ArgumentNullException.ThrowIfNull(transform);
 1539            return transform.Apply(input, culture.OrCurrent());
 40        }
 41
 42        /// <summary>
 43        /// Redacts the middle part of the text and keeps edge characters visible.
 44        /// </summary>
 45        public string Redact(int showStart, int showEnd, char maskCharacter = '*', CultureInfo? culture = null)
 346            => input.Redact(new FixedMaskTextRedactor(new()
 347                {
 348                    ShowStart = showStart,
 349                    ShowEnd = showEnd,
 350                    MaskCharacter = maskCharacter
 351                }),
 352                culture);
 53
 54        /// <summary>
 55        /// Redacts parts matching a regular expression.
 56        /// </summary>
 357        public string Redact(Regex pattern, string replacement = "***", CultureInfo? culture = null) => input.Redact(new
 58    }
 59}
 60