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

luttje / Key2Joy / 6603144428

22 Oct 2023 10:10AM UTC coverage: 43.896% (-0.2%) from 44.094%
6603144428

Pull #54

github

web-flow
Merge 6b56375be into 6b38fe9a4
Pull Request #54: Feature/rework override default

765 of 2403 branches covered (0.0%)

Branch coverage included in aggregate %.

97 of 97 new or added lines in 10 files covered. (100.0%)

3902 of 8229 relevant lines covered (47.42%)

20421.27 hits per line

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

34.09
/Core/Key2Joy.Contracts/Util/StringExtensions.cs
1
namespace Key2Joy.Contracts.Util;
2

3
public static class StringExtensions
4
{
5
    /// <summary>
6
    /// Ellipsizes the string to the specified length, adding ... at the end
7
    /// </summary>
8
    /// <param name="input"></param>
9
    /// <param name="maxLength"></param>
10
    /// <returns></returns>
11
    /// <exception cref="System.ArgumentOutOfRangeException"></exception>
12
    public static string Ellipsize(this string input, int maxLength)
13
    {
14
        if (input == null)
6!
15
        {
16
            return null;
×
17
        }
18

19
        if (input.Length <= maxLength)
6✔
20
        {
21
            return input;
3✔
22
        }
23

24
        if (maxLength < 0)
3✔
25
        {
26
            throw new System.ArgumentOutOfRangeException(nameof(maxLength));
1✔
27
        }
28

29
        if (maxLength <= 3)
2✔
30
        {
31
            return "...";
1✔
32
        }
33

34
        return input.Substring(0, maxLength - 3) + "...";
1✔
35
    }
36

37
    /// <summary>
38
    /// Places newlines in the string to make it fit the specified width
39
    /// </summary>
40
    /// <param name="input"></param>
41
    /// <param name="maxCharLength"></param>
42
    /// <returns></returns>
43
    public static string Wrap(this string input, int maxCharLength)
44
    {
45
        if (input == null)
×
46
        {
47
            return null;
×
48
        }
49

50
        if (maxCharLength <= 0)
×
51
        {
52
            throw new System.ArgumentOutOfRangeException(nameof(maxCharLength));
×
53
        }
54

55
        if (input.Length <= maxCharLength)
×
56
        {
57
            return input;
×
58
        }
59

60
        var sb = new System.Text.StringBuilder();
×
61
        var words = input.Split(' ');
×
62
        var lineLength = 0;
×
63
        foreach (var word in words)
×
64
        {
65
            if (lineLength + word.Length > maxCharLength)
×
66
            {
67
                sb.AppendLine();
×
68
                lineLength = 0;
×
69
            }
70

71
            sb.Append(word);
×
72
            sb.Append(' ');
×
73
            lineLength += word.Length + 1;
×
74
        }
75

76
        return sb.ToString().TrimEnd();
×
77
    }
78
}
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

© 2025 Coveralls, Inc