updated StringEx to 0.2, in favor of s.NonWhiteSpaceLines()

This commit is contained in:
Licshee
2016-02-06 15:03:52 +08:00
parent 732866c095
commit a8ffc60d31
5 changed files with 47 additions and 10 deletions
+41
View File
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
@@ -26,6 +27,17 @@ static partial class StringEx
public static bool IsNullOrWhiteSpace(this string value)
=> string.IsNullOrWhiteSpace(value);
public static bool IsWhiteSpace(this string value)
{
foreach(var c in value)
{
if (char.IsWhiteSpace(c)) continue;
return false;
}
return true;
}
#if !PCL
public static string IsInterned(this string value)
{
@@ -135,6 +147,35 @@ static partial class StringEx
#endregion
#region ToLines
public static IEnumerable<string> ToLines(this TextReader reader)
{
string line;
while ((line = reader.ReadLine()) != null)
yield return line;
}
public static IEnumerable<string> NonEmptyLines(this TextReader reader)
{
string line;
while ((line = reader.ReadLine()) != null)
{
if (line == "") continue;
yield return line;
}
}
public static IEnumerable<string> NonWhiteSpaceLines(this TextReader reader)
{
string line;
while ((line = reader.ReadLine()) != null)
{
if (line.IsWhiteSpace()) continue;
yield return line;
}
}
#endregion
#region others
private static readonly char[][] Quotes = new[]