Skip to content

Commit

Permalink
Reference to Cysharp ZString v2.6.0 package (#382)
Browse files Browse the repository at this point in the history
* Reference Cysharp `ZString` v2.6.0 in `SmartFormat` project (net461 target use the netstandard2.0 assemblies)
* Remove project `SmartFormat.Zstring`
* Move internal static class ZStringBuilderExtensions to namespace SmartFormat.ZString
* Rename ZStringBuilderExtensions to ZStringBuilderUtilities
  • Loading branch information
axunonb committed May 10, 2024
1 parent c48f7c6 commit 693243b
Show file tree
Hide file tree
Showing 20 changed files with 421 additions and 371 deletions.
30 changes: 20 additions & 10 deletions src/Demo/Sample Extensions/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
#nullable enable
namespace SmartFormat.Demo.Sample_Extensions
Expand Down Expand Up @@ -82,21 +83,30 @@ private static T RandomIterator<T>(this IEnumerable<T> source) where T:new()
return new T();
}

var index = (new Random()).Next(itemCount);
var index = GetRandomNumber(itemCount);
return sc.ElementAt(index);
}

#endregion
private static int GetRandomNumber(int itemCount)
{
using var rng = RandomNumberGenerator.Create();
var randomNumber = new byte[4]; // 4 for int32
rng.GetBytes(randomNumber);
var value = Math.Abs(BitConverter.ToInt32(randomNumber, 0));
return value % itemCount;
}

#region: Split :
#endregion

/// <summary>Splits the enumeration into segments,
/// each segment containing [count] items, and the last segment containing the remainder.
/// </summary>
/// <param name="source"></param>
/// <param name="count">The number of items to include in each segment.
/// The last segment might contain fewer items.</param>
public static IEnumerable<TSource[]> Split<TSource>(this IEnumerable<TSource> source, int count)
#region: Split :

