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

loresoft / EntityFrameworkCore.Generator / 5698020083

29 Jul 2023 02:14AM UTC coverage: 45.814%. First build
5698020083

push

github

pwelter34
Merge branch 'master' of https://github.com/loresoft/EntityFrameworkCore.Generator

382 of 1007 branches covered (37.93%)

Branch coverage included in aggregate %.

3 of 3 new or added lines in 2 files covered. (100.0%)

1320 of 2708 relevant lines covered (48.74%)

33.13 hits per line

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

67.16
/src/EntityFrameworkCore.Generator.Core/Extensions/StringExtensions.cs
1
using System;
2
using System.Linq;
3
using System.Text;
4
using System.Text.RegularExpressions;
5

6
namespace EntityFrameworkCore.Generator.Extensions;
7

8
public static class StringExtensions
9
{
10

11
    private static readonly Regex _splitNameRegex = new Regex(@"[\W_]+");
1✔
12

13
    /// <summary>
14
    /// Indicates whether the specified String object is null or an empty string
15
    /// </summary>
16
    /// <param name="item">A String reference</param>
17
    /// <returns>
18
    ///     <c>true</c> if is null or empty; otherwise, <c>false</c>.
19
    /// </returns>
20
    public static bool IsNullOrEmpty(this string item)
21
    {
22
        return string.IsNullOrEmpty(item);
378✔
23
    }
24

25
    /// <summary>
26
    /// Indicates whether a specified string is null, empty, or consists only of white-space characters
27
    /// </summary>
28
    /// <param name="item">A String reference</param>
29
    /// <returns>
30
    ///      <c>true</c> if is null or empty; otherwise, <c>false</c>.
31
    /// </returns>
32
    public static bool IsNullOrWhiteSpace(this string item)
33
    {
34
        if (item == null)
1,276!
35
            return true;
×
36

37
        for (int i = 0; i < item.Length; i++)
2,552✔
38
            if (!char.IsWhiteSpace(item[i]))
1,275!
39
                return false;
1,275✔
40

41
        return true;
1✔
42
    }
43

44
    /// <summary>
45
    /// Determines whether the specified string is not <see cref="IsNullOrEmpty"/>.
46
    /// </summary>
47
    /// <param name="value">The value to check.</param>
48
    /// <returns>
49
    ///   <c>true</c> if the specified <paramref name="value"/> is not <see cref="IsNullOrEmpty"/>; otherwise, <c>false</c>.
50
    /// </returns>
51
    public static bool HasValue(this string value)
52
    {
53
        return !string.IsNullOrEmpty(value);
1,099✔
54
    }
55

56
    /// <summary>
57
    /// Does string contain both uppercase and lowercase characters?
58
    /// </summary>
59
    /// <param name="s">The value.</param>
60
    /// <returns>True if contain mixed case.</returns>
61
    public static bool IsMixedCase(this string s)
62
    {
63
        if (s.IsNullOrEmpty())
231!
64
            return false;
×
65

66
        var containsUpper = s.Any(Char.IsUpper);
231✔
67
        var containsLower = s.Any(Char.IsLower);
231✔
68

69
        return containsLower && containsUpper;
231✔
70
    }
71

72
    /// <summary>
73
    /// Converts a string to use camelCase.
74
    /// </summary>
75
    /// <param name="value">The value.</param>
76
    /// <returns>The to camel case. </returns>
77
    public static string ToCamelCase(this string value)
78
    {
79
        if (string.IsNullOrEmpty(value))
×
80
            return value;
×
81

82
        string output = ToPascalCase(value);
×
83
        if (output.Length > 2)
×
84
            return char.ToLower(output[0]) + output.Substring(1);
×
85

86
        return output.ToLower();
×
87
    }
88

89
    /// <summary>
90
    /// Converts a string to use PascalCase.
91
    /// </summary>
92
    /// <param name="value">Text to convert</param>
93
    /// <returns>The string</returns>
94
    public static string ToPascalCase(this string value)
95
    {
96
        return value.ToPascalCase(_splitNameRegex);
231✔
97
    }
98

99
    /// <summary>
100
    /// Converts a string to use PascalCase.
101
    /// </summary>
102
    /// <param name="value">Text to convert</param>
103
    /// <param name="splitRegex">Regular Expression to split words on.</param>
104
    /// <returns>The string</returns>
105
    public static string ToPascalCase(this string value, Regex splitRegex)
106
    {
107
        if (string.IsNullOrEmpty(value))
231!
108
            return value;
×
109

110
        var mixedCase = value.IsMixedCase();
231✔
111
        var names = splitRegex.Split(value);
231✔
112
        var output = new StringBuilder();
231✔
113

114
        if (names.Length > 1)
231✔
115
        {
116
            foreach (string name in names)
18✔
117
            {
118
                if (name.Length > 1)
6!
119
                {
120
                    output.Append(char.ToUpper(name[0]));
6✔
121
                    output.Append(mixedCase ? name.Substring(1) : name.Substring(1).ToLower());
6!
122
                }
123
                else
124
                {
125
                    output.Append(name.ToUpper());
×
126
                }
127
            }
128
        }
129
        else if (value.Length > 1)
228!
130
        {
131
            output.Append(char.ToUpper(value[0]));
228✔
132
            output.Append(mixedCase ? value.Substring(1) : value.Substring(1).ToLower());
228✔
133
        }
134
        else
135
        {
136
            output.Append(value.ToUpper());
×
137
        }
138

139
        return output.ToString();
231✔
140
    }
141

142

143
}
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