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

JaCraig / BigBookOfDataTypes / 12918214872

22 Jan 2025 10:25PM UTC coverage: 48.059%. Remained the same
12918214872

push

github

JaCraig
fix: Small update to StringBuilder extensions

1441 of 3326 branches covered (43.33%)

Branch coverage included in aggregate %.

3 of 3 new or added lines in 1 file covered. (100.0%)

1 existing line in 1 file now uncovered.

2322 of 4504 relevant lines covered (51.55%)

153.06 hits per line

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

93.06
/BigBook/ExtensionMethods/StringBuilderExtensions.cs
1
using System;
2
using System.ComponentModel;
3
using System.Globalization;
4
using System.Linq;
5
using System.Text;
6

7
namespace BigBook
8
{
9
    /// <summary>
10
    /// String builder extensions
11
    /// </summary>
12
    [EditorBrowsable(EditorBrowsableState.Never)]
13
    public static class StringBuilderExtensions
14
    {
15
        /// <summary>
16
        /// Does an AppendFormat and then an AppendLine on the StringBuilder
17
        /// </summary>
18
        /// <param name="builder">Builder object</param>
19
        /// <param name="provider">Format provider (CultureInfo) to use</param>
20
        /// <param name="format">Format string</param>
21
        /// <param name="objects">Objects to format</param>
22
        /// <returns>The StringBuilder passed in</returns>
23
        public static StringBuilder AppendLineFormat(this StringBuilder builder, IFormatProvider provider, string format, params object[] objects)
24
        {
25
            builder ??= new StringBuilder();
7!
26
            if (string.IsNullOrEmpty(format))
7!
UNCOV
27
                return builder;
×
28

29
            objects ??= [];
7!
30
            provider ??= CultureInfo.InvariantCulture;
7!
31
            return builder.AppendFormat(provider, format, objects).AppendLine();
7✔
32
        }
33

34
        /// <summary>
35
        /// Does an AppendFormat and then an AppendLine on the StringBuilder
36
        /// </summary>
37
        /// <param name="builder">Builder object</param>
38
        /// <param name="format">Format string</param>
39
        /// <param name="objects">Objects to format</param>
40
        /// <returns>The StringBuilder passed in</returns>
41
        public static StringBuilder AppendLineFormat(this StringBuilder builder, string format, params object[] objects) => builder.AppendLineFormat(CultureInfo.InvariantCulture, format, objects);
7✔
42

43
        /// <summary>
44
        /// Trims the specified string.
45
        /// </summary>
46
        /// <param name="builder">The builder.</param>
47
        /// <param name="trimCharacters">The characters to trim.</param>
48
        /// <returns>The string minus the characters specified.</returns>
49
        public static StringBuilder? Trim(this StringBuilder? builder, params char[] trimCharacters)
50
        {
51
            if (builder is null)
6✔
52
                return builder;
1✔
53
            if (trimCharacters is null || trimCharacters.Length == 0)
5✔
54
                trimCharacters = new char[] { ' ', '\t', '\n' };
5✔
55
            return builder.TrimStart(trimCharacters).TrimEnd(trimCharacters);
5✔
56
        }
57

58
        /// <summary>
59
        /// Trims the end of the string.
60
        /// </summary>
61
        /// <param name="builder">The builder.</param>
62
        /// <param name="trimCharacters">The characters to trim.</param>
63
        /// <returns>The string builder minus the characters specified.</returns>
64
        public static StringBuilder? TrimEnd(this StringBuilder? builder, params char[] trimCharacters)
65
        {
66
            if (builder is null)
9✔
67
                return builder;
1✔
68
            if (trimCharacters is null || trimCharacters.Length == 0)
8✔
69
                trimCharacters = new char[] { ' ', '\t', '\n' };
3✔
70
            var x = builder.Length;
8✔
71
            for (; x > 0; --x)
20✔
72
            {
73
                if (!trimCharacters.Any(y => builder[x - 1] == y))
36✔
74
                    break;
75
            }
76
            if (x == builder.Length)
8✔
77
                return builder;
5✔
78
            _ = builder.Remove(x, builder.Length - x);
3✔
79
            return builder;
3✔
80
        }
81

82
        /// <summary>
83
        /// Trims the start of the string.
84
        /// </summary>
85
        /// <param name="builder">The builder.</param>
86
        /// <param name="trimCharacters">The characters to trim.</param>
87
        /// <returns>The builder with the values trimmed.</returns>
88
        public static StringBuilder? TrimStart(this StringBuilder? builder, params char[] trimCharacters)
89
        {
90
            if (builder is null)
9✔
91
                return builder;
1✔
92
            if (trimCharacters is null || trimCharacters.Length == 0)
8✔
93
                trimCharacters = new char[] { ' ', '\t', '\n' };
3✔
94
            var x = 0;
8✔
95
            for (; x < builder.Length; ++x)
20✔
96
            {
97
                if (!trimCharacters.Any(y => builder[x] == y))
36✔
98
                    break;
99
            }
100
            if (x == 0)
8✔
101
                return builder;
5✔
102
            _ = builder.Remove(0, x);
3✔
103
            return builder;
3✔
104
        }
105
    }
106
}
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