OSDN Git Service

autoPopulatedUserIdsとattachmentUrlの抽出をFormatStatusTextExtendedメソッドにまとめる
authorKimura Youichi <kim.upsilon@bucyou.net>
Mon, 3 Oct 2016 12:24:42 +0000 (21:24 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Sat, 11 Nov 2017 21:07:18 +0000 (06:07 +0900)
OpenTween/Tween.cs

index 8969231..0011112 100644 (file)
@@ -986,7 +986,7 @@ namespace OpenTween
             StatusLabel.AutoToolTip = false;
             StatusLabel.ToolTipText = "";
             //文字カウンタ初期化
-            lblLen.Text = this.GetRestStatusCount("").ToString();
+            lblLen.Text = this.GetRestStatusCount(this.FormatStatusTextExtended("")).ToString();
 
             this.JumpReadOpMenuItem.ShortcutKeyDisplayString = "Space";
             CopySTOTMenuItem.ShortcutKeyDisplayString = "Ctrl+C";
@@ -2121,13 +2121,11 @@ namespace OpenTween
             StatusText.SelectionStart = StatusText.Text.Length;
             CheckReplyTo(StatusText.Text);
 
-            long[] autoPopulatedUserIds;
-            var statusText = this.RemoveAutoPopuratedMentions(this.StatusText.Text, out autoPopulatedUserIds);
+            var statusText = this.StatusText.Text;
 
+            long[] autoPopulatedUserIds;
             string attachmentUrl;
-            statusText = this.RemoveAttachmentUrl(statusText, out attachmentUrl);
-
-            statusText = this.FormatStatusText(statusText);
+            statusText = this.FormatStatusTextExtended(statusText, out autoPopulatedUserIds, out attachmentUrl);
 
             if (this.GetRestStatusCount(statusText) < 0)
             {
@@ -4721,7 +4719,7 @@ namespace OpenTween
         private void StatusText_TextChanged(object sender, EventArgs e)
         {
             //文字数カウント
-            int pLen = this.GetRestStatusCount(this.StatusText.Text);
+            int pLen = this.GetRestStatusCount(this.FormatStatusTextExtended(this.StatusText.Text));
             lblLen.Text = pLen.ToString();
             if (pLen < 0)
             {
@@ -4792,6 +4790,26 @@ namespace OpenTween
             return statusText.TrimEnd(' ');
         }
 
+        private string FormatStatusTextExtended(string statusText)
+        {
+            long[] autoPopulatedUserIds;
+            string attachmentUrl;
+
+            return this.FormatStatusTextExtended(statusText, out autoPopulatedUserIds, out attachmentUrl);
+        }
+
+        /// <summary>
+        /// <see cref="FormatStatusText"/> に加えて、拡張モードで140字にカウントされない文字列の除去を行います
+        /// </summary>
+        private string FormatStatusTextExtended(string statusText, out long[] autoPopulatedUserIds, out string attachmentUrl)
+        {
+            statusText = this.RemoveAutoPopuratedMentions(statusText, out autoPopulatedUserIds);
+
+            statusText = this.RemoveAttachmentUrl(statusText, out attachmentUrl);
+
+            return this.FormatStatusText(statusText);
+        }
+
         /// <summary>
         /// ツイート投稿前のフッター付与などの前処理を行います
         /// </summary>
@@ -4891,14 +4909,6 @@ namespace OpenTween
         /// </summary>
         private int GetRestStatusCount(string statusText)
         {
-            long[] autoPopulatedUserIds;
-            statusText = this.RemoveAutoPopuratedMentions(statusText, out autoPopulatedUserIds);
-
-            string attachmentUrl;
-            statusText = this.RemoveAttachmentUrl(statusText, out attachmentUrl);
-
-            statusText = this.FormatStatusText(statusText);
-
             var remainCount = this.tw.GetTextLengthRemain(statusText);
 
             var uploadService = this.GetSelectedImageService();