< Summary

Information
Class: MyNet.Text.Truncation.FixedLengthTextTruncator
Assembly: MyNet.Text
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Text/Truncation/FixedLengthTextTruncator.cs
Tag: 323_28699572109
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 38
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
ApplyCore(...)100%1010100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Text/Truncation/FixedLengthTextTruncator.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="FixedLengthTextTruncator.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System.Globalization;
 8
 9namespace MyNet.Text.Truncation;
 10
 11/// <summary>
 12/// Truncates a string to a fixed length, optionally adding a truncation string (e.g. ellipsis) at the truncation point.
 13/// </summary>
 14/// <param name="options">The options to use for truncating text.</param>
 12015public sealed class FixedLengthTextTruncator(TextTruncationOptions options) : TextTruncatorBase(options)
 16{
 17    /// <inheritdoc/>
 18    protected override string ApplyCore(string input, CultureInfo culture)
 19    {
 11720        if (string.IsNullOrEmpty(input) || input.Length <= Options.Length)
 7221            return input;
 22
 4523        if (Options.TruncationString.Length >= Options.Length)
 24        {
 925            return Options.Direction == TruncateFrom.Right ? input[..Options.Length] : input[^Options.Length..];
 26        }
 27
 3628        var contentLength = Options.Length - Options.TruncationString.Length;
 29
 3630        return Options.Direction switch
 3631        {
 1232            TruncateFrom.Left => TruncateLeft(input, input.Length - contentLength),
 3633
 2434            _ => TruncateRight(input, contentLength)
 3635        };
 36    }
 37}
 38