Compare commits

...
21 Commits
Author SHA1 Message Date
ds5678 57912c52f1 Update version to 3.1.5 and adjust project properties
- Bump version number from 3.1.4 to 3.1.5.
- Update copyright year to 2025.
- Add property group for trimmability with net6.0.
- Modify AOT compatibility check for net8.0.
2025-02-13 16:03:05 -08:00
ds5678 5ab5d744d6 UnityVersion : IParsable<UnityVersion> 2025-02-13 15:57:20 -08:00
ds5678 cd7f841845 Json serialization support for UnityVersion 2025-02-13 15:56:24 -08:00
ds5678 9a5f8bb707 .NET 9 support 2025-02-13 15:47:09 -08:00
dependabot[bot] 089c71d944 Bump actions/setup-dotnet from 4.1.0 to 4.3.0
Bumps [actions/setup-dotnet](https://github.com/actions/setup-dotnet) from 4.1.0 to 4.3.0.
- [Release notes](https://github.com/actions/setup-dotnet/releases)
- [Commits](https://github.com/actions/setup-dotnet/compare/v4.1.0...v4.3.0)

---
updated-dependencies:
- dependency-name: actions/setup-dotnet
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
2025-02-13 18:44:41 -05:00
ds5678 919fa0d5ab Don't bother testing .NET 5 2025-02-13 15:40:27 -08:00
ds5678 df8c5e2879 All frameworks 2025-02-13 15:34:49 -08:00
ds5678 13ece60907 Remove dotnet restore 2025-02-13 15:26:28 -08:00
ds5678 3a46414f08 .net 8 only 2025-02-13 15:24:08 -08:00
ds5678 bc556b7c72 .net 8 2025-02-13 15:23:01 -08:00
ds5678 7147a5d5b1 Strings instead of floats 2025-02-13 15:21:08 -08:00
ds5678 776ab543fa Use a build matrix 2025-02-13 15:18:48 -08:00
ds5678 ca701a43dc Bump version 2024-12-19 13:51:34 -08:00
ds5678 f478cd8015 Make regexes more strict 2024-12-19 13:50:51 -08:00
dependabot[bot] 8cd69e8946 Bump actions/setup-dotnet from 4.0.1 to 4.1.0
Bumps [actions/setup-dotnet](https://github.com/actions/setup-dotnet) from 4.0.1 to 4.1.0.
- [Release notes](https://github.com/actions/setup-dotnet/releases)
- [Commits](https://github.com/actions/setup-dotnet/compare/v4.0.1...v4.1.0)

---
updated-dependencies:
- dependency-name: actions/setup-dotnet
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
2024-12-19 13:32:52 -08:00
dependabot[bot] 3cba893ff2 Bump actions/setup-dotnet from 4.0.0 to 4.0.1
Bumps [actions/setup-dotnet](https://github.com/actions/setup-dotnet) from 4.0.0 to 4.0.1.
- [Release notes](https://github.com/actions/setup-dotnet/releases)
- [Commits](https://github.com/actions/setup-dotnet/compare/v4.0.0...v4.0.1)

---
updated-dependencies:
- dependency-name: actions/setup-dotnet
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
2024-08-06 21:29:50 -07:00
ds5678 9c4a7d8127 Bump version 2024-08-06 19:42:08 -07:00
ds5678 fd3590ad52 Tiered Regex compilation 2024-08-06 19:37:36 -07:00
ds5678 3ef5dae9d4 IEqualityOperators 2024-06-09 16:57:21 -07:00
ds5678 78ecfb7de4 Bump version 2024-05-31 07:23:23 -07:00
ds5678 5080b7eb29 Add net461 target 2024-05-31 07:17:06 -07:00
11 changed files with 174 additions and 85 deletions

No files matched your search

+12 -57
View File
@@ -7,70 +7,25 @@ on:
branches: [ master ]
jobs:
net8:
build-and-test:
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: ["9.0", "8.0", "7.0", "6.0"]
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4.0.0
uses: actions/setup-dotnet@v4.3.0
with:
dotnet-version: 8.0.x
dotnet-version: |
6.0.x
7.0.x
8.0.x
9.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --framework net8.0 --no-restore
run: dotnet build --framework net${{ matrix.dotnet-version }} --no-restore
- name: Test
run: dotnet test --framework net8.0 --no-build --verbosity normal
net7:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/[email protected]
with:
dotnet-version: 7.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --framework net7.0 --no-restore
- name: Test
run: dotnet test --framework net7.0 --no-build --verbosity normal
net6:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/[email protected]
with:
dotnet-version: 6.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --framework net6.0 --no-restore
- name: Test
run: dotnet test --framework net6.0 --no-build --verbosity normal
net5:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/[email protected]
with:
dotnet-version: 5.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --framework net5.0 --no-restore
- name: Test
run: dotnet test --framework net5.0 --no-build --verbosity normal
run: dotnet test --framework net${{ matrix.dotnet-version }} --no-build --verbosity normal
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netframework3.5;netframework4.0;netframework4.8;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net35;net40;net48;net5.0;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<LangVersion>Latest</LangVersion>
<Nullable>enable</Nullable>
@@ -73,6 +73,22 @@ public class ParsingTests
});
}
[TestCase("g2019")]
[TestCase("g2019.4")]
[TestCase("g2019.4.3")]
[TestCase("g2019.4.3f")]
[TestCase("g2019.4.3f1")]
[TestCase("g2019.4.3f1c1")]
[TestCase("2019g")]
[TestCase("2019.4g")]
[TestCase("2019.4.3g")]
[TestCase("2019.4.3fg")]
// "2019.4.3f1g" and "2019.4.3f1c1g" are technically valid because custom engines often append some text to the version string.
public void InvalidVersionStringFailsToParse(string versionString)
{
Assert.That(UnityVersion.TryParse(versionString, out _, out _), Is.False);
}
private static IEnumerable<UnityVersion> GenerateRandomVersions(int count)
{
Randomizer random = TestContext.CurrentContext.Random;
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netframework3.5;netframework4.0;netstandard2.0;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net35;net40;net461;netstandard2.0;net5.0;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<LangVersion>Latest</LangVersion>
<Nullable>enable</Nullable>
<Authors>ds5678</Authors>
<Company>AssetRipper</Company>
<Version>3.1.1</Version>
<Version>3.1.5</Version>
<AssemblyVersion>$(Version)</AssemblyVersion>
<PackageId>AssetRipper.Primitives</PackageId>
<PackageTags>C# assetripper unity unity3d</PackageTags>
@@ -14,18 +14,18 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryType>git</RepositoryType>
<PackageProjectUrl>https://github.com/AssetRipper/AssetRipper.Primitives</PackageProjectUrl>
<Copyright>Copyright (c) 2022-2024 ds5678</Copyright>
<Copyright>Copyright (c) 2022-2025 ds5678</Copyright>
<Description>Managed library for primitive types used in AssetRipper.</Description>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>1591</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' != 'netframework3.5' and '$(TargetFramework)' != 'netframework4.0' ">
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>
@@ -40,7 +40,7 @@
</PackageReference>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'net461'">
<PackageReference Include="Microsoft.Bcl.HashCode">
<Version>1.1.1</Version>
</PackageReference>
@@ -49,4 +49,10 @@
</PackageReference>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<PackageReference Include="System.ValueTuple">
<Version>4.5.0</Version>
</PackageReference>
</ItemGroup>
</Project>
+4 -1
View File
@@ -1,4 +1,4 @@
#if NET5_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER
#if NET5_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET461_OR_GREATER
using System.Buffers.Binary;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
@@ -13,6 +13,9 @@ namespace AssetRipper.Primitives;
[System.Text.Json.Serialization.JsonConverter(typeof(UnityGuidJsonConverter))]
#endif
public readonly record struct UnityGuid
#if NET7_0_OR_GREATER
: System.Numerics.IEqualityOperators<UnityGuid, UnityGuid, bool>
#endif
{
public UnityGuid(Guid guid)
{
+15 -1
View File
@@ -2,10 +2,24 @@
using System.Numerics;
namespace AssetRipper.Primitives;
partial struct UnityVersion : IComparisonOperators<UnityVersion, UnityVersion, bool>, IEqualityOperators<UnityVersion, UnityVersion, bool>, IMinMaxValue<UnityVersion>
partial struct UnityVersion :
IComparisonOperators<UnityVersion, UnityVersion, bool>,
IEqualityOperators<UnityVersion, UnityVersion, bool>,
IMinMaxValue<UnityVersion>,
IParsable<UnityVersion>
{
static UnityVersion IMinMaxValue<UnityVersion>.MaxValue => MaxVersion;
static UnityVersion IMinMaxValue<UnityVersion>.MinValue => MinVersion;
static UnityVersion IParsable<UnityVersion>.Parse(string s, IFormatProvider? provider)
{
return Parse(s);
}
static bool IParsable<UnityVersion>.TryParse(string? s, IFormatProvider? provider, out UnityVersion result)
{
return TryParse(s, out result, out _);
}
}
#endif
@@ -0,0 +1,10 @@
#if NET5_0_OR_GREATER
using System.Text.Json.Serialization;
namespace AssetRipper.Primitives;
[JsonConverter(typeof(UnityVersionJsonConverter))]
partial struct UnityVersion
{
}
#endif
+7 -14
View File
@@ -2,15 +2,8 @@
using System.Text.RegularExpressions;
namespace AssetRipper.Primitives;
public readonly partial struct UnityVersion
{
private static readonly Regex majorRegex = new Regex(@"^([0-9]+)$", RegexOptions.Compiled);
private static readonly Regex majorMinorRegex = new Regex(@"^([0-9]+)\.([0-9]+)$", RegexOptions.Compiled);
private static readonly Regex majorMinorBuildRegex = new Regex(@"^([0-9]+)\.([0-9]+)\.([0-9]+)$", RegexOptions.Compiled);
private static readonly Regex normalRegex = new Regex(@"^([0-9]+)\.([0-9]+)\.([0-9]+)\.?([abcfpx])([0-9]+)((?:.|[\r\n])+)?$", RegexOptions.Compiled);
private static readonly Regex chinaRegex = new Regex(@"^([0-9]+)\.([0-9]+)\.([0-9]+)\.?f1c([0-9]+)((?:.|[\r\n])+)?$", RegexOptions.Compiled);
/// <summary>
/// Serialize the version as a string using <see cref="UnityVersionFormatFlags.Default"/>.
/// </summary>
@@ -91,15 +84,15 @@ public readonly partial struct UnityVersion
/// <param name="version">The parsed Unity version</param>
/// <param name="customEngine">Not null if this version was generated by a custom Unity Engine.</param>
/// <returns>True if parsing was successful</returns>
public static bool TryParse(string s, out UnityVersion version, out string? customEngine)
public static bool TryParse(string? s, out UnityVersion version, out string? customEngine)
{
if (string.IsNullOrEmpty(s))
if (s is null || s.Length is 0)
{
customEngine = null;
version = default;
return false;
}
else if (chinaRegex.TryMatch(s, out Match? match))
else if (UnityVersionRegexes.GetChinaRegex().TryMatch(s, out Match? match))
{
int major = int.Parse(match.Groups[1].Value);
int minor = int.Parse(match.Groups[2].Value);
@@ -109,7 +102,7 @@ public readonly partial struct UnityVersion
version = new UnityVersion((ushort)major, (ushort)minor, (ushort)build, UnityVersionType.China, (byte)typeNumber);
return true;
}
else if(normalRegex.TryMatch(s, out match))
else if(UnityVersionRegexes.GetNormalRegex().TryMatch(s, out match))
{
int major = int.Parse(match.Groups[1].Value);
int minor = int.Parse(match.Groups[2].Value);
@@ -120,7 +113,7 @@ public readonly partial struct UnityVersion
version = new UnityVersion((ushort)major, (ushort)minor, (ushort)build, type.ToUnityVersionType(), (byte)typeNumber);
return true;
}
else if (majorMinorBuildRegex.TryMatch(s, out match))
else if (UnityVersionRegexes.GetMajorMinorBuildRegex().TryMatch(s, out match))
{
int major = int.Parse(match.Groups[1].Value);
int minor = int.Parse(match.Groups[2].Value);
@@ -131,7 +124,7 @@ public readonly partial struct UnityVersion
: default;
return true;
}
else if (majorMinorRegex.TryMatch(s, out match))
else if (UnityVersionRegexes.GetMajorMinorRegex().TryMatch(s, out match))
{
int major = int.Parse(match.Groups[1].Value);
int minor = int.Parse(match.Groups[2].Value);
@@ -141,7 +134,7 @@ public readonly partial struct UnityVersion
: default;
return true;
}
else if (majorRegex.TryMatch(s, out match))
else if (UnityVersionRegexes.GetMajorRegex().TryMatch(s, out match))
{
int major = int.Parse(match.Groups[1].Value);
customEngine = null;
@@ -0,0 +1,19 @@
#if NET5_0_OR_GREATER
using System.Text.Json;
using System.Text.Json.Serialization;
namespace AssetRipper.Primitives;
public sealed class UnityVersionJsonConverter : JsonConverter<UnityVersion>
{
public override UnityVersion Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return UnityVersion.Parse(reader.GetString() ?? throw new JsonException("String was read as null"));
}
public override void Write(Utf8JsonWriter writer, UnityVersion value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString());
}
}
#endif
@@ -0,0 +1,68 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.RegularExpressions;
namespace AssetRipper.Primitives;
internal static partial class UnityVersionRegexes
{
#if NET35
private const RegexOptions Options = RegexOptions.None;
#else
private const RegexOptions Options = RegexOptions.Compiled;
#endif
[StringSyntax("regex")]
private const string Major = @"^([0-9]+)$";
[StringSyntax("regex")]
private const string MajorMinor = @"^([0-9]+)\.([0-9]+)$";
[StringSyntax("regex")]
private const string MajorMinorBuild = @"^([0-9]+)\.([0-9]+)\.([0-9]+)$";
[StringSyntax("regex")]
private const string Normal = @"^([0-9]+)\.([0-9]+)\.([0-9]+)\.?([abcfpx])([0-9]+)((?:.|[\r\n])+)?$";
[StringSyntax("regex")]
private const string China = @"^([0-9]+)\.([0-9]+)\.([0-9]+)\.?f1c([0-9]+)((?:.|[\r\n])+)?$";
#if NET7_0_OR_GREATER
[GeneratedRegex(Major, Options)]
public static partial Regex GetMajorRegex();
#else
private static readonly Regex majorRegex = new Regex(Major, Options);
public static Regex GetMajorRegex() => majorRegex;
#endif
#if NET7_0_OR_GREATER
[GeneratedRegex(MajorMinor, Options)]
public static partial Regex GetMajorMinorRegex();
#else
private static readonly Regex majorMinorRegex = new Regex(MajorMinor, Options);
public static Regex GetMajorMinorRegex() => majorMinorRegex;
#endif
#if NET7_0_OR_GREATER
[GeneratedRegex(MajorMinorBuild, Options)]
public static partial Regex GetMajorMinorBuildRegex();
#else
private static readonly Regex majorMinorBuildRegex = new Regex(MajorMinorBuild, Options);
public static Regex GetMajorMinorBuildRegex() => majorMinorBuildRegex;
#endif
#if NET7_0_OR_GREATER
[GeneratedRegex(Normal, Options)]
public static partial Regex GetNormalRegex();
#else
private static readonly Regex normalRegex = new Regex(Normal, Options);
public static Regex GetNormalRegex() => normalRegex;
#endif
#if NET7_0_OR_GREATER
[GeneratedRegex(China, Options)]
public static partial Regex GetChinaRegex();
#else
private static readonly Regex chinaRegex = new Regex(China, Options);
public static Regex GetChinaRegex() => chinaRegex;
#endif
}
+7 -2
View File
@@ -1,4 +1,4 @@
#if NET5_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER
#if NET5_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER || NET461_OR_GREATER
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;
@@ -11,7 +11,12 @@ namespace AssetRipper.Primitives;
/// <remarks>
/// Conversions to and from <see cref="string"/> are handled by <see cref="Encoding.UTF8"/>.
/// </remarks>
public sealed class Utf8String : IEquatable<Utf8String>
public sealed class Utf8String :
#if NET7_0_OR_GREATER
System.Numerics.IEqualityOperators<Utf8String?, Utf8String?, bool>,
System.Numerics.IEqualityOperators<Utf8String?, string?, bool>,
#endif
IEquatable<Utf8String>
{
private readonly byte[] data;
private string? cachedString;