OSDN Git Service

#27617 Wiktionaryに対応・設定の切り替え/追加機能を追加
[wptscs/wpts.git] / HmLib / Utilities / CollectionUtils.cs
1 // ================================================================================================
2 // <summary>
3 //      コレクション/配列処理に関するユーティリティクラスソース。</summary>
4 //
5 // <copyright file="CollectionUtils.cs" company="honeplusのメモ帳">
6 //      Copyright (C) 2012 Honeplus. All rights reserved.</copyright>
7 // <author>
8 //      Honeplus</author>
9 // ================================================================================================
10
11 namespace Honememo.Utilities
12 {
13     using System;
14     using System.Collections.Generic;
15
16     /// <summary>
17     /// コレクション/配列処理に関するユーティリティクラスです。
18     /// </summary>
19     public static class CollectionUtils
20     {
21         #region 比較メソッド
22
23         /// <summary>
24         /// 指定された文字列が渡されたコレクション内に存在するかを大文字小文字を無視して判定する。
25         /// </summary>
26         /// <param name="collection">探索するコレクション。</param>
27         /// <param name="item">含まれるか判定する文字列。</param>
28         /// <returns>指定された文字列が含まれる場合<c>true</c>。</returns>
29         /// <exception cref="ArgumentNullException"><para>collection</para>が<c>null</c>の場合。</exception>
30         public static bool ContainsIgnoreCase(IEnumerable<string> collection, string item)
31         {
32             foreach (string s in Validate.NotNull(collection))
33             {
34                 if (s == item || (s != null && item != null && s.ToLower() == item.ToLower()))
35                 {
36                     return true;
37                 }
38             }
39
40             return false;
41         }
42
43         #endregion
44
45         #region 加工メソッド
46
47         /// <summary>
48         /// 渡された文字列配列の中の要素を全て<see cref="String.Trim()"/>した配列を返す。
49         /// </summary>
50         /// <param name="array"><c>Trim</c>する文字列配列。</param>
51         /// <returns><c>Trim</c>された文字列配列。</returns>
52         /// <exception cref="ArgumentNullException"><para>array</para>が<c>null</c>の場合。</exception>
53         /// <remarks><para>array</para>中に<c>null</c>要素が存在するのは可。</remarks>
54         public static string[] Trim(string[] array)
55         {
56             string[] result = new string[Validate.NotNull(array).Length];
57             for (int i = 0; i < array.Length; i++)
58             {
59                 string s = array[i];
60                 if (s != null)
61                 {
62                     result[i] = s.Trim();
63                 }
64             }
65
66             return result;
67         }
68
69         #endregion
70     }
71 }