From 3c25e7a9b3d1e16977856fb8104f7b49a8a70e8d Mon Sep 17 00:00:00 2001 From: axunonb Date: Tue, 2 Nov 2021 22:14:04 +0100 Subject: [PATCH 1/4] Squashed commit of the following: commit a8dec64b7a6090cc4e4c3f491e3475feffd567b1 Merge: ebb820c c4f0115 Author: axunonb Date: Tue Nov 2 21:55:35 2021 +0100 Merge branch 'axuno:main' into main commit c4f0115b4e7873c2aaa5f839ab807c8a7c2bea6b Author: axunonb Date: Tue Nov 2 21:54:46 2021 +0100 Delete .github/workflows directory commit 3283ba98be417b2668d6226af7a36259d352f73d Author: axunonb Date: Tue Nov 2 17:05:09 2021 +0100 Remove demo projects commit 0ebf3f411ebb4e492f4e30912f3f681b3900e36a Author: axunonb Date: Tue Nov 2 16:30:42 2021 +0100 Corrected path to test project commit a9a79d1e9cc625907e494e0693d973b38c3e5c4a Author: axunonb Date: Tue Nov 2 16:22:48 2021 +0100 Add AltCover to test commit 608533fa43ffa504b2731e0fd6a77025e14d20f9 Author: axunonb Date: Tue Nov 2 16:07:01 2021 +0100 Update build.yml commit 3005692bda97fb669cf5b1c08a1e941062c78965 Author: axunonb Date: Tue Nov 2 15:00:06 2021 +0100 Update build.yml commit 4683d5925b11f4b102c61bbd5dbd81714b5d9134 Author: axunonb Date: Tue Nov 2 14:23:29 2021 +0100 Update build.yml commit d3f9b68eb5571ac8a6b866a29e65e29a79b7b1e1 Author: axunonb Date: Tue Nov 2 14:19:05 2021 +0100 Update build.yml commit 4ac19ea1d3715bf5c88ae86a52d5eb1fca074a1a Author: axunonb Date: Tue Nov 2 14:11:42 2021 +0100 Update build.yml commit ef76dba3d489b12258bfc14a32b6dffd18124f20 Author: axunonb Date: Tue Nov 2 14:08:13 2021 +0100 Update build.yml commit e2406b464166f33640b0ab1dff0739b9b69c96ae Author: axunonb Date: Tue Nov 2 14:01:07 2021 +0100 Update build.yml commit adee45a7af07fcd3f06c85c24b6e34f0da933432 Author: axunonb Date: Tue Nov 2 14:00:40 2021 +0100 Update build.yml commit 5464bb9dd8b589cee3fa93ece66e7361fbd520eb Author: axunonb Date: Tue Nov 2 13:53:50 2021 +0100 Create build.yml commit ebb820c1ff3035214c5169b2943edb41d881e6b8 Merge: 365bbd0 ca28b30 Author: axunonb Date: Thu Oct 21 10:06:49 2021 +0200 Merge branch 'axuno:main' into main commit ca28b3005ce8b9132a892e6757c0ebe6584afe8d Author: axunonb Date: Thu Oct 21 10:05:03 2021 +0200 Backport fixes from v3 (#213) Bumped version to 2.7.1 Back-ported bug fixes from v3.0.0-alpha: #179 - Corrected DualFromZeroToTwo plural rule #211 . Illegal placeholder characters that are not 8-bit, will no more throw unexpected ThrowByteOverflowException commit 365bbd08a83b9d71acb4775ee54a6c0177a23040 Author: axunonb Date: Thu Oct 21 09:16:12 2021 +0200 Bumped version to 2.7.1 Backported bug fixes from v3.0.0-alpha: #179 - Corrected DualFromZeroToTwo plural rule #211 . Illegal placeholder characters that are not 8-bit, will no more throw unexpected ThrowByteOverflowException commit 3165fc7226ff5659da44aa36bf678fb9ec34d942 Author: axunonb Date: Thu Oct 21 08:03:32 2021 +0200 Updated NuGet secure key commit 8169585baf5a3d1c6da6b5f2bb7672b126c14e60 Author: axunonb Date: Sun Sep 5 23:09:38 2021 +0200 Update README.md commit 1e09b6a1548c22375e29879f8c943edaa6490f25 Author: axunonb Date: Mon Aug 30 01:52:50 2021 +0200 Update README.md commit 8954f3ec76e3554523c2e304d121cffc4fa25350 Author: axunonb Date: Mon Aug 30 01:51:32 2021 +0200 Update README.md commit a16b01c43438dd62aba5248ab28fc4754441f8f4 Author: axunonb Date: Tue Jun 15 00:06:03 2021 +0200 Update README.md commit d9462f586726d14b50198ee255bde2e38fc54813 Author: axunonb Date: Tue Jun 15 00:05:17 2021 +0200 Update README.md --- CHANGES.md | 2 +- appveyor.yml | 1 - src/SmartFormat/SmartFormat.csproj | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3ef3501c..f7b39145 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,7 +1,7 @@ Latest Changes ==== -What's new in v3.0.0-alpha.3 +What's new in v3.0.0-alpha.4 ==== ### 1. Significant boost in performance diff --git a/appveyor.yml b/appveyor.yml index 96957387..0faf552e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -62,4 +62,3 @@ for: test_script: - dotnet test --no-build --framework net5.0 SmartFormat.sln /p:configuration=release /p:AltCover=true /p:AltCoverXmlReport="coverage.xml" /p:AltCover=true /p:AltCoverStrongNameKey="..\SmartFormat\SmartFormat.snk" /p:AltCoverAssemblyExcludeFilter="SmartFormat.Tests|NUnit3.TestAdapter" /p:AltCoverLineCover="true" - bash <(curl -s https://codecov.io/bash) -f ./SmartFormat.Tests/coverage.net5.0.xml -n net5.0linux - diff --git a/src/SmartFormat/SmartFormat.csproj b/src/SmartFormat/SmartFormat.csproj index be921ff9..44ecc3af 100644 --- a/src/SmartFormat/SmartFormat.csproj +++ b/src/SmartFormat/SmartFormat.csproj @@ -10,7 +10,7 @@ SmartFormat.snk true SmartFormat.NET - See the change log with for details of this release: + See the change log for details of this release: https://github.com/axuno/SmartFormat/blob/master/CHANGES.md https://github.com/axuno/SmartFormat From ed9021fae0a1509d9695c9a9ac7728e59e7771a9 Mon Sep 17 00:00:00 2001 From: axunonb Date: Wed, 17 Nov 2021 10:59:42 +0100 Subject: [PATCH 2/4] Remove all references to Cysharp.Text * Create ZStringBuilder as a 1:1 wrapper for Utf16ValueStringBuilder * Replace usage of Utf16ValueStringBuilder by ZStringBuilder --- .../Sample Extensions/RTFOutput.cs | 5 +- src/Demo/Sample Extensions/RTFOutput.cs | 4 +- .../Core/Output/NullOutputTests.cs | 3 +- .../Core/Output/StringOutputTests.cs | 7 +- .../Core/Output/TextWriterOutputTests.cs | 6 +- .../Core/Output/ZStringOutputTests.cs | 5 +- src/SmartFormat.ZString/ZStringBuilder.cs | 463 ++++++++++++++++++ src/SmartFormat.ZString/ZStringWriter.cs | 7 +- src/SmartFormat/Core/Output/IOutput.cs | 6 +- src/SmartFormat/Core/Output/NullOutput.cs | 4 +- src/SmartFormat/Core/Output/StringOutput.cs | 4 +- .../Core/Output/TextWriterOutput.cs | 4 +- src/SmartFormat/Core/Output/ZStringOutput.cs | 22 +- .../Utilities/ZStringExtensions.cs | 25 +- 14 files changed, 514 insertions(+), 51 deletions(-) create mode 100644 src/SmartFormat.ZString/ZStringBuilder.cs diff --git a/src/Demo.NetFramework/Sample Extensions/RTFOutput.cs b/src/Demo.NetFramework/Sample Extensions/RTFOutput.cs index 0be5c0d1..8617292c 100644 --- a/src/Demo.NetFramework/Sample Extensions/RTFOutput.cs +++ b/src/Demo.NetFramework/Sample Extensions/RTFOutput.cs @@ -1,9 +1,10 @@ using System; using System.Drawing; -using Cysharp.Text; using RTF; using SmartFormat.Core.Extensions; using SmartFormat.Core.Output; +using SmartFormat.ZString; + #nullable enable namespace SmartFormat.Demo.Sample_Extensions @@ -58,7 +59,7 @@ public void Write(string text, int startIndex, int length, IFormattingInfo? form } /// - public void Write(Utf16ValueStringBuilder stringBuilder, IFormattingInfo? formattingInfo) + public void Write(ZStringBuilder stringBuilder, IFormattingInfo? formattingInfo) { #if NETSTANDARD2_1 output.Append(stringBuilder.AsSpan()); diff --git a/src/Demo/Sample Extensions/RTFOutput.cs b/src/Demo/Sample Extensions/RTFOutput.cs index d151c651..48fab83a 100644 --- a/src/Demo/Sample Extensions/RTFOutput.cs +++ b/src/Demo/Sample Extensions/RTFOutput.cs @@ -1,9 +1,9 @@ using System; using System.Drawing; -using Cysharp.Text; using RTF; using SmartFormat.Core.Extensions; using SmartFormat.Core.Output; +using SmartFormat.ZString; namespace SmartFormat.Demo.Sample_Extensions { @@ -58,7 +58,7 @@ public void Write(string text, int startIndex, int length, IFormattingInfo forma } /// - public void Write(Utf16ValueStringBuilder stringBuilder, IFormattingInfo formattingInfo) + public void Write(ZStringBuilder stringBuilder, IFormattingInfo formattingInfo) { #if NETSTANDARD2_1 output.Append(stringBuilder.AsSpan()); diff --git a/src/SmartFormat.Tests/Core/Output/NullOutputTests.cs b/src/SmartFormat.Tests/Core/Output/NullOutputTests.cs index cbab9227..16a07fca 100644 --- a/src/SmartFormat.Tests/Core/Output/NullOutputTests.cs +++ b/src/SmartFormat.Tests/Core/Output/NullOutputTests.cs @@ -3,7 +3,6 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -using Cysharp.Text; using NUnit.Framework; using SmartFormat.Core.Output; @@ -30,7 +29,7 @@ public void Output_Of_String() [Test] public void Output_Of_ValueStringBuilder() { - using var sb = ZString.CreateStringBuilder(); + using var sb = SmartFormat.Utilities.ZStringExtensions.CreateStringBuilder(); sb.Append("text"); var so = new NullOutput(); Assert.DoesNotThrow(() =>so.Write(sb, null)); diff --git a/src/SmartFormat.Tests/Core/Output/StringOutputTests.cs b/src/SmartFormat.Tests/Core/Output/StringOutputTests.cs index 255f5f94..d2c16aa2 100644 --- a/src/SmartFormat.Tests/Core/Output/StringOutputTests.cs +++ b/src/SmartFormat.Tests/Core/Output/StringOutputTests.cs @@ -1,9 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Cysharp.Text; using NUnit.Framework; using SmartFormat.Core.Output; @@ -32,7 +27,7 @@ public void Output_Of_String() public void Output_Of_ValueStringBuilder() { var so = new StringOutput(); - using var sb = ZString.CreateStringBuilder(); + using var sb = SmartFormat.Utilities.ZStringExtensions.CreateStringBuilder(); sb.Append("text"); so.Write(sb, null!); Assert.AreEqual("text", so.ToString()); diff --git a/src/SmartFormat.Tests/Core/Output/TextWriterOutputTests.cs b/src/SmartFormat.Tests/Core/Output/TextWriterOutputTests.cs index 9a159d57..dc282e73 100644 --- a/src/SmartFormat.Tests/Core/Output/TextWriterOutputTests.cs +++ b/src/SmartFormat.Tests/Core/Output/TextWriterOutputTests.cs @@ -1,10 +1,6 @@ using System; -using System.Collections.Generic; using System.IO; -using System.Linq; using System.Text; -using System.Threading.Tasks; -using Cysharp.Text; using NUnit.Framework; using SmartFormat.Core.Output; @@ -36,7 +32,7 @@ public void Output_Of_String() [Test] public void Output_Of_ValueStringBuilder() { - using var sb = ZString.CreateStringBuilder(); + using var sb = SmartFormat.Utilities.ZStringExtensions.CreateStringBuilder(); sb.Append("text"); var sw = new StringWriter(new StringBuilder()); var two = new TextWriterOutput(sw); diff --git a/src/SmartFormat.Tests/Core/Output/ZStringOutputTests.cs b/src/SmartFormat.Tests/Core/Output/ZStringOutputTests.cs index 4fec5945..239cb67d 100644 --- a/src/SmartFormat.Tests/Core/Output/ZStringOutputTests.cs +++ b/src/SmartFormat.Tests/Core/Output/ZStringOutputTests.cs @@ -3,7 +3,6 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -using Cysharp.Text; using NUnit.Framework; using SmartFormat.Core.Output; @@ -22,7 +21,7 @@ public void Create_With_Capacity() [Test] public void Create_With_Other_ValueStringBuilder() { - using var vsb = ZString.CreateStringBuilder(); + using var vsb = SmartFormat.Utilities.ZStringExtensions.CreateStringBuilder(); vsb.Append("text"); using var zStringOutput = new ZStringOutput(vsb); Assert.That(zStringOutput, Is.Not.Null); @@ -49,7 +48,7 @@ public void Output_Of_String() public void Output_Of_ValueStringBuilder() { var so = new ZStringOutput(); - using var sb = ZString.CreateStringBuilder(); + using var sb = SmartFormat.Utilities.ZStringExtensions.CreateStringBuilder(); sb.Append("text"); so.Write(sb, null); Assert.AreEqual("text", so.ToString()); diff --git a/src/SmartFormat.ZString/ZStringBuilder.cs b/src/SmartFormat.ZString/ZStringBuilder.cs new file mode 100644 index 00000000..e1e6a956 --- /dev/null +++ b/src/SmartFormat.ZString/ZStringBuilder.cs @@ -0,0 +1,463 @@ +using System; +using System.Collections.Generic; +using Cysharp.Text; + +namespace SmartFormat.ZString +{ + /// + /// A 1:1 wrapper around , + /// so that we don't have to reference Cysharp.Text classes directly. + /// + /// + /// ********************************** + /// The only required additional method is: + /// public void Append(ZStringBuilder value) => _vsb.Append(value._vsb); + /// ********************************** + /// + public struct ZStringBuilder : IDisposable + { + private Utf16ValueStringBuilder _vsb; + + /// + /// Initializes a new instance + /// + /// + /// If true uses thread-static buffer that is faster but must return immediately. + /// + /// + public ZStringBuilder(bool disposeImmediately) + { + _vsb = new Utf16ValueStringBuilder(disposeImmediately); + } + + /// Length of written buffer. + public int Length => _vsb.Length; + + /// Get the written buffer data. + public ReadOnlySpan AsSpan() => _vsb.AsSpan(); + + /// Get the written buffer data. + public ReadOnlyMemory AsMemory() => _vsb.AsMemory(); + + /// Get the written buffer data. + public ArraySegment AsArraySegment() => _vsb.AsArraySegment(); + + /// + /// Return the inner buffer to pool. + /// + public void Dispose() => _vsb.Dispose(); + + public void Clear() => _vsb.Clear(); + public void TryGrow(int sizeHint) => _vsb.TryGrow(sizeHint); + public void Grow(int sizeHint) => _vsb.Grow(sizeHint); + + /// Appends the default line terminator to the end of this instance. + public void AppendLine() => _vsb.AppendLine(); + + /// Appends the string representation of a specified value followed by the default line terminator to the end of this instance. + public void AppendLine(char value) => _vsb.AppendLine(value); + + /// Appends the string representation of a specified value followed by the default line terminator to the end of this instance. + public void AppendLine(string value) => _vsb.AppendLine(value); + + public void AppendLine(ReadOnlySpan value) => _vsb.AppendLine(value); + + /// Appends the string representation of a specified value followed by the default line terminator to the end of this instance. + public void AppendLine(T value) => _vsb.AppendLine(value); + + /// Appends the string representation of a specified value followed by the default line terminator to the end of this instance. + public void AppendLine(System.Byte value) => _vsb.AppendLine(value); + + /// Appends the string representation of a specified value with numeric format strings followed by the default line terminator to the end of this instance. + public void AppendLine(System.Byte value, string format) => _vsb.AppendLine(value, format); + + /// Appends the string representation of a specified value followed by the default line terminator to the end of this instance. + public void AppendLine(System.DateTime value) => _vsb.AppendLine(value); + + /// Appends the string representation of a specified value with numeric format strings followed by the default line terminator to the end of this instance. + public void AppendLine(System.DateTime value, string format) => _vsb.AppendLine(value, format); + + /// Appends the string representation of a specified value followed by the default line terminator to the end of this instance. + public void AppendLine(System.DateTimeOffset value) => _vsb.AppendLine(value); + + /// Appends the string representation of a specified value with numeric format strings followed by the default line terminator to the end of this instance. + public void AppendLine(System.DateTimeOffset value, string format) => _vsb.AppendLine(value, format); + + /// Appends the string representation of a specified value followed by the default line terminator to the end of this instance. + public void AppendLine(System.Decimal value) => _vsb.AppendLine(value); + + /// Appends the string representation of a specified value with numeric format strings followed by the default line terminator to the end of this instance. + public void AppendLine(System.Decimal value, string format) => _vsb.AppendLine(value, format); + + /// Appends the string representation of a specified value followed by the default line terminator to the end of this instance. + public void AppendLine(System.Double value) => _vsb.AppendLine(value); + + /// Appends the string representation of a specified value with numeric format strings followed by the default line terminator to the end of this instance. + public void AppendLine(System.Double value, string format) => _vsb.AppendLine(value, format); + + /// Appends the string representation of a specified value followed by the default line terminator to the end of this instance. + public void AppendLine(System.Int16 value) => _vsb.AppendLine(value); + + /// Appends the string representation of a specified value with numeric format strings followed by the default line terminator to the end of this instance. + public void AppendLine(System.Int16 value, string format) => _vsb.AppendLine(value, format); + + /// Appends the string representation of a specified value followed by the default line terminator to the end of this instance. + public void AppendLine(System.Int32 value) => _vsb.AppendLine(value); + + /// Appends the string representation of a specified value with numeric format strings followed by the default line terminator to the end of this instance. + public void AppendLine(System.Int32 value, string format) => _vsb.AppendLine(value, format); + + /// Appends the string representation of a specified value followed by the default line terminator to the end of this instance. + public void AppendLine(System.Int64 value) => _vsb.AppendLine(value); + + /// Appends the string representation of a specified value with numeric format strings followed by the default line terminator to the end of this instance. + public void AppendLine(System.Int64 value, string format) => _vsb.AppendLine(value, format); + + /// Appends the string representation of a specified value followed by the default line terminator to the end of this instance. + public void AppendLine(System.SByte value) => _vsb.AppendLine(value); + + /// Appends the string representation of a specified value with numeric format strings followed by the default line terminator to the end of this instance. + public void AppendLine(System.SByte value, string format) => _vsb.AppendLine(value, format); + + /// Appends the string representation of a specified value followed by the default line terminator to the end of this instance. + public void AppendLine(System.Single value) => _vsb.AppendLine(value); + + /// Appends the string representation of a specified value with numeric format strings followed by the default line terminator to the end of this instance. + public void AppendLine(System.Single value, string format) => _vsb.AppendLine(value, format); + + /// Appends the string representation of a specified value followed by the default line terminator to the end of this instance. + public void AppendLine(System.TimeSpan value) => _vsb.AppendLine(value); + + /// Appends the string representation of a specified value with numeric format strings followed by the default line terminator to the end of this instance. + public void AppendLine(System.TimeSpan value, string format) => _vsb.AppendLine(value, format); + + /// Appends the string representation of a specified value followed by the default line terminator to the end of this instance. + public void AppendLine(System.UInt16 value) => _vsb.AppendLine(value); + + /// Appends the string representation of a specified value with numeric format strings followed by the default line terminator to the end of this instance. + public void AppendLine(System.UInt16 value, string format) => _vsb.AppendLine(value, format); + + /// Appends the string representation of a specified value followed by the default line terminator to the end of this instance. + public void AppendLine(System.UInt32 value) => _vsb.AppendLine(value); + + /// Appends the string representation of a specified value with numeric format strings followed by the default line terminator to the end of this instance. + public void AppendLine(System.UInt32 value, string format) => _vsb.AppendLine(value, format); + + /// Appends the string representation of a specified value followed by the default line terminator to the end of this instance. + public void AppendLine(System.UInt64 value) => _vsb.AppendLine(value); + + /// Appends the string representation of a specified value with numeric format strings followed by the default line terminator to the end of this instance. + public void AppendLine(System.UInt64 value, string format) => _vsb.AppendLine(value, format); + + /// Appends the string representation of a specified value followed by the default line terminator to the end of this instance. + public void AppendLine(System.Guid value) => _vsb.AppendLine(value); + + /// Appends the string representation of a specified value with numeric format strings followed by the default line terminator to the end of this instance. + public void AppendLine(System.Guid value, string format) => _vsb.AppendLine(value, format); + + /// Appends the string representation of a specified value to this instance. + public void Append(char value) => _vsb.Append(value); + + public void Append(char value, int repeatCount) => _vsb.Append(value, repeatCount); + + /// Appends the string representation of a specified value to this instance. + public void Append(string value) => _vsb.Append(value); + + /// Appends a contiguous region of arbitrary memory to this instance. + public void Append(ReadOnlySpan value) => _vsb.Append(value); + + /// Appends the string representation of a specified value to this instance. + public void Append(T value) => _vsb.Append(value); + + /// Appends the string representation of a specified value to this instance. + public void Append(ZStringBuilder value) => _vsb.Append(value._vsb); + + /// Appends the string representation of a specified value to this instance. + public void Append(System.Byte value) => _vsb.Append(value); + + /// Appends the string representation of a specified value to this instance with numeric format strings. + public void Append(System.Byte value, string format) => _vsb.Append(value, format); + + /// Appends the string representation of a specified value to this instance. + public void Append(System.DateTime value) => _vsb.Append(value); + + /// Appends the string representation of a specified value to this instance with numeric format strings. + public void Append(System.DateTime value, string format) => _vsb.Append(value, format); + + /// Appends the string representation of a specified value to this instance. + public void Append(System.DateTimeOffset value) => _vsb.Append(value); + + /// Appends the string representation of a specified value to this instance with numeric format strings. + public void Append(System.DateTimeOffset value, string format) => _vsb.Append(value, format); + + /// Appends the string representation of a specified value to this instance. + public void Append(System.Decimal value) => _vsb.Append(value); + + /// Appends the string representation of a specified value to this instance with numeric format strings. + public void Append(System.Decimal value, string format) => _vsb.Append(value, format); + + /// Appends the string representation of a specified value to this instance. + public void Append(System.Double value) => _vsb.Append(value); + + /// Appends the string representation of a specified value to this instance with numeric format strings. + public void Append(System.Double value, string format) => _vsb.Append(value, format); + + /// Appends the string representation of a specified value to this instance. + public void Append(System.Int16 value) => _vsb.Append(value); + + /// Appends the string representation of a specified value to this instance with numeric format strings. + public void Append(System.Int16 value, string format) => _vsb.Append(value, format); + + /// Appends the string representation of a specified value to this instance. + public void Append(System.Int32 value) => _vsb.Append(value); + + /// Appends the string representation of a specified value to this instance with numeric format strings. + public void Append(System.Int32 value, string format) => _vsb.Append(value, format); + + /// Appends the string representation of a specified value to this instance. + public void Append(System.Int64 value) => _vsb.Append(value); + + /// Appends the string representation of a specified value to this instance with numeric format strings. + public void Append(System.Int64 value, string format) => _vsb.Append(value, format); + + /// Appends the string representation of a specified value to this instance. + public void Append(System.SByte value) => _vsb.Append(value); + + /// Appends the string representation of a specified value to this instance with numeric format strings. + public void Append(System.SByte value, string format) => _vsb.Append(value, format); + + /// Appends the string representation of a specified value to this instance. + public void Append(System.Single value) => _vsb.Append(value); + + /// Appends the string representation of a specified value to this instance with numeric format strings. + public void Append(System.Single value, string format) => _vsb.Append(value, format); + + /// Appends the string representation of a specified value to this instance. + public void Append(System.TimeSpan value) => _vsb.Append(value); + + /// Appends the string representation of a specified value to this instance with numeric format strings. + public void Append(System.TimeSpan value, string format) => _vsb.Append(value, format); + + /// Appends the string representation of a specified value to this instance. + public void Append(System.UInt16 value) => _vsb.Append(value); + + /// Appends the string representation of a specified value to this instance with numeric format strings. + public void Append(System.UInt16 value, string format) => _vsb.Append(value, format); + + /// Appends the string representation of a specified value to this instance. + public void Append(System.UInt32 value) => _vsb.Append(value); + + /// Appends the string representation of a specified value to this instance with numeric format strings. + public void Append(System.UInt32 value, string format) => _vsb.Append(value, format); + + /// Appends the string representation of a specified value to this instance. + public void Append(System.UInt64 value) => _vsb.Append(value); + + /// Appends the string representation of a specified value to this instance with numeric format strings. + public void Append(System.UInt64 value, string format) => _vsb.Append(value, format); + + /// Appends the string representation of a specified value to this instance. + public void Append(System.Guid value) => _vsb.Append(value); + + /// Appends the string representation of a specified value to this instance with numeric format strings. + public void Append(System.Guid value, string format) => _vsb.Append(value, format); + + /// + /// Inserts a string 0 or more times into this builder at the specified position. + /// + /// The index to insert in this builder. + /// The string to insert. + /// The number of times to insert the string. + public void Insert(int index, string value, int count) => _vsb.Insert(index, value, count); + + public void Insert(int index, string value) => _vsb.Insert(index, value); + public void Insert(int index, ReadOnlySpan value, int count) => _vsb.Insert(index, value, count); + + /// + /// Replaces all instances of one character with another in this builder. + /// + /// The character to replace. + /// The character to replace with. + public void Replace(char oldChar, char newChar) => _vsb.Replace(oldChar, newChar); + + /// + /// Replaces all instances of one character with another in this builder. + /// + /// The character to replace. + /// The character to replace with. + /// The index to start in this builder. + /// The number of characters to read in this builder. + public void Replace(char oldChar, char newChar, int startIndex, int count) => + _vsb.Replace(oldChar, newChar, startIndex, count); + + /// + /// Replaces all instances of one string with another in this builder. + /// + /// The string to replace. + /// The string to replace with. + /// + /// If is null, instances of + /// are removed from this builder. + /// + public void Replace(string oldValue, string newValue) => _vsb.Replace(oldValue, newValue); + + public void Replace(ReadOnlySpan oldValue, ReadOnlySpan newValue) => _vsb.Replace(oldValue, newValue); + + /// + /// Replaces all instances of one string with another in part of this builder. + /// + /// The string to replace. + /// The string to replace with. + /// The index to start in this builder. + /// The number of characters to read in this builder. + /// + /// If is null, instances of + /// are removed from this builder. + /// + public void Replace(string oldValue, string newValue, int startIndex, int count) => + _vsb.Replace(oldValue, newValue, startIndex, count); + + public void Replace(ReadOnlySpan oldValue, ReadOnlySpan newValue, int startIndex, int count) => + _vsb.Replace(oldValue, newValue, startIndex, count); + + /// + /// Removes a range of characters from this builder. + /// + /// + /// This method does not reduce the capacity of this builder. + /// + public void Remove(int startIndex, int length) => _vsb.Remove(startIndex, length); + + /// Copy inner buffer to the destination span. + public bool TryCopyTo(Span destination, out int charsWritten) => _vsb.TryCopyTo(destination, out charsWritten); + + /// Converts the value of this instance to a System.String. + public string ToString() => _vsb.ToString(); + + /// IBufferWriter.GetMemory. + public Memory GetMemory(int sizeHint) => _vsb.GetMemory(sizeHint); + + /// IBufferWriter.GetSpan. + public Span GetSpan(int sizeHint) => _vsb.GetSpan(sizeHint); + + /// IBufferWriter.Advance. + public void Advance(int count) => _vsb.Advance(count); + + /// Appends the string returned by processing a composite format string, each format item is replaced by the string representation of arguments. + public void AppendFormat(string format, T1 arg1) => _vsb.AppendFormat(format, arg1); + + /// Appends the string returned by processing a composite format string, each format item is replaced by the string representation of arguments. + public void AppendFormat(string format, T1 arg1, T2 arg2) => _vsb.AppendFormat(format, arg1, arg2); + + /// Appends the string returned by processing a composite format string, each format item is replaced by the string representation of arguments. + public void AppendFormat(string format, T1 arg1, T2 arg2, T3 arg3) => + _vsb.AppendFormat(format, arg1, arg2, arg3); + + /// Appends the string returned by processing a composite format string, each format item is replaced by the string representation of arguments. + public void AppendFormat(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4) => + _vsb.AppendFormat(format, arg1, arg2, arg3, arg4); + + /// Appends the string returned by processing a composite format string, each format item is replaced by the string representation of arguments. + public void AppendFormat(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) => + _vsb.AppendFormat(format, arg1, arg2, arg3, arg4, arg5); + + /// Appends the string returned by processing a composite format string, each format item is replaced by the string representation of arguments. + public void AppendFormat(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, + T6 arg6) => _vsb.AppendFormat(format, arg1, arg2, arg3, arg4, arg5, arg6); + + /// Appends the string returned by processing a composite format string, each format item is replaced by the string representation of arguments. + public void AppendFormat(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, + T6 arg6, T7 arg7) => _vsb.AppendFormat(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7); + + /// Appends the string returned by processing a composite format string, each format item is replaced by the string representation of arguments. + public void AppendFormat(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, + T6 arg6, T7 arg7, T8 arg8) => _vsb.AppendFormat(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + + /// Appends the string returned by processing a composite format string, each format item is replaced by the string representation of arguments. + public void AppendFormat(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) => _vsb.AppendFormat(format, arg1, arg2, arg3, arg4, arg5, arg6, + arg7, arg8, arg9); + + /// Appends the string returned by processing a composite format string, each format item is replaced by the string representation of arguments. + public void AppendFormat(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10) => _vsb.AppendFormat(format, arg1, arg2, arg3, arg4, arg5, arg6, + arg7, arg8, arg9, arg10); + + /// Appends the string returned by processing a composite format string, each format item is replaced by the string representation of arguments. + public void AppendFormat(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11) => _vsb.AppendFormat(format, arg1, arg2, arg3, arg4, arg5, arg6, + arg7, arg8, arg9, arg10, arg11); + + /// Appends the string returned by processing a composite format string, each format item is replaced by the string representation of arguments. + public void AppendFormat(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12) => _vsb.AppendFormat(format, arg1, arg2, arg3, arg4, arg5, arg6, + arg7, arg8, arg9, arg10, arg11, arg12); + + /// Appends the string returned by processing a composite format string, each format item is replaced by the string representation of arguments. + public void AppendFormat(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13) => _vsb.AppendFormat(format, arg1, arg2, arg3, arg4, arg5, arg6, + arg7, arg8, arg9, arg10, arg11, arg12, arg13); + + /// Appends the string returned by processing a composite format string, each format item is replaced by the string representation of arguments. + public void AppendFormat(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14) => _vsb.AppendFormat(format, arg1, arg2, arg3, arg4, arg5, arg6, + arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14); + + /// Appends the string returned by processing a composite format string, each format item is replaced by the string representation of arguments. + public void AppendFormat(string format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15) => _vsb.AppendFormat(format, arg1, arg2, arg3, arg4, arg5, arg6, + arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15); + + /// Appends the string returned by processing a composite format string, each format item is replaced by the string representation of arguments. + public void AppendFormat(string format, T1 arg1, + T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, + T13 arg13, T14 arg14, T15 arg15, T16 arg16) => _vsb.AppendFormat(format, arg1, arg2, arg3, arg4, arg5, arg6, + arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16); + + /// + /// Concatenates the string representations of the elements in the provided array of objects, using the specified char separator between each member, then appends the result to the current instance of the string builder. + /// + /// + /// + /// + public void AppendJoin(char separator, params T[] values) => _vsb.AppendJoin(separator, values); + + public void AppendJoin(char separator, List values) => _vsb.AppendJoin(separator, values); + public void AppendJoin(char separator, ReadOnlySpan values) => _vsb.AppendJoin(separator, values); + + /// + /// Concatenates and appends the members of a collection, using the specified char separator between each member. + /// + /// + /// + /// + public void AppendJoin(char separator, IEnumerable values) => _vsb.AppendJoin(separator, values); + + public void AppendJoin(char separator, ICollection values) => _vsb.AppendJoin(separator, values); + public void AppendJoin(char separator, IList values) => _vsb.AppendJoin(separator, values); + public void AppendJoin(char separator, IReadOnlyList values) => _vsb.AppendJoin(separator, values); + public void AppendJoin(char separator, IReadOnlyCollection values) => _vsb.AppendJoin(separator, values); + + /// + /// Concatenates the string representations of the elements in the provided array of objects, using the specified separator between each member, then appends the result to the current instance of the string builder. + /// + /// + /// + /// + public void AppendJoin(string separator, params T[] values) => _vsb.AppendJoin(separator, values); + + public void AppendJoin(string separator, List values) => _vsb.AppendJoin(separator, values); + public void AppendJoin(string separator, ReadOnlySpan values) => _vsb.AppendJoin(separator, values); + + /// + /// Concatenates and appends the members of a collection, using the specified separator between each member. + /// + /// + /// + /// + public void AppendJoin(string separator, IEnumerable values) => _vsb.AppendJoin(separator, values); + + public void AppendJoin(string separator, ICollection values) => _vsb.AppendJoin(separator, values); + public void AppendJoin(string separator, IList values) => _vsb.AppendJoin(separator, values); + public void AppendJoin(string separator, IReadOnlyList values) => _vsb.AppendJoin(separator, values); + public void AppendJoin(string separator, IReadOnlyCollection values) => _vsb.AppendJoin(separator, values); + + void IDisposable.Dispose() + { + _vsb.Dispose(); + } + } +} \ No newline at end of file diff --git a/src/SmartFormat.ZString/ZStringWriter.cs b/src/SmartFormat.ZString/ZStringWriter.cs index 68835b87..5bd9cc25 100644 --- a/src/SmartFormat.ZString/ZStringWriter.cs +++ b/src/SmartFormat.ZString/ZStringWriter.cs @@ -5,6 +5,11 @@ using System.Threading; using System.Threading.Tasks; +/* + * The ZStringWriter class from the repo is excluded from the project + * and replaced with this modified version, so we can compile for TFM net461 + */ + namespace Cysharp.Text { /// @@ -50,7 +55,7 @@ protected override void Dispose(bool disposing) base.Dispose(disposing); } - public override Encoding Encoding => encoding = encoding ?? new UnicodeEncoding(false, false); + public override Encoding Encoding => encoding ??= new UnicodeEncoding(false, false); public override void Write(char value) { diff --git a/src/SmartFormat/Core/Output/IOutput.cs b/src/SmartFormat/Core/Output/IOutput.cs index f5a8d7ea..5c1a0f2b 100644 --- a/src/SmartFormat/Core/Output/IOutput.cs +++ b/src/SmartFormat/Core/Output/IOutput.cs @@ -4,8 +4,8 @@ // using System; -using Cysharp.Text; using SmartFormat.Core.Extensions; +using SmartFormat.ZString; namespace SmartFormat.Core.Output { @@ -29,10 +29,10 @@ public interface IOutput void Write(ReadOnlySpan text, IFormattingInfo? formattingInfo = null); /// - /// Writes text of a to the output. + /// Writes text of a to the output. /// /// /// - void Write(Utf16ValueStringBuilder stringBuilder, IFormattingInfo? formattingInfo = null); + void Write(ZStringBuilder stringBuilder, IFormattingInfo? formattingInfo = null); } } \ No newline at end of file diff --git a/src/SmartFormat/Core/Output/NullOutput.cs b/src/SmartFormat/Core/Output/NullOutput.cs index 7061a125..c1dda300 100644 --- a/src/SmartFormat/Core/Output/NullOutput.cs +++ b/src/SmartFormat/Core/Output/NullOutput.cs @@ -4,8 +4,8 @@ // using System; -using Cysharp.Text; using SmartFormat.Core.Extensions; +using SmartFormat.ZString; namespace SmartFormat.Core.Output { @@ -38,7 +38,7 @@ public void Write(ReadOnlySpan text, IFormattingInfo? formattingInfo = nul } /// - public void Write(Utf16ValueStringBuilder stringBuilder, IFormattingInfo? formattingInfo = null) + public void Write(ZStringBuilder stringBuilder, IFormattingInfo? formattingInfo = null) { // Nothing to do here } diff --git a/src/SmartFormat/Core/Output/StringOutput.cs b/src/SmartFormat/Core/Output/StringOutput.cs index f07c976b..41e0484e 100644 --- a/src/SmartFormat/Core/Output/StringOutput.cs +++ b/src/SmartFormat/Core/Output/StringOutput.cs @@ -5,8 +5,8 @@ using System; using System.Text; -using Cysharp.Text; using SmartFormat.Core.Extensions; +using SmartFormat.ZString; namespace SmartFormat.Core.Output { @@ -71,7 +71,7 @@ public void Write(ReadOnlySpan text, IFormattingInfo? formattingInfo = nul } /// - public void Write(Utf16ValueStringBuilder stringBuilder, IFormattingInfo? formattingInfo = null) + public void Write(ZStringBuilder stringBuilder, IFormattingInfo? formattingInfo = null) { #if NETSTANDARD2_1 _output.Append(stringBuilder.AsSpan()); diff --git a/src/SmartFormat/Core/Output/TextWriterOutput.cs b/src/SmartFormat/Core/Output/TextWriterOutput.cs index c542840b..8c96c2ee 100644 --- a/src/SmartFormat/Core/Output/TextWriterOutput.cs +++ b/src/SmartFormat/Core/Output/TextWriterOutput.cs @@ -5,8 +5,8 @@ using System; using System.IO; -using Cysharp.Text; using SmartFormat.Core.Extensions; +using SmartFormat.ZString; namespace SmartFormat.Core.Output { @@ -46,7 +46,7 @@ public void Write(ReadOnlySpan text, IFormattingInfo? formattingInfo = nul } /// - public void Write(Utf16ValueStringBuilder stringBuilder, IFormattingInfo? formattingInfo = null) + public void Write(ZStringBuilder stringBuilder, IFormattingInfo? formattingInfo = null) { #if NETSTANDARD2_1 Output.Write(stringBuilder.AsSpan()); diff --git a/src/SmartFormat/Core/Output/ZStringOutput.cs b/src/SmartFormat/Core/Output/ZStringOutput.cs index 44e41cb4..3ca441ff 100644 --- a/src/SmartFormat/Core/Output/ZStringOutput.cs +++ b/src/SmartFormat/Core/Output/ZStringOutput.cs @@ -5,34 +5,34 @@ using System; using System.Text; -using Cysharp.Text; +using SmartFormat.ZString; using SmartFormat.Core.Extensions; namespace SmartFormat.Core.Output { /// - /// Wraps a so it can be used for output. + /// Wraps a so it can be used for output. /// This is used for the default output. /// /// - /// , , + /// , , /// and objects use UTF-16 encoding to store characters. /// public class ZStringOutput : IOutput, IDisposable { - private Utf16ValueStringBuilder _output; + private ZStringBuilder _output; /// - /// Returns the used for output. + /// Returns the used for output. /// - public Utf16ValueStringBuilder Output => _output; // Use with a backing field! + public ZStringBuilder Output => _output; // Use with a backing field! /// /// Creates a new instance of . /// public ZStringOutput() { - _output = ZString.CreateStringBuilder(); + _output = Utilities.ZStringExtensions.CreateStringBuilder(); } /// @@ -45,9 +45,9 @@ public ZStringOutput(int capacity) } /// - /// Creates a new instance of using the given . + /// Creates a new instance of using the given . /// - public ZStringOutput(Utf16ValueStringBuilder stringBuilder) + public ZStringOutput(ZStringBuilder stringBuilder) { _output = stringBuilder; } @@ -65,13 +65,13 @@ public void Write(ReadOnlySpan text, IFormattingInfo? formattingInfo = nul } /// - public void Write(Utf16ValueStringBuilder stringBuilder, IFormattingInfo? formattingInfo = null) + public void Write(ZStringBuilder stringBuilder, IFormattingInfo? formattingInfo = null) { _output.Append(stringBuilder); } /// - /// Returns the string result of the . + /// Returns the string result of the . /// public override string ToString() { diff --git a/src/SmartFormat/Utilities/ZStringExtensions.cs b/src/SmartFormat/Utilities/ZStringExtensions.cs index 2753d8ac..05e5425f 100644 --- a/src/SmartFormat/Utilities/ZStringExtensions.cs +++ b/src/SmartFormat/Utilities/ZStringExtensions.cs @@ -1,8 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Cysharp.Text; -using SmartFormat.Core.Parsing; +using SmartFormat.Core.Parsing; +using SmartFormat.ZString; namespace SmartFormat.Utilities { @@ -25,21 +22,29 @@ internal static int CalcCapacity(Format format) } /// - /// Creates a new instance of with the given initial capacity. + /// Creates a new instance of with the given initial capacity. + /// + internal static ZStringBuilder CreateStringBuilder() + { + return new ZStringBuilder(false); + } + + /// + /// Creates a new instance of with the given initial capacity. /// /// The estimated buffer capacity will be calculated from the instance. - internal static Utf16ValueStringBuilder CreateStringBuilder(Format format) + internal static ZStringBuilder CreateStringBuilder(Format format) { return CreateStringBuilder(CalcCapacity(format)); } /// - /// Creates a new instance of with the given initial capacity. + /// Creates a new instance of with the given initial capacity. /// /// The estimated capacity required. This will reduce or avoid incremental buffer increases. - internal static Utf16ValueStringBuilder CreateStringBuilder(int capacity) + internal static ZStringBuilder CreateStringBuilder(int capacity) { - var sb = new Utf16ValueStringBuilder(false); + var sb = new ZStringBuilder(false); if(capacity > DefaultBufferSize) sb.Grow(capacity - DefaultBufferSize); From 5989849ca0d7dcb6d0199880307069560936f104 Mon Sep 17 00:00:00 2001 From: axunonb Date: Wed, 17 Nov 2021 11:23:26 +0100 Subject: [PATCH 3/4] Modified tests for linux build on net60 --- .../Extensions/DefaultSourceTests.cs | 5 ++-- .../Extensions/NullFormatterTests.cs | 2 +- .../Extensions/SubStringFormatterTests.cs | 3 ++- .../Extensions/TimeFormatterTests.cs | 3 ++- .../TestUtils/FormattingInfoExtensions.cs | 26 +++++++++++++++++++ 5 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 src/SmartFormat.Tests/TestUtils/FormattingInfoExtensions.cs diff --git a/src/SmartFormat.Tests/Extensions/DefaultSourceTests.cs b/src/SmartFormat.Tests/Extensions/DefaultSourceTests.cs index 83e7e613..a975f17c 100644 --- a/src/SmartFormat.Tests/Extensions/DefaultSourceTests.cs +++ b/src/SmartFormat.Tests/Extensions/DefaultSourceTests.cs @@ -7,6 +7,7 @@ using SmartFormat.Core.Extensions; using SmartFormat.Core.Formatting; using SmartFormat.Extensions; +using SmartFormat.Tests.TestUtils; namespace SmartFormat.Tests.Extensions { @@ -20,14 +21,14 @@ private class SourceImplementation : Source public void Call_With_NonNumeric_Argument_Should_Fail() { var source = new DefaultSource(); - Assert.That(source.TryEvaluateSelector(FormattingInfo.Create("{a}", new List())), Is.EqualTo(false)); + Assert.That(source.TryEvaluateSelector(FormattingInfoExtensions.Create("{a}", new List())), Is.EqualTo(false)); } [Test] public void TryEvaluateSelector_Should_Fail() { var source = new SourceImplementation(); - Assert.That(source.TryEvaluateSelector(FormattingInfo.Create("{Dummy}", new List())), Is.EqualTo(false)); + Assert.That(source.TryEvaluateSelector(FormattingInfoExtensions.Create("{Dummy}", new List())), Is.EqualTo(false)); } } } diff --git a/src/SmartFormat.Tests/Extensions/NullFormatterTests.cs b/src/SmartFormat.Tests/Extensions/NullFormatterTests.cs index 0507b355..377f7598 100644 --- a/src/SmartFormat.Tests/Extensions/NullFormatterTests.cs +++ b/src/SmartFormat.Tests/Extensions/NullFormatterTests.cs @@ -97,7 +97,7 @@ public void NullFormatter_Must_Not_Contain_Choose_Options() public void NullFormatter_Format_Count_Must_Be_1_or_2() { var smart = GetFormatter(); - Assert.That(() => smart.Format("{0:isnull:1|2|3}", 123), Throws.InstanceOf(), "No format included"); + Assert.That(delegate { return smart.Format("{0:isnull:1|2|3}", 123); }, Throws.InstanceOf(), "No format included"); } } } diff --git a/src/SmartFormat.Tests/Extensions/SubStringFormatterTests.cs b/src/SmartFormat.Tests/Extensions/SubStringFormatterTests.cs index 95a32ac1..728f5f93 100644 --- a/src/SmartFormat.Tests/Extensions/SubStringFormatterTests.cs +++ b/src/SmartFormat.Tests/Extensions/SubStringFormatterTests.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using SmartFormat.Core.Formatting; +using SmartFormat.Tests.TestUtils; namespace SmartFormat.Tests.Extensions { @@ -161,7 +162,7 @@ public void ImplicitFormatterEvaluation_With_Wrong_Args_Should_Fail() var smart = GetFormatter(); Assert.That( smart.GetFormatterExtension()!.TryEvaluateFormat( - FormattingInfo.Create("{0::(0,2)}", new List(new[] {new object()}))), Is.EqualTo(false)); + FormattingInfoExtensions.Create("{0::(0,2)}", new List(new[] {new object()}))), Is.EqualTo(false)); } } } \ No newline at end of file diff --git a/src/SmartFormat.Tests/Extensions/TimeFormatterTests.cs b/src/SmartFormat.Tests/Extensions/TimeFormatterTests.cs index e74c7315..e883f3dc 100644 --- a/src/SmartFormat.Tests/Extensions/TimeFormatterTests.cs +++ b/src/SmartFormat.Tests/Extensions/TimeFormatterTests.cs @@ -47,7 +47,8 @@ public void UseTimeFormatter_WithIllegalLanguage() var timeFormatter = smart.GetFormatterExtension()!; timeFormatter.FallbackLanguage = string.Empty; - Assert.That(() => smart.Format(CultureInfo.InvariantCulture, "{0:time:noless}", new TimeSpan(1, 2, 3)), + Assert.That( + delegate { return smart.Format(CultureInfo.InvariantCulture, "{0:time:noless}", new TimeSpan(1, 2, 3)); }, Throws.InstanceOf().And.Message.Contains("TimeTextInfo could not be found"), "Language as argument"); } diff --git a/src/SmartFormat.Tests/TestUtils/FormattingInfoExtensions.cs b/src/SmartFormat.Tests/TestUtils/FormattingInfoExtensions.cs new file mode 100644 index 00000000..e53ae5c3 --- /dev/null +++ b/src/SmartFormat.Tests/TestUtils/FormattingInfoExtensions.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using SmartFormat.Core.Formatting; +using SmartFormat.Core.Output; +using SmartFormat.Core.Settings; + +namespace SmartFormat.Tests.TestUtils +{ + internal static class FormattingInfoExtensions + { + /// + /// Creates a new instance of . + /// + /// The input format string. + /// The data argument. + /// A new instance of . + public static FormattingInfo Create(string format, IList data) + { + var formatter = new SmartFormatter(new SmartSettings()); + var formatParsed = formatter.Parser.ParseFormat(format); + // use StringOutput because we don't have to care about disposing. + var formatDetails = new FormatDetails(formatter, formatParsed, data, null, new StringOutput()); + return new FormattingInfo(formatDetails, formatDetails.OriginalFormat, data); + } + } +} From 212eac2e1389e5cb185f0499d57e676c18c62b1a Mon Sep 17 00:00:00 2001 From: axunonb Date: Wed, 17 Nov 2021 17:39:08 +0100 Subject: [PATCH 4/4] Added comments to ZStringBuilder --- src/SmartFormat.ZString/ZStringBuilder.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/SmartFormat.ZString/ZStringBuilder.cs b/src/SmartFormat.ZString/ZStringBuilder.cs index e1e6a956..f6bc5934 100644 --- a/src/SmartFormat.ZString/ZStringBuilder.cs +++ b/src/SmartFormat.ZString/ZStringBuilder.cs @@ -8,14 +8,13 @@ namespace SmartFormat.ZString /// A 1:1 wrapper around , /// so that we don't have to reference Cysharp.Text classes directly. /// - /// - /// ********************************** - /// The only required additional method is: - /// public void Append(ZStringBuilder value) => _vsb.Append(value._vsb); - /// ********************************** - /// public struct ZStringBuilder : IDisposable { + /********************************** + The only required additional method is: + public void Append(ZStringBuilder value) => _vsb.Append(value._vsb); + **********************************/ + private Utf16ValueStringBuilder _vsb; ///