OSDN Git Service

ドキュメントの保存関係をStringBufferクラスに移した
authortest <test@yahoo.co.jp>
Wed, 6 Feb 2019 03:28:11 +0000 (12:28 +0900)
committertest <test@yahoo.co.jp>
Wed, 6 Feb 2019 03:28:11 +0000 (12:28 +0900)
Core/Document.cs
Core/StringBuffer.cs

index 0a42405..6f7998a 100644 (file)
@@ -1158,33 +1158,8 @@ namespace FooEditEngine
         /// <remarks>非同期操作中はこのメソッドを実行することはできません。同時にダーティフラグもクリアされます</remarks>
         public async Task SaveAsync(TextWriter fs, CancellationTokenSource tokenSource = null)
         {
-            try
-            {
-                await this.buffer.LockAsync().ConfigureAwait(false);
-                StringBuilder line = new StringBuilder();
-                for (int i = 0; i < this.Length; i++)
-                {
-                    char c = this[i];
-                    line.Append(c);
-                    if (c == Document.NewLine || i == this.Length - 1)
-                    {
-                        string str = line.ToString();
-                        str = str.Replace(Document.NewLine.ToString(), fs.NewLine);
-                        await fs.WriteAsync(str).ConfigureAwait(false);
-                        line.Clear();
-                        if (tokenSource != null)
-                            tokenSource.Token.ThrowIfCancellationRequested();
-#if TEST_ASYNC
-                    System.Threading.Thread.Sleep(10);
-#endif
-                    }
-                }
-                this.Dirty = false;
-            }
-            finally
-            {
-                this.buffer.UnLock();
-            }
+            await this.buffer.SaveAsync(fs, tokenSource);
+            this.Dirty = false;
         }
 
         /// <summary>
index 0fdc448..d1247ab 100644 (file)
@@ -228,6 +228,36 @@ namespace FooEditEngine
             } while (readCount > 0);
         }
 
+        internal async Task SaveAsync(TextWriter fs, CancellationTokenSource tokenSource = null)
+        {
+            try
+            {
+                await this.LockAsync().ConfigureAwait(false);
+                StringBuilder line = new StringBuilder();
+                for (int i = 0; i < this.Length; i++)
+                {
+                    char c = this[i];
+                    line.Append(c);
+                    if (c == Document.NewLine || i == this.Length - 1)
+                    {
+                        string str = line.ToString();
+                        str = str.Replace(Document.NewLine.ToString(), fs.NewLine);
+                        await fs.WriteAsync(str).ConfigureAwait(false);
+                        line.Clear();
+                        if (tokenSource != null)
+                            tokenSource.Token.ThrowIfCancellationRequested();
+#if TEST_ASYNC
+                    System.Threading.Thread.Sleep(10);
+#endif
+                    }
+                }
+            }
+            finally
+            {
+                this.UnLock();
+            }
+        }
+
         internal void ReplaceRegexAll(LineToIndexTable layoutlines, Regex regex, string pattern, bool groupReplace)
         {
             for (int i = 0; i < layoutlines.Count; i++)