feat: More utilities!

- Also document that CStringExtensions only works with bundled CS.
This commit is contained in:
Kaz Wolfe 2025-03-24 18:16:39 -07:00
parent 314c046ec9
commit a7509ef77d
No known key found for this signature in database
GPG key ID: 258813F53A16EBB4
2 changed files with 31 additions and 3 deletions

View file

@ -1744,7 +1744,7 @@ internal class SeStringEvaluator : IServiceType, ISeStringEvaluator
return false;
case TextParameterType.String:
this.EvaluateAndAppendTo(builder, p.StringValue.AsReadOnlySeStringSpan(), null, language);
this.EvaluateAndAppendTo(builder, p.StringValue.AsSpan(), null, language);
return false;
case TextParameterType.Uninitialized:

View file

@ -1,4 +1,6 @@
using InteropGenerator.Runtime;
using Dalamud.Game.Text.SeStringHandling;
using InteropGenerator.Runtime;
using Lumina.Text.ReadOnly;
@ -7,6 +9,9 @@ namespace Dalamud.Utility;
/// <summary>
/// A set of helpful utilities for working with <see cref="CStringPointer"/>s from ClientStructs.
/// </summary>
/// <remarks>
/// WARNING: Will break if a custom ClientStructs is used. These are here for CONVENIENCE ONLY!
/// </remarks>
public static class CStringExtensions
{
/// <summary>
@ -14,11 +19,34 @@ public static class CStringExtensions
/// </summary>
/// <param name="ptr">The pointer to convert.</param>
/// <returns>A span.</returns>
public static unsafe ReadOnlySeStringSpan AsReadOnlySeStringSpan(this CStringPointer ptr)
public static ReadOnlySeStringSpan AsReadOnlySeStringSpan(this CStringPointer ptr)
{
return ptr.AsSpan();
}
/// <summary>
/// Convert a CStringPointer to a Dalamud SeString.
/// </summary>
/// <param name="ptr">The pointer to convert.</param>
/// <returns>A Dalamud-flavored SeString.</returns>
public static SeString AsDalamudSeString(this CStringPointer ptr)
{
return ptr.AsReadOnlySeStringSpan().ToDalamudString();
}
/// <summary>
/// Get a new SeString that's a <em>copy</em> of the text in this CStringPointer.
/// </summary>
/// <param name="ptr">The pointer to copy.</param>
/// <returns>A new Lumina SeString.</returns>
public static Lumina.Text.SeString AsLuminaSeString(this CStringPointer ptr)
{
var ssb = new Lumina.Text.SeStringBuilder();
ssb.Append(ptr.AsSpan());
return ssb.ToSeString();
}
/// <summary>
/// Extract text from this CStringPointer following <see cref="ReadOnlySeStringSpan.ExtractText()"/>'s rules. Only
/// useful for SeStrings.