mirror of
https://github.com/AssetRipper/AssetRipper.Primitives.git
synced 2026-11-13 04:26:30 -10:00
Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa6517ba7a | ||
|
|
7091ff7f36 | ||
|
|
3377fa0bea | ||
|
|
d759b3db98 | ||
|
|
55b3294ff5 | ||
|
|
c3ff29e8d7 | ||
|
|
61f47faf04 |
No files matched your search
@@ -14,9 +14,9 @@ jobs:
|
||||
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.3.0
|
||||
uses: actions/setup-dotnet@v5.3.0
|
||||
with:
|
||||
dotnet-version: |
|
||||
6.0.x
|
||||
|
||||
@@ -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,7 +6,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<Authors>ds5678</Authors>
|
||||
<Company>AssetRipper</Company>
|
||||
<Version>3.1.5</Version>
|
||||
<Version>3.2.0</Version>
|
||||
<AssemblyVersion>$(Version)</AssemblyVersion>
|
||||
<PackageId>AssetRipper.Primitives</PackageId>
|
||||
<PackageTags>C# assetripper unity unity3d</PackageTags>
|
||||
|
||||
@@ -11,12 +11,15 @@ namespace AssetRipper.Primitives;
|
||||
/// <remarks>
|
||||
/// Conversions to and from <see cref="string"/> are handled by <see cref="Encoding.UTF8"/>.
|
||||
/// </remarks>
|
||||
#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>,
|
||||
System.Numerics.IEqualityOperators<Utf8String?, string?, bool>,
|
||||
#endif
|
||||
IEquatable<Utf8String>
|
||||
IEquatable<Utf8String>
|
||||
{
|
||||
private readonly byte[] data;
|
||||
private string? cachedString;
|
||||
@@ -28,7 +31,7 @@ public sealed class Utf8String :
|
||||
/// </summary>
|
||||
public Utf8String()
|
||||
{
|
||||
data = Array.Empty<byte>();
|
||||
data = [];
|
||||
cachedString = "";
|
||||
}
|
||||
|
||||
@@ -108,8 +111,10 @@ public sealed class 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
|
||||
Reference in new issue
Block a user