< Summary

Information
Class: MyNet.Text.TextCasing.SnakeCasingTransform
Assembly: MyNet.Text
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Text/TextCasing/SnakeCasingTransform.cs
Tag: 323_28699572109
Line coverage
100%
Covered lines: 6
Uncovered lines: 0
Coverable lines: 6
Total lines: 43
Line coverage: 100%
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
.ctor()100%11100%
Apply(...)100%11100%

File(s)

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

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="SnakeCasingTransform.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;
 10
 11namespace MyNet.Text.TextCasing;
 12
 13/// <summary>
 14/// Transforms a string to snake_case.
 15/// </summary>
 16public sealed partial class SnakeCasingTransform : ITextCasingTransform
 17{
 18    /// <summary>
 19    /// Initializes a new instance of the <see cref="SnakeCasingTransform"/> class.
 20    /// </summary>
 3621    internal SnakeCasingTransform() { }
 22
 23    /// <inheritdoc/>
 24    public string Apply(string input, CultureInfo culture)
 25    {
 4526        ArgumentNullException.ThrowIfNull(input);
 4527        ArgumentNullException.ThrowIfNull(culture);
 28
 4529        return NormalizeSeparatorsRegex()
 4530            .Replace(UpperLowerBoundaryRegex().Replace(AcronymBoundaryRegex().Replace(input, "$1_$2"), "$1_$2"), "_")
 4531            .ToLower(culture);
 32    }
 33
 34    [GeneratedRegex("[-\\s]")]
 35    private static partial Regex NormalizeSeparatorsRegex();
 36
 37    [GeneratedRegex(@"([\p{Ll}\d])([\p{Lu}])")]
 38    private static partial Regex UpperLowerBoundaryRegex();
 39
 40    [GeneratedRegex(@"([\p{Lu}]+)([\p{Lu}][\p{Ll}])")]
 41    private static partial Regex AcronymBoundaryRegex();
 42}
 43