public delegate bool Predicate<in T>(T obj);
}
+
+namespace System.Buffers
+{
+ public delegate void SpanAction<T, in TArg>(Span<T> span, TArg arg);
+ public delegate void ReadOnlySpanAction<T, in TArg>(ReadOnlySpan<T> span, TArg arg);
+}
{
using System.Text;
using System;
+ using System.Buffers;
using System.Runtime;
using System.Runtime.ConstrainedExecution;
using System.Globalization;
return result;
}
+ public static string Create<TState>(int length, TState state, SpanAction<char, TState> action)
+ {
+ if (action == null)
+ {
+ throw new ArgumentNullException(nameof(action));
+ }
+
+ if (length > 0)
+ {
+ string result = FastAllocateString(length);
+ action(new Span<char>(ref result.GetRawStringData(), length), state);
+ return result;
+ }
+
+ if (length == 0)
+ {
+ return Empty;
+ }
+
+ throw new ArgumentOutOfRangeException(nameof(length));
+ }
+
// Returns this string.
public override String ToString()
{