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 |
No files matched your search
@@ -6,7 +6,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<Authors>ds5678</Authors>
|
||||
<Company>AssetRipper</Company>
|
||||
<Version>3.1.2</Version>
|
||||
<Version>3.1.3</Version>
|
||||
<AssemblyVersion>$(Version)</AssemblyVersion>
|
||||
<PackageId>AssetRipper.Primitives</PackageId>
|
||||
<PackageTags>C# assetripper unity unity3d</PackageTags>
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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