• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

loresoft / FluentCommand / 27284007534

10 Jun 2026 02:31PM UTC coverage: 65.051%. First build
27284007534

push

github

pwelter34
Capture and trim SQL Server PRINT/log messages

1737 of 3466 branches covered (50.12%)

Branch coverage included in aggregate %.

27 of 32 new or added lines in 3 files covered. (84.38%)

5535 of 7713 relevant lines covered (71.76%)

296.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.14
/src/FluentCommand/Extensions/StringExtensions.cs
1
using System.Buffers;
2
using System.Diagnostics.CodeAnalysis;
3

4
namespace FluentCommand.Extensions;
5

6
/// <summary>
7
/// <see cref="T:String"/> extension methods
8
/// </summary>
9
public static class StringExtensions
10
{
11
    /// <summary>
12
    /// Indicates whether the specified String object is null or an empty string
13
    /// </summary>
14
    /// <param name="item">A String reference</param>
15
    /// <returns>
16
    ///     <c>true</c> if is null or empty; otherwise, <c>false</c>.
17
    /// </returns>
18
    public static bool IsNullOrEmpty([NotNullWhen(false)] this string? item)
19
    {
20
        return string.IsNullOrEmpty(item);
13,117✔
21
    }
22

23
    /// <summary>
24
    /// Indicates whether a specified string is null, empty, or consists only of white-space characters
25
    /// </summary>
26
    /// <param name="item">A String reference</param>
27
    /// <returns>
28
    ///      <c>true</c> if is null or empty; otherwise, <c>false</c>.
29
    /// </returns>
30
    public static bool IsNullOrWhiteSpace([NotNullWhen(false)] this string? item)
31
    {
32
        return string.IsNullOrWhiteSpace(item);
2,598✔
33
    }
34

35
    /// <summary>
36
    /// Determines whether the specified string is not <see cref="IsNullOrEmpty"/>.
37
    /// </summary>
38
    /// <param name="value">The value to check.</param>
39
    /// <returns>
40
    ///   <c>true</c> if the specified <paramref name="value"/> is not <see cref="IsNullOrEmpty"/>; otherwise, <c>false</c>.
41
    /// </returns>
42
    public static bool HasValue([NotNullWhen(true)] this string? value)
43
    {
44
        return !string.IsNullOrEmpty(value);
2,253✔
45
    }
46

47
    /// <summary>
48
    /// Replaces the format item in a specified string with the string representation of a corresponding object in a specified array.
49
    /// </summary>
50
    /// <param name="format">A composite format string</param>
51
    /// <param name="args">An object array that contains zero or more objects to format</param>
52
    /// <returns>A copy of format in which the format items have been replaced by the string representation of the corresponding objects in args</returns>
53
    public static string FormatWith([StringSyntax("CompositeFormat")] this string format, params object?[] args)
54
    {
55
        return string.Format(format, args);
×
56
    }
57

58
    /// <summary>
59
    /// Truncates the specified string to a maximum length, optionally appending an ellipsis or custom suffix if truncation occurs.
60
    /// </summary>
61
    /// <param name="text">The string to truncate.</param>
62
    /// <param name="keep">The number of characters to keep (including the ellipsis, if used).</param>
63
    /// <param name="ellipsis">The string to append if truncation occurs. Defaults to "..." if not specified.</param>
64
    /// <returns>
65
    /// The truncated string with the ellipsis (or custom suffix) appended if truncation occurred; otherwise, the original string.
66
    /// Returns <c>null</c> if <paramref name="text"/> is <c>null</c>.
67
    /// </returns>
68
    [return: NotNullIfNotNull(nameof(text))]
69
    public static string? Truncate(this string? text, int keep, string? ellipsis = "...")
70
    {
71
        if (IsNullOrEmpty(text) || text.Length <= keep)
3!
72
            return text;
1✔
73

74
        ellipsis ??= string.Empty;
2!
75

76
        int ellipsisLength = ellipsis.Length;
2✔
77

78
        // If there's no room for ellipsis, just return truncated prefix
79
        if (keep <= ellipsisLength)
2!
NEW
80
            return text[..keep];
×
81

82
        int prefixLength = keep - ellipsisLength;
2✔
83

84
#if NETSTANDARD2_0
85
        return string.Concat(text[..prefixLength], ellipsis);
86
#else
87
        int totalLength = prefixLength + ellipsisLength;
2✔
88

89
        // Use stack allocation for short strings, or rent from the pool for longer ones
90
        char[]? rentedArray = null;
2✔
91
        Span<char> buffer = totalLength <= 256
2!
92
            ? stackalloc char[totalLength]
2✔
93
            : (rentedArray = ArrayPool<char>.Shared.Rent(totalLength));
2✔
94

95
        try
96
        {
97
            text.AsSpan(0, prefixLength).CopyTo(buffer);
2✔
98
            ellipsis.AsSpan().CopyTo(buffer[prefixLength..]);
2✔
99

100
            return new string(buffer[..totalLength]);
2✔
101
        }
102
        finally
103
        {
104
            // Return rented array to the pool to avoid memory leaks
105
            if (rentedArray != null)
2!
NEW
106
                ArrayPool<char>.Shared.Return(rentedArray);
×
107
        }
2✔
108
#endif
109
    }
2✔
110

111
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc