mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-15 20:54:58 +00:00
refactor: Removing unused methods
This commit is contained in:
@@ -51,24 +51,6 @@ namespace ICD.Common.Utils.Tests.Extensions
|
|||||||
Assert.AreEqual("0", split[3]);
|
Assert.AreEqual("0", split[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void SplitStringDelimiterTest()
|
|
||||||
{
|
|
||||||
string[] split = "1234567890".Split("23").ToArray();
|
|
||||||
|
|
||||||
Assert.AreEqual(2, split.Length);
|
|
||||||
Assert.AreEqual("14567890", string.Join("", split));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void SplitStringDelimitersTest()
|
|
||||||
{
|
|
||||||
string[] split = "1234567890".Split(new[] { "23", "67" }).ToArray();
|
|
||||||
|
|
||||||
Assert.AreEqual(3, split.Length);
|
|
||||||
Assert.AreEqual("145890", string.Join("", split));
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestCase("12345", " 12 3 4 \t 5\n")]
|
[TestCase("12345", " 12 3 4 \t 5\n")]
|
||||||
public void RemoveWhitespaceTest(string expected, string value)
|
public void RemoveWhitespaceTest(string expected, string value)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -134,97 +134,6 @@ namespace ICD.Common.Utils.Extensions
|
|||||||
.Select(i => extends.Substring(i * chunkSize, Math.Min(chunkSize, extends.Length - (i * chunkSize))));
|
.Select(i => extends.Substring(i * chunkSize, Math.Min(chunkSize, extends.Length - (i * chunkSize))));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Splits a string by a given substring.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="extends"></param>
|
|
||||||
/// <param name="delimeter"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[PublicAPI]
|
|
||||||
public static IEnumerable<string> Split(this string extends, string delimeter)
|
|
||||||
{
|
|
||||||
if (extends == null)
|
|
||||||
throw new ArgumentNullException("extends");
|
|
||||||
|
|
||||||
if (delimeter == null)
|
|
||||||
throw new ArgumentNullException("delimeter");
|
|
||||||
|
|
||||||
return SplitIterator(extends, delimeter);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Splits a string by a given substring.
|
|
||||||
/// Taken from
|
|
||||||
/// https://social.msdn.microsoft.com/Forums/en-US/914a350f-e0e9-45e0-91a4-6b4b2168e780/string-split-function
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="value"></param>
|
|
||||||
/// <param name="delimeter"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
private static IEnumerable<string> SplitIterator(string value, string delimeter)
|
|
||||||
{
|
|
||||||
int dSum = 0;
|
|
||||||
int sSum = 0;
|
|
||||||
int length = value.Length;
|
|
||||||
int delimiterLength = delimeter.Length;
|
|
||||||
|
|
||||||
if (delimiterLength == 0 || length == 0 || length < delimiterLength)
|
|
||||||
{
|
|
||||||
yield return value;
|
|
||||||
yield break;
|
|
||||||
}
|
|
||||||
|
|
||||||
char[] cd = delimeter.ToCharArray();
|
|
||||||
char[] cs = value.ToCharArray();
|
|
||||||
|
|
||||||
for (int i = 0; i < delimiterLength; i++)
|
|
||||||
{
|
|
||||||
dSum += cd[i];
|
|
||||||
sSum += cs[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
int start = 0;
|
|
||||||
for (int i = start; i < length - delimiterLength; i++)
|
|
||||||
{
|
|
||||||
if (i >= start && dSum == sSum && value.Substring(i, delimiterLength) == delimeter)
|
|
||||||
{
|
|
||||||
yield return value.Substring(start, i - start);
|
|
||||||
start = i + delimiterLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
sSum += cs[i + delimiterLength] - cs[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dSum == sSum && value.Substring(length - delimiterLength, delimiterLength) == delimeter)
|
|
||||||
{
|
|
||||||
yield return value.Substring(start, length - delimiterLength - start);
|
|
||||||
yield return string.Empty;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
yield return value.Substring(start, length - start);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Splits a string by the given substrings.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="extends"></param>
|
|
||||||
/// <param name="delimeters"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[PublicAPI]
|
|
||||||
public static IEnumerable<string> Split(this string extends, IEnumerable<string> delimeters)
|
|
||||||
{
|
|
||||||
if (extends == null)
|
|
||||||
throw new ArgumentNullException("extends");
|
|
||||||
|
|
||||||
if (delimeters == null)
|
|
||||||
throw new ArgumentNullException("delimeters");
|
|
||||||
|
|
||||||
string[] delimitersArray = delimeters as string[] ?? delimeters.ToArray();
|
|
||||||
return delimitersArray.Length == 0
|
|
||||||
? new[] {extends}
|
|
||||||
: extends.Split(delimitersArray.First())
|
|
||||||
.SelectMany(s => s.Split(delimitersArray.Skip(1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Removes whitespace from the string.
|
/// Removes whitespace from the string.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user