/// <summary>Splits the enumeration into segments,
/// each segment containing [count] items, and the last segment containing the remainder.
/// </summary>
/// <param name="source"></param>
/// <param name="count">The number of items to include in each segment.
/// The last segment might contain fewer items.</param>
public static IEnumerable<TSource[]> Split<TSource>(this IEnumerable<TSource> source, int count)
{
ArgumentValidator.CheckForNullReference(source, "source");
ArgumentValidator.CheckForZeroValue(count, "count");
Expand Down
2 changes: 2 additions & 0 deletions src/Demo/ThirdParty/RTFLib/RTFImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace RTF
{
using System;
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
Expand Down Expand Up @@ -79,6 +80,7 @@ public RTFImage(RTFBuilder builder)
/// <param name="_flags">
/// Flags used to specify the format of the Windows Metafile returned
/// </param>
[SuppressMessage("Security", "CA5392:P/invoke methods should not be visible", Justification = "Method is safe.")]
[DllImport("gdiplus.dll")]
private static extern uint GdipEmfToWmfBits(IntPtr _hEmf, uint _bufferSize, byte[] _buffer, int _mappingMode, EmfToWmfBitsFlags _flags);

Expand Down
1 change: 0 additions & 1 deletion src/Performance/Performance.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<ItemGroup>
<ProjectReference Include="..\SmartFormat.Extensions.Newtonsoft.Json\SmartFormat.Extensions.Newtonsoft.Json.csproj" />
<ProjectReference Include="..\SmartFormat.Extensions.System.Text.Json\SmartFormat.Extensions.System.Text.Json.csproj" />
<ProjectReference Include="..\SmartFormat.ZString\SmartFormat.ZString.csproj" />
<ProjectReference Include="..\SmartFormat\SmartFormat.csproj" />
</ItemGroup>

Expand Down
10 changes: 0 additions & 10 deletions src/SmartFormat.Deploy.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SmartFormat.Extensions.Time
EndProject
# Include SmartFormat.ZString in the Deploy Sln File in order to get the release assembly into the SmartFormat.csproj package.
# The SmartFormat.ZString.csproj is marked with IsPackable=false, so no nupkg/snupkg will be created.
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SmartFormat.ZString", "SmartFormat.ZString\SmartFormat.ZString.csproj", "{A15DAB96-3884-4063-9D1C-47367D408842}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -75,14 +73,6 @@ Global
{62553041-4606-47FC-B44E-8D6D51F23E22}.Release|Any CPU.Build.0 = Release|Any CPU
{62553041-4606-47FC-B44E-8D6D51F23E22}.Release|x86.ActiveCfg = Release|Any CPU
{62553041-4606-47FC-B44E-8D6D51F23E22}.Release|x86.Build.0 = Release|Any CPU
{A15DAB96-3884-4063-9D1C-47367D408842}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A15DAB96-3884-4063-9D1C-47367D408842}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A15DAB96-3884-4063-9D1C-47367D408842}.Debug|x86.ActiveCfg = Debug|Any CPU
{A15DAB96-3884-4063-9D1C-47367D408842}.Debug|x86.Build.0 = Debug|Any CPU
{A15DAB96-3884-4063-9D1C-47367D408842}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A15DAB96-3884-4063-9D1C-47367D408842}.Release|Any CPU.Build.0 = Release|Any CPU
{A15DAB96-3884-4063-9D1C-47367D408842}.Release|x86.ActiveCfg = Release|Any CPU
{A15DAB96-3884-4063-9D1C-47367D408842}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 2 additions & 2 deletions src/SmartFormat.Tests/Core/Output/NullOutputTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public void Output_Of_String()
[Test]
public void Output_Of_ValueStringBuilder()
{
using var sb = SmartFormat.Utilities.ZStringBuilderExtensions.CreateZStringBuilder();
using var sb = ZString.ZStringBuilderUtilities.CreateZStringBuilder();
sb.Append("text");
var so = new NullOutput();
Assert.DoesNotThrow(() =>so.Write(sb, null));
}
}
}
4 changes: 2 additions & 2 deletions src/SmartFormat.Tests/Core/Output/StringOutputTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public void Output_Of_String()
public void Output_Of_ValueStringBuilder()
{
var so = new StringOutput();
using var sb = SmartFormat.Utilities.ZStringBuilderExtensions.CreateZStringBuilder();
using var sb = ZString.ZStringBuilderUtilities.CreateZStringBuilder();
sb.Append("text");
so.Write(sb, null!);
Assert.That(so.ToString(), Is.EqualTo("text"));
}
}
}
4 changes: 2 additions & 2 deletions src/SmartFormat.Tests/Core/Output/TextWriterOutputTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public void Output_Of_String()
[Test]
public void Output_Of_ValueStringBuilder()
{
using var sb = SmartFormat.Utilities.ZStringBuilderExtensions.CreateZStringBuilder();
using var sb = ZString.ZStringBuilderUtilities.CreateZStringBuilder();
sb.Append("text");
var sw = new StringWriter(new StringBuilder());
var two = new TextWriterOutput(sw);
two.Write(sb, null);
sw.Flush();
Assert.That(sw.ToString(), Is.EqualTo("text"));
}
}
}
8 changes: 4 additions & 4 deletions src/SmartFormat.Tests/Core/Output/ZStringOutputTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ZStringOutputTests
[Test]
public void Create_With_Capacity()
{
using var zStringOutput = new ZStringOutput(SmartFormat.Utilities.ZStringBuilderExtensions.DefaultBufferSize + 10000);
using var zStringOutput = new ZStringOutput(ZString.ZStringBuilderUtilities.DefaultBufferSize + 10000);
Assert.Multiple(() =>
{
Assert.That(zStringOutput.Output, Is.InstanceOf<ZStringBuilder>());
Expand All @@ -22,7 +22,7 @@ public void Create_With_Capacity()
[Test]
public void Create_With_Other_ValueStringBuilder()
{
using var vsb = SmartFormat.Utilities.ZStringBuilderExtensions.CreateZStringBuilder();
using var vsb = ZString.ZStringBuilderUtilities.CreateZStringBuilder();
vsb.Append("text");
using var zStringOutput = new ZStringOutput(vsb);
Assert.That(zStringOutput, Is.Not.Null);
Expand All @@ -49,9 +49,9 @@ public void Output_Of_String()
public void Output_Of_ValueStringBuilder()
{
var so = new ZStringOutput();
using var sb = SmartFormat.Utilities.ZStringBuilderExtensions.CreateZStringBuilder();
using var sb = ZString.ZStringBuilderUtilities.CreateZStringBuilder();
sb.Append("text");
so.Write(sb, null);
Assert.That(so.ToString(), Is.EqualTo("text"));
}
}
}
1 change: 0 additions & 1 deletion src/SmartFormat.Tests/SmartFormat.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@

<ItemGroup>
<ProjectReference Include="..\SmartFormat.Net\SmartFormat.Net.csproj" />
<ProjectReference Include="..\SmartFormat.ZString\SmartFormat.ZString.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 693243b

Please sign in to comment.