Method InvokeWithUTF8Span
InvokeWithUTF8Span(ReadOnlySpan<char>, Action<nint, int>)
Converts the specified UTF-16 character span to UTF-8 and invokes the provided action with a pointer to the UTF-8 data and its length.
public static void InvokeWithUTF8Span(ReadOnlySpan<char> input, Action<nint, int> action)
Parameters
inputReadOnlySpan<char>The UTF-16 character span to be converted to UTF-8. If the span is empty, the action is invoked with a null pointer and a length of 0.
actionAction<nint, int>The action to invoke with the UTF-8 data. The action receives a pointer to the UTF-8-encoded bytes and the number of bytes in the UTF-8 data. The pointer is valid only for the duration of the action's execution.
Remarks
This method uses stack allocation for small UTF-8 buffers and heap allocation for larger ones. Callers should ensure that the action does not store or use the pointer outside the scope of the action.