Compare commits

...
6 Commits
Author SHA1 Message Date
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
5 changed files with 38 additions and 14 deletions

No files matched your search

+2 -2
View File
@@ -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.1.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>
+9 -4
View File
@@ -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