Compare commits

...
Author SHA1 Message Date
dependabot[bot] aa6517ba7a Bump actions/setup-dotnet from 5.1.0 to 5.3.0
Bumps [actions/setup-dotnet](https://github.com/actions/setup-dotnet) from 5.1.0 to 5.3.0.
- [Release notes](https://github.com/actions/setup-dotnet/releases)
- [Commits](https://github.com/actions/setup-dotnet/compare/v5.1.0...v5.3.0)

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

Signed-off-by: dependabot[bot] <[email protected]>
2026-05-28 20:25:59 +00:00
dependabot[bot] 7091ff7f36 Bump actions/checkout from 4 to 6
Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 6.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v4...v6)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
2026-01-14 12:08:29 -08:00
dependabot[bot] 3377fa0bea Bump actions/setup-dotnet from 4.3.0 to 5.1.0
Bumps [actions/setup-dotnet](https://github.com/actions/setup-dotnet) from 4.3.0 to 5.1.0.
- [Release notes](https://github.com/actions/setup-dotnet/releases)
- [Commits](https://github.com/actions/setup-dotnet/compare/v4.3.0...v5.1.0)

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

Signed-off-by: dependabot[bot] <[email protected]>
2026-01-14 12:07:30 -08:00
ds5678 d759b3db98 Bump version to 3.2.0 in AssetRipper.Primitives.csproj
Updated the package version from 3.1.6 to 3.2.0 to reflect the latest changes and improvements.
2025-04-28 20:42:46 -07:00
ds5678 55b3294ff5 Explicit conversion for Utf8String from ReadOnlySpan 2025-04-28 20:42:03 -07:00
ds5678 c3ff29e8d7 Bump version to 3.1.6 in project file
Updated the version number from 3.1.5 to 3.1.6 in the AssetRipper.Primitives.csproj file.
2025-02-22 21:43:28 -08:00
ds5678 61f47faf04 Utf8StringJsonConverter 2025-02-22 21:42:49 -08:00
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
ds5678 2e8940973f Bump version 2024-05-19 17:40:14 -04:00
ds5678 64f50b46fb Add .NET 8 to the CI workflow 2024-05-19 17:34:41 -04:00
ds5678 fbdda777ac Remove package reference to System.Text.Json 2024-05-19 17:32:46 -04:00
ds5678 2de06bfaf4 .NET target 2024-05-19 17:28:57 -04:00
ds5678 c7a8932863 Remove benchmarks 2024-05-19 17:25:33 -04:00
18 changed files with 212 additions and 178 deletions

No files matched your search

+13 -43
View File
@@ -7,55 +7,25 @@ on:
branches: [ master ]
jobs:
net7:
build-and-test:
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: ["9.0", "8.0", "7.0", "6.0"]
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- name: Setup .NET
uses: actions/setup-dotnet@v4.0.0
uses: actions/setup-dotnet@v5.3.0
with:
dotnet-version: 7.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 net7.0 --no-restore
run: dotnet build --framework net${{ matrix.dotnet-version }} --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
6.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,15 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<LangVersion>Latest</LangVersion>
<TargetFrameworks>net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
</ItemGroup>
</Project>
@@ -1,11 +0,0 @@
using BenchmarkDotNet.Running;
namespace AssetRipper.Primitives.Benckmarks;
internal static class Program
{
static void Main()
{
BenchmarkRunner.Run(typeof(Program).Assembly);
}
}
@@ -1,46 +0,0 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using System.Runtime.CompilerServices;
namespace AssetRipper.Primitives.Benckmarks;
[SimpleJob(RuntimeMoniker.Net80)]
[RPlotExporter]
public class YearVersionCheck
{
[Params(4, 5, 6, 7, 2016, 2017, 2018, 2022, 2023, 2024)]
public ushort Major;
[Benchmark]
public bool Simple() => Major is >= 2017 and <= 2023;
[Benchmark]
public bool BitsWith2016() => BitComparison(Major);
[Benchmark]
public bool BitsWithout2016() => BitComparison(Major) && Major is not 2016;
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
private static bool BitComparison(uint value)
{
//This function determines if an unsigned integer
//is between 2016 and 2023, inclusive. It does this
//by comparing bits of the value with know constants.
const uint VariableBitMask = 0x7;
const uint FixedBitMask = ~VariableBitMask;
const uint ExpectedFixedBits = 0x7E0;//2016
return (value & FixedBitMask) == ExpectedFixedBits;
}
/* Results:
* Due to the simplicity of the methods being profiled,
* benchmarking was inconclusive. The costs of calling
* these methods are almost neglible.
*
* Decision:
* For the time being, the library will continue to use
* the simple bounds check. If another option is shown
* to be significantly better, I am open to switching.
*/
}
@@ -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</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;
@@ -33,7 +33,7 @@ public class Utf8StringTests
[Test]
public void Utf8StringMadeFromUtf8LiteralIsTheSameAsMadeFromConstantString()
{
Utf8String dataString = "AssetRipperTestString"u8;
Utf8String dataString = (Utf8String)"AssetRipperTestString"u8;
Utf8String systemString = "AssetRipperTestString";
Assert.That(dataString, Is.EqualTo(systemString));
}
@@ -41,7 +41,7 @@ public class Utf8StringTests
[Test]
public void ConcatenationBetweenTwoUtf8StringsWorks()
{
Utf8String dataString = "AssetRipperTestString"u8;
Utf8String dataString = (Utf8String)"AssetRipperTestString"u8;
Utf8String systemString = "AssetRipperTestString";
Utf8String concatenated = dataString + systemString;
Assert.That(concatenated, Is.EqualTo((Utf8String)"AssetRipperTestStringAssetRipperTestString"u8));
@@ -58,10 +58,10 @@ public class Utf8StringTests
[Test]
public void ConcatenationBetweenFourUtf8StringsWorks()
{
Utf8String string1 = "hello"u8;
Utf8String string2 = " world"u8;
Utf8String string3 = "!"u8;
Utf8String string4 = ", how are you?"u8;
Utf8String string1 = (Utf8String)"hello"u8;
Utf8String string2 = (Utf8String)" world"u8;
Utf8String string3 = (Utf8String)"!"u8;
Utf8String string4 = (Utf8String)", how are you?"u8;
Utf8String concatenated = Utf8String.Concat(string1, string2, string3, string4);
Assert.That(concatenated, Is.EqualTo((Utf8String)"hello world!, how are you?"u8));
}
@@ -81,7 +81,7 @@ public class Utf8StringTests
[Test]
public void IsNullOrEmptyReturnsFalseForNonEmptyString()
{
Assert.That(Utf8String.IsNullOrEmpty("AssetRipperTestString"u8), Is.False);
Assert.That(Utf8String.IsNullOrEmpty((Utf8String)"AssetRipperTestString"u8), Is.False);
}
}
#endif
-6
View File
@@ -24,8 +24,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AssetRipper.Primitives", "A
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AssetRipper.Primitives.Tests", "AssetRipper.Primitives.Tests\AssetRipper.Primitives.Tests.csproj", "{545E670D-141B-4F05-9AFD-2F184A59EADC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AssetRipper.Primitives.Benckmarks", "AssetRipper.Primitives.Benckmarks\AssetRipper.Primitives.Benckmarks.csproj", "{E3DEB571-4EE4-4C89-9005-DB10D9FB561B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -40,10 +38,6 @@ Global
{545E670D-141B-4F05-9AFD-2F184A59EADC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{545E670D-141B-4F05-9AFD-2F184A59EADC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{545E670D-141B-4F05-9AFD-2F184A59EADC}.Release|Any CPU.Build.0 = Release|Any CPU
{E3DEB571-4EE4-4C89-9005-DB10D9FB561B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E3DEB571-4EE4-4C89-9005-DB10D9FB561B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E3DEB571-4EE4-4C89-9005-DB10D9FB561B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E3DEB571-4EE4-4C89-9005-DB10D9FB561B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -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</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.0</Version>
<Version>3.2.0</Version>
<AssemblyVersion>$(Version)</AssemblyVersion>
<PackageId>AssetRipper.Primitives</PackageId>
<PackageTags>C# assetripper unity unity3d</PackageTags>
@@ -14,17 +14,21 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryType>git</RepositoryType>
<PackageProjectUrl>https://github.com/AssetRipper/AssetRipper.Primitives</PackageProjectUrl>
<Copyright>Copyright (c) 2022-2023 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="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
@@ -36,33 +40,18 @@
</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>
<PackageReference Include="System.Memory">
<Version>4.5.5</Version>
</PackageReference>
<PackageReference Include="System.Text.Json">
<Version>8.0.1</Version>
</PackageReference>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
<PackageReference Include="System.Text.Json">
<Version>8.0.1</Version>
</PackageReference>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="System.Text.Json">
<Version>8.0.1</Version>
</PackageReference>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
<PackageReference Include="System.Text.Json">
<Version>8.0.1</Version>
<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<PackageReference Include="System.ValueTuple">
<Version>4.5.0</Version>
</PackageReference>
</ItemGroup>
+7 -3
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;
@@ -6,12 +6,16 @@ using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Text.Json.Serialization;
namespace AssetRipper.Primitives;
[JsonConverter(typeof(UnityGuidJsonConverter))]
#if NET5_0_OR_GREATER
[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)
{
@@ -1,4 +1,4 @@
#if NET5_0_OR_GREATER || NETSTANDARD2_0_OR_GREATER
#if NET5_0_OR_GREATER
using System.Text.Json;
using System.Text.Json.Serialization;
+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
}
+14 -4
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,15 @@ 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>
#if NET5_0_OR_GREATER
[System.Text.Json.Serialization.JsonConverter(typeof(Utf8StringJsonConverter))]
#endif
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;
@@ -23,7 +31,7 @@ public sealed class Utf8String : IEquatable<Utf8String>
/// </summary>
public Utf8String()
{
data = Array.Empty<byte>();
data = [];
cachedString = "";
}
@@ -103,8 +111,10 @@ public sealed class Utf8String : IEquatable<Utf8String>
return utf8String?.String;
}
public static implicit operator Utf8String(ReadOnlySpan<byte> data)
public static explicit operator Utf8String(ReadOnlySpan<byte> data)
{
// Explicit conversion because of first class spans
// https://github.com/dotnet/roslyn/issues/78314
return data.Length == 0 ? Empty : new Utf8String(data);
}
@@ -0,0 +1,19 @@
#if NET5_0_OR_GREATER
using System.Text.Json;
using System.Text.Json.Serialization;
namespace AssetRipper.Primitives;
public sealed class Utf8StringJsonConverter : JsonConverter<Utf8String>
{
public override Utf8String Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return reader.GetString() ?? throw new JsonException("String was read as null");
}
public override void Write(Utf8JsonWriter writer, Utf8String value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString());
}
}
#endif