aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Model/Extensions
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Model/Extensions')
-rw-r--r--MediaBrowser.Model/Extensions/LinqExtensions.cs97
-rw-r--r--MediaBrowser.Model/Extensions/ListHelper.cs41
-rw-r--r--MediaBrowser.Model/Extensions/StringHelper.cs134
3 files changed, 0 insertions, 272 deletions
diff --git a/MediaBrowser.Model/Extensions/LinqExtensions.cs b/MediaBrowser.Model/Extensions/LinqExtensions.cs
deleted file mode 100644
index 09ace42e8..000000000
--- a/MediaBrowser.Model/Extensions/LinqExtensions.cs
+++ /dev/null
@@ -1,97 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace MediaBrowser.Model.Extensions
-{
- // MoreLINQ - Extensions to LINQ to Objects
- // Copyright (c) 2008 Jonathan Skeet. All rights reserved.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
-
- public static class LinqExtensions
- {
- /// <summary>
- /// Returns all distinct elements of the given source, where "distinctness"
- /// is determined via a projection and the default equality comparer for the projected type.
- /// </summary>
- /// <remarks>
- /// This operator uses deferred execution and streams the results, although
- /// a set of already-seen keys is retained. If a key is seen multiple times,
- /// only the first element with that key is returned.
- /// </remarks>
- /// <typeparam name="TSource">Type of the source sequence</typeparam>
- /// <typeparam name="TKey">Type of the projected element</typeparam>
- /// <param name="source">Source sequence</param>
- /// <param name="keySelector">Projection for determining "distinctness"</param>
- /// <returns>A sequence consisting of distinct elements from the source sequence,
- /// comparing them by the specified key projection.</returns>
-
- public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source,
- Func<TSource, TKey> keySelector)
- {
- return source.DistinctBy(keySelector, null);
- }
-
- public static TSource[] ToArray<TSource>(this IEnumerable<TSource> source, int count)
- {
- if (source == null) throw new ArgumentNullException("source");
- if (count < 0) throw new ArgumentOutOfRangeException("count");
- var array = new TSource[count];
- int i = 0;
- foreach (var item in source)
- {
- array[i++] = item;
- }
- return array;
- }
-
- /// <summary>
- /// Returns all distinct elements of the given source, where "distinctness"
- /// is determined via a projection and the specified comparer for the projected type.
- /// </summary>
- /// <remarks>
- /// This operator uses deferred execution and streams the results, although
- /// a set of already-seen keys is retained. If a key is seen multiple times,
- /// only the first element with that key is returned.
- /// </remarks>
- /// <typeparam name="TSource">Type of the source sequence</typeparam>
- /// <typeparam name="TKey">Type of the projected element</typeparam>
- /// <param name="source">Source sequence</param>
- /// <param name="keySelector">Projection for determining "distinctness"</param>
- /// <param name="comparer">The equality comparer to use to determine whether or not keys are equal.
- /// If null, the default equality comparer for <c>TSource</c> is used.</param>
- /// <returns>A sequence consisting of distinct elements from the source sequence,
- /// comparing them by the specified key projection.</returns>
-
- public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source,
- Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
- {
- if (source == null) throw new ArgumentNullException("source");
- if (keySelector == null) throw new ArgumentNullException("keySelector");
- return DistinctByImpl(source, keySelector, comparer);
- }
-
- private static IEnumerable<TSource> DistinctByImpl<TSource, TKey>(IEnumerable<TSource> source,
- Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
- {
- var knownKeys = new HashSet<TKey>(comparer);
- foreach (var element in source)
- {
- if (knownKeys.Add(keySelector(element)))
- {
- yield return element;
- }
- }
- }
- }
-}
diff --git a/MediaBrowser.Model/Extensions/ListHelper.cs b/MediaBrowser.Model/Extensions/ListHelper.cs
deleted file mode 100644
index 6fe1793db..000000000
--- a/MediaBrowser.Model/Extensions/ListHelper.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-using System;
-
-namespace MediaBrowser.Model.Extensions
-{
- public static class ListHelper
- {
- public static bool ContainsIgnoreCase(string[] list, string value)
- {
- if (value == null)
- {
- throw new ArgumentNullException("value");
- }
-
- foreach (var item in list)
- {
- if (string.Equals(item, value, StringComparison.OrdinalIgnoreCase))
- {
- return true;
- }
- }
- return false;
- }
-
- public static bool ContainsAnyIgnoreCase(string[] list, string[] values)
- {
- if (values == null)
- {
- throw new ArgumentNullException("values");
- }
-
- foreach (string val in values)
- {
- if (ContainsIgnoreCase(list, val))
- {
- return true;
- }
- }
- return false;
- }
- }
-}
diff --git a/MediaBrowser.Model/Extensions/StringHelper.cs b/MediaBrowser.Model/Extensions/StringHelper.cs
deleted file mode 100644
index 9cde3bfa4..000000000
--- a/MediaBrowser.Model/Extensions/StringHelper.cs
+++ /dev/null
@@ -1,134 +0,0 @@
-using System;
-using System.Globalization;
-using System.Text;
-using System.Text.RegularExpressions;
-
-namespace MediaBrowser.Model.Extensions
-{
- /// <summary>
- /// Isolating these helpers allow this entire project to be easily converted to Java
- /// </summary>
- public static class StringHelper
- {
- /// <summary>
- /// Equalses the ignore case.
- /// </summary>
- /// <param name="str1">The STR1.</param>
- /// <param name="str2">The STR2.</param>
- /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
- public static bool EqualsIgnoreCase(string str1, string str2)
- {
- return string.Equals(str1, str2, StringComparison.OrdinalIgnoreCase);
- }
-
- /// <summary>
- /// Indexes the of ignore case.
- /// </summary>
- /// <param name="str">The string.</param>
- /// <param name="value">The value.</param>
- /// <returns>System.Int32.</returns>
- public static int IndexOfIgnoreCase(string str, string value)
- {
- return str.IndexOf(value, StringComparison.OrdinalIgnoreCase);
- }
-
- /// <summary>
- /// To the string culture invariant.
- /// </summary>
- /// <param name="val">The value.</param>
- /// <returns>System.String.</returns>
- public static string ToStringCultureInvariant(int val)
- {
- return val.ToString(CultureInfo.InvariantCulture);
- }
-
- /// <summary>
- /// To the string culture invariant.
- /// </summary>
- /// <param name="val">The value.</param>
- /// <returns>System.String.</returns>
- public static string ToStringCultureInvariant(long val)
- {
- return val.ToString(CultureInfo.InvariantCulture);
- }
-
- /// <summary>
- /// To the string culture invariant.
- /// </summary>
- /// <param name="val">The value.</param>
- /// <returns>System.String.</returns>
- public static string ToStringCultureInvariant(double val)
- {
- return val.ToString(CultureInfo.InvariantCulture);
- }
-
- /// <summary>
- /// Trims the start.
- /// </summary>
- /// <param name="str">The string.</param>
- /// <param name="c">The c.</param>
- /// <returns>System.String.</returns>
- public static string TrimStart(string str, char c)
- {
- return str.TrimStart(c);
- }
-
- /// <summary>
- /// Splits the specified string.
- /// </summary>
- /// <param name="str">The string.</param>
- /// <param name="term">The term.</param>
- /// <returns>System.String[].</returns>
- public static string[] RegexSplit(string str, string term)
- {
- return Regex.Split(str, term, RegexOptions.IgnoreCase);
- }
-
- /// <summary>
- /// Splits the specified string.
- /// </summary>
- /// <param name="str">The string.</param>
- /// <param name="term">The term.</param>
- /// <param name="limit">The limit.</param>
- /// <returns>System.String[].</returns>
- public static string[] RegexSplit(string str, string term, int limit)
- {
- return new Regex(term).Split(str, limit);
- }
-
- /// <summary>
- /// Replaces the specified STR.
- /// </summary>
- /// <param name="str">The STR.</param>
- /// <param name="oldValue">The old value.</param>
- /// <param name="newValue">The new value.</param>
- /// <param name="comparison">The comparison.</param>
- /// <returns>System.String.</returns>
- public static string Replace(this string str, string oldValue, string newValue, StringComparison comparison)
- {
- var sb = new StringBuilder();
-
- var previousIndex = 0;
- var index = str.IndexOf(oldValue, comparison);
-
- while (index != -1)
- {
- sb.Append(str.Substring(previousIndex, index - previousIndex));
- sb.Append(newValue);
- index += oldValue.Length;
-
- previousIndex = index;
- index = str.IndexOf(oldValue, index, comparison);
- }
-
- sb.Append(str.Substring(previousIndex));
-
- return sb.ToString();
- }
-
- public static string FirstToUpper(this string str)
- {
- return string.IsNullOrEmpty(str) ? "" : str.Substring(0, 1).ToUpper() + str.Substring(1);
- }
- }
-}