< Summary

Information
Class: MyNet.Text.TextCasing.SentenceCasingTransform
Assembly: MyNet.Text
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Text/TextCasing/SentenceCasingTransform.cs
Tag: 323_28699572109
Line coverage
100%
Covered lines: 10
Uncovered lines: 0
Coverable lines: 10
Total lines: 42
Line coverage: 100%
Branch coverage
50%
Covered branches: 2
Total branches: 4
Branch coverage: 50%
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(...)50%44100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Text/TextCasing/SentenceCasingTransform.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="SentenceCasingTransform.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Globalization;
 9
 10namespace MyNet.Text.TextCasing;
 11
 12/// <summary>
 13/// Transforms a string to sentence case, meaning the first letter is capitalized and the rest are unchanged.
 14/// </summary>
 15public sealed class SentenceCasingTransform : ITextCasingTransform
 16{
 17    /// <summary>
 18    /// Initializes a new instance of the <see cref="SentenceCasingTransform"/> class.
 19    /// </summary>
 620    internal SentenceCasingTransform() { }
 21
 22    /// <summary>
 23    /// Transforms the input to sentence case.
 24    /// </summary>
 25    /// <param name="input">The string to transform.</param>
 26    /// <param name="culture">The culture to use for the transformation.</param>
 27    /// <returns>The transformed string in sentence case.</returns>
 28    public string Apply(string input, CultureInfo culture)
 29    {
 1830        ArgumentNullException.ThrowIfNull(input);
 1831        ArgumentNullException.ThrowIfNull(culture);
 32
 1833        return string.IsNullOrEmpty(input)
 1834            ? input
 1835            : input.Length == 1
 1836            ? input.ToUpper(culture)
 1837            : string.Concat(
 1838            culture.TextInfo.ToUpper(input[..1]),
 1839            input[1..]);
 40    }
 41}
 42