OSDN Git Service

na-get-lib,AppliStation-GUI,レポジトリリスト編集機能追加
[applistation/AppliStation.git] / na-get-lib / NaGet / Utils.cs
index 87b2736..59a61d7 100644 (file)
@@ -40,12 +40,16 @@ namespace NaGet
                        }\r
                }\r
                \r
+               #endregion\r
+               \r
+               #region リスト関連関数\r
+               \r
                /// <summary>\r
                /// イテレータを結合して、返す\r
                /// </summary>\r
                /// <param name="enus">元となる複数のイテレータ</param>\r
                /// <returns>結合されたイテレータ</returns>\r
-               public static IEnumerable<T> MeargeEnumerable<T>(params IEnumerable<T>[] enus)\r
+               public static IEnumerable<T> MergeEnumerable<T>(params IEnumerable<T>[] enus)\r
                {\r
                        foreach (IEnumerable<T> enu in enus) {\r
                                if (enu == null) continue;\r
@@ -61,7 +65,7 @@ namespace NaGet
                /// </summary>\r
                /// <param name="enus">元となる複数のイテレータ</param>\r
                /// <returns>結合されたイテレータ</returns>\r
-               public static IEnumerable<T> MeargeEnumerable<T>(params IEnumerator<T>[] enus)\r
+               public static IEnumerable<T> MergeEnumerable<T>(params IEnumerator<T>[] enus)\r
                {\r
                        foreach (IEnumerator<T> enu in enus) {\r
                                if (enu == null) continue;\r
@@ -107,8 +111,25 @@ namespace NaGet
                        }\r
                }\r
                \r
-               #endregion\r
+               /// <summary>\r
+               /// リストに対して指定した2つの要素の位置を入れ替える\r
+               /// </summary>\r
+               /// <param name="list">操作対象のリスト</param>\r
+               /// <param name="indexA">位置</param>\r
+               /// <param name="indexB">位置</param>\r
+               public static void ListSwap(System.Collections.IList list, int indexA, int indexB)\r
+               {\r
+                       if ((indexA < 0) || (list.Count <= indexA) || (indexB < 0) || (list.Count <= indexB)) {\r
+                               throw new IndexOutOfRangeException();\r
+                       } else if (indexA != indexB) {\r
+                               object temp = list[indexA];\r
+                               list[indexA] = list[indexB];\r
+                               list[indexB] = temp;\r
+                       }\r
+               }\r
                \r
+               #endregion\r
+                               \r
                #region ファイル情報関連ユーテイリティ関数\r
                \r
                /// <summary>\r
@@ -154,7 +175,7 @@ namespace NaGet
                /// <param name="url">対象のurl</param>\r
                public static string Url2filename(string url)\r
                {\r
-                       string filename = Path.GetFileName(UrlDecode(url, Encoding.UTF8));\r
+                       string filename = Path.GetFileName(System.Web.HttpUtility.UrlDecode(url, Encoding.UTF8));\r
                        \r
                        int pos;\r
                        if ((pos = filename.IndexOfAny(Path.GetInvalidFileNameChars())) >= 0) {\r
@@ -170,69 +191,6 @@ namespace NaGet
                }\r
                \r
                /// <summary>\r
-               /// URLのデコードを行う\r
-               /// </summary>\r
-               /// <param name="s">対象のurl文字列</param>\r
-               /// <param name="e">デコードの処理に使う文字コード</param>\r
-               public static string UrlDecode(string s, Encoding e)\r
-               {\r
-                       // mono の System.Net.HttpUtility より作成\r
-                       \r
-                       if (null == s)\r
-                               return null;\r
-\r
-                       if (s.IndexOf ('%') == -1 && s.IndexOf ('+') == -1)\r
-                               return s;\r
-\r
-                       if (e == null)\r
-                               e = Encoding.GetEncoding (28591);\r
-\r
-                       StringBuilder output = new StringBuilder ();\r
-                       long len = s.Length;\r
-                       NumberStyles hexa = NumberStyles.HexNumber;\r
-                       MemoryStream bytes = new MemoryStream ();\r
-\r
-                       for (int i = 0; i < len; i++) {\r
-                               if (s [i] == '%' && i + 2 < len) {\r
-                                       if (s [i + 1] == 'u' && i + 5 < len) {\r
-                                               if (bytes.Length > 0) {\r
-                                                       //output.Append (GetChars (bytes, e));\r
-                                                       output.Append(e.GetChars(bytes.GetBuffer(), 0, (int) bytes.Length));\r
-                                                       bytes.SetLength (0);\r
-                                               }\r
-                                               \r
-                                               output.Append ((char) int.Parse(s.Substring (i + 2, 4), hexa));\r
-                                               i += 5;\r
-                                       } else {\r
-                                               bytes.WriteByte ((byte) int.Parse(s.Substring (i + 1, 2), hexa));\r
-                                               i += 2;\r
-                                       }\r
-                                       continue;\r
-                               }\r
-\r
-                               if (bytes.Length > 0) {\r
-                                       //output.Append (GetChars (bytes, e));\r
-                                       output.Append(e.GetChars(bytes.GetBuffer(), 0, (int) bytes.Length));\r
-                                       bytes.SetLength (0);\r
-                               }\r
-\r
-                               if (s [i] == '+') {\r
-                                       output.Append (' ');\r
-                               } else {\r
-                                       output.Append (s [i]);\r
-                               }\r
-                       }\r
-\r
-                       if (bytes.Length > 0) {\r
-                               //output.Append (GetChars (bytes, e));\r
-                               output.Append(e.GetChars(bytes.GetBuffer(), 0, (int) bytes.Length));\r
-                       }\r
-\r
-                       bytes = null;\r
-                       return output.ToString ();\r
-               }\r
-    \r
-               /// <summary>\r
                /// 再帰的にファイルの属性を指定します。強制的にフォルダの再帰削除の前に読み込み専用属性を消すのに使います。\r
                /// </summary>\r
                /// <param name="path">設定するフォルダ</param>\r
@@ -544,6 +502,7 @@ namespace NaGet
                \r
                #endregion\r
 \r
+               #region イベント情報\r
                \r
                /// <summary>\r
                /// 任意データのイベント情報を表現するクラス\r
@@ -567,5 +526,7 @@ namespace NaGet
                                get { return data; }\r
                        }\r
                }\r
+\r
+               #endregion\r
        }\r
 }\r