-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
20d6bf3
commit 7478b30
Showing
22 changed files
with
276 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/Intermediate/Rxmxnx.PInvoke.CString.Intermediate/CStringSequence/CStringSpanState.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace Rxmxnx.PInvoke; | ||
|
||
[SuppressMessage(SuppressMessageConstants.CSharpSquid, SuppressMessageConstants.CheckIdS6640)] | ||
public unsafe partial class CStringSequence | ||
{ | ||
/// <summary> | ||
/// State for pinned <see cref="CString"/> span. | ||
/// </summary> | ||
internal readonly struct CStringSpanState | ||
{ | ||
#pragma warning disable CS8500 | ||
/// <summary> | ||
/// <see cref="CString"/> pointer. | ||
/// </summary> | ||
public CString?* Ptr { get; init; } | ||
/// <summary> | ||
/// Span length. | ||
/// </summary> | ||
public Int32 Length { get; init; } | ||
#pragma warning restore CS8500 | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/Intermediate/Rxmxnx.PInvoke.CString.Intermediate/CStringSequence/CStringStringState.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
namespace Rxmxnx.PInvoke; | ||
|
||
public partial class CStringSequence | ||
{ | ||
/// <summary> | ||
/// State for temporal functional <see cref="CString"/>. | ||
/// </summary> | ||
internal readonly struct CStringStringState(String value) : IUtf8FunctionState<CStringStringState> | ||
{ | ||
/// <summary> | ||
/// Internal text value. | ||
/// </summary> | ||
private readonly String _value = value; | ||
/// <summary> | ||
/// Internal text UTF-8 length. | ||
/// </summary> | ||
private readonly Int32 _utf8Length = Encoding.UTF8.GetByteCount(value); | ||
|
||
Boolean IUtf8FunctionState<CStringStringState>.IsNullTerminated => false; | ||
#if NET6_0 | ||
[RequiresPreviewFeatures] | ||
#endif | ||
static ReadOnlySpan<Byte> IUtf8FunctionState<CStringStringState>.GetSpan(CStringStringState state) | ||
=> Encoding.UTF8.GetBytes(state._value); | ||
#if NET6_0 | ||
[RequiresPreviewFeatures] | ||
#endif | ||
static Int32 IUtf8FunctionState<CStringStringState>.GetLength(CStringStringState state) => state._utf8Length; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/Intermediate/Rxmxnx.PInvoke.CString.Intermediate/IUtf8FunctionState.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
namespace Rxmxnx.PInvoke; | ||
|
||
/// <summary> | ||
/// Interface representing a value state for functional <see cref="CString"/> creation. | ||
/// </summary> | ||
/// <typeparam name="TSelf">Current state type.</typeparam> | ||
public interface IUtf8FunctionState<in TSelf> where TSelf : struct, IUtf8FunctionState<TSelf> | ||
{ | ||
/// <summary> | ||
/// Indicates whether resulting UTF-8 text is null-terminated. | ||
/// </summary> | ||
Boolean IsNullTerminated { get; } | ||
|
||
/// <summary> | ||
/// Retrieves the span from <paramref name="state"/>. | ||
/// </summary> | ||
/// <param name="state">Current item sequence state.</param> | ||
/// <returns>The binary span for the specified state.</returns> | ||
#if NET6_0 | ||
[RequiresPreviewFeatures] | ||
#endif | ||
static abstract ReadOnlySpan<Byte> GetSpan(TSelf state); | ||
/// <summary> | ||
/// Retrieves the span length from <paramref name="state"/>. | ||
/// </summary> | ||
/// <param name="state">Current item sequence state.</param> | ||
/// <returns>The binary span length for the specified state.</returns> | ||
[ExcludeFromCodeCoverage] | ||
#if NET6_0 | ||
[RequiresPreviewFeatures] | ||
#endif | ||
static virtual Int32 GetLength(TSelf state) => TSelf.GetSpan(state).Length; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.