< Summary

Information
Class: MyNet.Text.Formatting.InitialsFormatterTransform
Assembly: MyNet.Text
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Text/Formatting/InitialsFormatterTransform.cs
Tag: 323_28699572109
Line coverage
93%
Covered lines: 14
Uncovered lines: 1
Coverable lines: 15
Total lines: 53
Line coverage: 93.3%
Branch coverage
87%
Covered branches: 7
Total branches: 8
Branch coverage: 87.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
Apply(...)87.5%8892.85%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Text/Formatting/InitialsFormatterTransform.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="InitialsFormatterTransform.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;
 10
 11namespace MyNet.Text.Formatting;
 12
 13/// <summary>
 14/// Builds initials by taking the first character of each whitespace-delimited token.
 15/// </summary>
 16public sealed class InitialsFormatterTransform : ITextFormatterTransform
 17{
 18    /// <summary>
 19    /// Initializes a new instance of the <see cref="InitialsFormatterTransform"/> class.
 20    /// </summary>
 321    internal InitialsFormatterTransform() { }
 22
 23    /// <inheritdoc/>
 24    public string Apply(string input, CultureInfo culture)
 25    {
 926        ArgumentNullException.ThrowIfNull(input);
 927        ArgumentNullException.ThrowIfNull(culture);
 28
 929        if (input.Length == 0)
 030            return input;
 31
 932        var builder = new StringBuilder();
 933        var insideToken = false;
 34
 30035        foreach (var c in input)
 36        {
 14137            if (char.IsWhiteSpace(c))
 38            {
 1239                insideToken = false;
 1240                continue;
 41            }
 42
 12943            if (insideToken)
 44                continue;
 45
 2146            builder.Append(char.ToUpper(c, culture));
 2147            insideToken = true;
 48        }
 49
 950        return builder.ToString();
 51    }
 52}
 53