mirror of
https://github.com/AssetRipper/AssetRipper.Primitives.git
synced 2026-11-13 04:26:30 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c4a7d8127 | ||
|
|
fd3590ad52 | ||
|
|
3ef5dae9d4 | ||
|
|
78ecfb7de4 | ||
|
|
5080b7eb29 |
No files matched your search
@@ -1,7 +1,7 @@
|
||||
<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</TargetFrameworks>
|
||||
<LangVersion>Latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
|
||||
@@ -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</TargetFrameworks>
|
||||
<LangVersion>Latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<Authors>ds5678</Authors>
|
||||
<Company>AssetRipper</Company>
|
||||
<Version>3.1.1</Version>
|
||||
<Version>3.1.3</Version>
|
||||
<AssemblyVersion>$(Version)</AssemblyVersion>
|
||||
<PackageId>AssetRipper.Primitives</PackageId>
|
||||
<PackageTags>C# assetripper unity unity3d</PackageTags>
|
||||
@@ -21,7 +21,7 @@
|
||||
<NoWarn>1591</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(TargetFramework)' != 'netframework3.5' and '$(TargetFramework)' != 'netframework4.0' ">
|
||||
<PropertyGroup Condition=" '$(TargetFramework)' != 'net35' and '$(TargetFramework)' != 'net40' ">
|
||||
<IsTrimmable>true</IsTrimmable>
|
||||
</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>
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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>
|
||||
@@ -99,7 +92,7 @@ public readonly partial struct UnityVersion
|
||||
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,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
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user