OSDN Git Service

varを使用する (IDE0007)
[opentween/open-tween.git] / OpenTween / MyCommon.cs
index caca10a..32eda4c 100644 (file)
@@ -104,7 +104,6 @@ namespace OpenTween
         {
             TinyUrl,
             Isgd,
-            Twurl,
             Bitly,
             Jmp,
             Uxnu,
@@ -112,6 +111,7 @@ namespace OpenTween
             Nicoms,
             //廃止
             Unu = -1,
+            Twurl = -1,
         }
 
         public enum HITRESULT
@@ -299,7 +299,7 @@ namespace OpenTween
 
         public static string ExceptionOutMessage(Exception ex)
         {
-            bool IsTerminatePermission = true;
+            var IsTerminatePermission = true;
             return ExceptionOutMessage(ex, ref IsTerminatePermission);
         }
 
@@ -453,75 +453,6 @@ namespace OpenTween
         }
 
         /// <summary>
-        /// URLに含まれているマルチバイト文字列を%xx形式でエンコードします。
-        /// <newpara>
-        /// マルチバイト文字のコードはUTF-8またはUnicodeで自動的に判断します。
-        /// </newpara>
-        /// </summary>
-        /// <param name="_input">エンコード対象のURL</param>
-        /// <returns>マルチバイト文字の部分をUTF-8/%xx形式でエンコードした文字列を返します。</returns>
-
-        public static string urlEncodeMultibyteChar(string _input)
-        {
-            Uri uri = null;
-            var sb = new StringBuilder(256);
-            var result = "";
-            var c_ = 'd';
-            foreach (var c in _input)
-            {
-                c_ = c;
-                if (Convert.ToInt32(c) > 127 || c == '%') break;
-            }
-            if (Convert.ToInt32(c_) <= 127 && c_ != '%') return _input;
-
-            var input = Uri.UnescapeDataString(_input);
-        retry:
-            foreach (char c in input)
-            {
-                if (Convert.ToInt32(c) > 255)
-                {
-                    // Unicodeの場合(1charが複数のバイトで構成されている)
-                    // Uriクラスをnewして再構成し、入力をPathAndQueryのみとしてやり直す
-                    foreach (var b in Encoding.UTF8.GetBytes(c.ToString()))
-                    {
-                        sb.AppendFormat("%{0:X2}", b);
-                    }
-                }
-                else if (Convert.ToInt32(c) > 127 || c == '%')
-                {
-                    // UTF-8の場合
-                    // Uriクラスをnewして再構成し、入力をinputからAuthority部分を除去してやり直す
-                    if (uri == null)
-                    {
-                        uri = new Uri(input);
-                        input = input.Remove(0, uri.GetLeftPart(UriPartial.Authority).Length);
-                        sb.Length = 0;
-                        goto retry;
-                    }
-                    else
-                    {
-                        sb.Append("%" + Convert.ToInt16(c).ToString("X2").ToUpperInvariant());
-                    }
-                }
-                else
-                {
-                    sb.Append(c);
-                }
-            }
-
-            if (uri == null)
-            {
-                result = sb.ToString();
-            }
-            else
-            {
-                result = uri.GetLeftPart(UriPartial.Authority) + sb;
-            }
-
-            return result;
-        }
-
-        /// <summary>
         /// URLのドメイン名をPunycode展開します。
         /// <para>
         /// ドメイン名がIDNでない場合はそのまま返します。
@@ -563,7 +494,7 @@ namespace OpenTween
             }
             catch (Exception)
             {
-                return null;
+                return inputUrl;
             }
         }
 
@@ -578,8 +509,6 @@ namespace OpenTween
 
                 // Punycodeをデコードする
                 outputUrl = MyCommon.IDNDecode(outputUrl);
-                if (outputUrl == null)
-                    return inputUrl;
 
                 // URL内で特殊な意味を持つ記号は元の文字に変換されることを避けるために二重エスケープする
                 // 参考: Firefoxの losslessDecodeURI() 関数
@@ -645,10 +574,10 @@ namespace OpenTween
                     desdecrypt = des.CreateEncryptor();
 
                     //書き込むためのCryptoStreamの作成
-                    using (CryptoStream cryptStream = new CryptoStream(msOut, desdecrypt, CryptoStreamMode.Write))
+                    using (var cryptStream = new CryptoStream(msOut, desdecrypt, CryptoStreamMode.Write))
                     {
                         //Disposeが重複して呼ばれないようにする
-                        MemoryStream msTmp = msOut;
+                        var msTmp = msOut;
                         msOut = null;
                         desdecrypt = null;
 
@@ -705,7 +634,7 @@ namespace OpenTween
                     desdecrypt = null;
 
                     //復号化されたデータを取得するためのStreamReader
-                    using (StreamReader srOut = new StreamReader(cryptStreem, Encoding.UTF8))
+                    using (var srOut = new StreamReader(cryptStreem, Encoding.UTF8))
                     {
                         //Disposeが重複して呼ばれないようにする
                         cryptStreem = null;
@@ -868,7 +797,7 @@ namespace OpenTween
 
         internal static bool _IsKeyDown(Keys modifierKeys, Keys[] targetKeys)
         {
-            foreach (Keys key in targetKeys)
+            foreach (var key in targetKeys)
             {
                 if ((modifierKeys & key) != key)
                 {
@@ -942,23 +871,10 @@ namespace OpenTween
             {
                 versionNum[2] = versionNum[2] + 1;
 
-                // 10を越えたら桁上げ
-                if (versionNum[2] >= 10)
-                {
-                    versionNum[1] += versionNum[2] / 10;
-                    versionNum[2] %= 10;
-
-                    if (versionNum[1] >= 10)
-                    {
-                        versionNum[0] += versionNum[1] / 10;
-                        versionNum[1] %= 10;
-                    }
-                }
-
                 if (versionNum[3] == 1)
                     return string.Format("{0}.{1}.{2}-dev", versionNum[0], versionNum[1], versionNum[2]);
                 else
-                    return string.Format("{0}.{1}.{2}-dev (Build {3})", versionNum[0], versionNum[1], versionNum[2], versionNum[3]);
+                    return string.Format("{0}.{1}.{2}-dev+build.{3}", versionNum[0], versionNum[1], versionNum[2], versionNum[3]);
             }
         }
 
@@ -1089,10 +1005,10 @@ namespace OpenTween
         public static string UrlEncode(string stringToEncode)
         {
             const string UnreservedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~";
-            StringBuilder sb = new StringBuilder();
-            byte[] bytes = Encoding.UTF8.GetBytes(stringToEncode);
+            var sb = new StringBuilder();
+            var bytes = Encoding.UTF8.GetBytes(stringToEncode);
 
-            foreach (byte b in bytes)
+            foreach (var b in bytes)
             {
                 if (UnreservedChars.IndexOf((char)b) != -1)
                     sb.Append((char)b);