Skip to content

Commit

Permalink
Replaced own IsNullOrWhiteSpace with usage of string.IsNullOrWhiteSpace
Browse files Browse the repository at this point in the history
  • Loading branch information
mcavigelli committed May 24, 2019
1 parent 53ee16b commit ac93266
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 47 deletions.
12 changes: 1 addition & 11 deletions FileHelpers.Tests/Tests/Helpers/StringHelperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace FileHelpers.Tests
{
/// <summary>
/// FileHelpers Helpers StringHelper tests
/// FileHelpers Helpers StringHelper tests
/// </summary>
[TestFixture]
internal class StringHelperTest
Expand Down Expand Up @@ -35,16 +35,6 @@ public void RemoveTrailingBlanks()
Check.That(StringHelper.RemoveBlanks(" + 41")).IsEqualTo("+41");
}

[Test(Description = "String IsNullOrWhiteSpace help method tests")]
public void IsNullOrWhiteSpace()
{
Check.That(StringHelper.IsNullOrWhiteSpace(" ")).IsEqualTo(true);
Check.That(StringHelper.IsNullOrWhiteSpace(null)).IsEqualTo(true);
Check.That(StringHelper.IsNullOrWhiteSpace("")).IsEqualTo(true);
Check.That(StringHelper.IsNullOrWhiteSpace(" test ")).IsEqualTo(false);
Check.That(StringHelper.IsNullOrWhiteSpace("test")).IsEqualTo(false);
}

[Test(Description = "String StartsWithIgnoringWhiteSpaces help method tests")]
public void StartsWithIgnoringWhiteSpaces()
{
Expand Down
2 changes: 1 addition & 1 deletion FileHelpers/Core/RecordOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public bool StringToRecord(object record, LineInfo line, object[] values)
private bool MustIgnoreLine(string line)
{
if (mRecordInfo.IgnoreEmptyLines) {
if ((mRecordInfo.IgnoreEmptySpaces && StringHelper.IsNullOrWhiteSpace(line)) ||
if ((mRecordInfo.IgnoreEmptySpaces && string.IsNullOrWhiteSpace(line)) ||
line.Length == 0)
return true;
}
Expand Down
37 changes: 2 additions & 35 deletions FileHelpers/Helpers/StringHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ internal static CompareInfo CreateComparer()
/// <param name="oldValue">Value to replace</param>
/// <param name="newValue">value to replace with</param>
/// <returns>String with all multiple occurrences replaced</returns>
internal static string ReplaceRecursive(string original, string oldValue, string newValue)
private static string ReplaceRecursive(string original, string oldValue, string newValue)
{
const int maxTries = 1000;

Expand Down Expand Up @@ -244,19 +244,7 @@ internal static string ToValidIdentifier(string original)
/// <returns>string with values replaced</returns>
public static string ReplaceIgnoringCase(string original, string oldValue, string newValue)
{
return Replace(original, oldValue, newValue, StringComparison.OrdinalIgnoreCase);
}

/// <summary>
/// String replace with a comparison function, eg OridinalIgnoreCase
/// </summary>
/// <param name="original">Original string</param>
/// <param name="oldValue">Value to be replaced</param>
/// <param name="newValue">value to replace with</param>
/// <param name="comparisionType">Comparison type (enum)</param>
/// <returns>String with values replaced</returns>
public static string Replace(string original, string oldValue, string newValue, StringComparison comparisionType)
{
StringComparison comparisionType = StringComparison.OrdinalIgnoreCase;
string result = original;

if (!string.IsNullOrEmpty(oldValue))
Expand All @@ -281,27 +269,6 @@ public static string Replace(string original, string oldValue, string newValue,
return result;
}

/// <summary>
/// Indicates whether a specified string is null, empty, or consists only of white-space characters.
/// </summary>
/// <param name="value">The string to test.</param>
/// <returns>true if the parameter is null, empty, or consists only of white-space characters.</returns>
public static bool IsNullOrWhiteSpace(string value)
{
if (value == null)
{
return true;
}
for (int i = 0; i < value.Length; i++)
{
if (!char.IsWhiteSpace(value[i]))
{
return false;
}
}
return true;
}

/// <summary>
/// Determines whether the beginning of this string instance matches the specified string ignoring white spaces at the start.
/// </summary>
Expand Down

0 comments on commit ac93266

Please sign in to comment.