public int IndexOf(UnicodeScalar unicodeScalar) { Span <char> span = stackalloc char[unicodeScalar.Utf16CodeUnitCount]; unicodeScalar.CopyUtf16CodeUnitsTo(span); return(RawString.AsSpan().IndexOf(span, StringComparison.Ordinal)); }
public bool StartsWith(UnicodeScalar unicodeScalar) { Span <char> span = stackalloc char[unicodeScalar.Utf16CodeUnitCount]; unicodeScalar.CopyUtf16CodeUnitsTo(span); return(RawString.AsSpan().StartsWith(span, StringComparison.Ordinal)); }
public int LastIndexOf(UnicodeScalar unicodeScalar, int startIndex, int count) { Span <char> span = stackalloc char[unicodeScalar.Utf16CodeUnitCount]; unicodeScalar.CopyUtf16CodeUnitsTo(span); return(RawString.AsSpan().Slice(startIndex, count).LastIndexOf(span)); }
public Utf16SharedString PadRight(int totalWidth, UnicodeScalar paddingScalar) { if (totalWidth <= Length) { return(this); } int paddingScalarWidth = paddingScalar.Utf16CodeUnitCount; int insertScalarCount = (totalWidth - Length) / paddingScalarWidth; int paddedLength = Length + insertScalarCount * paddingScalarWidth; Span <char> paddingSpan = stackalloc char[paddingScalarWidth]; paddingScalar.CopyUtf16CodeUnitsTo(paddingSpan); Span <char> span = paddedLength <= maxStackallocSize ? stackalloc char[paddedLength] : new char[paddedLength]; RawString.AsSpan().CopyTo(span); for (int i = Length; i < paddedLength; i += paddingScalarWidth) { for (int j = 0; j < paddingScalarWidth; j++) { span[i + j] = paddingSpan[j]; } } return(new Utf16SharedString(new string(span.ToArray()), Spans)); }
public static ReadOnlySpan <char> TrimStart(this ReadOnlySpan <char> span, UnicodeScalar unicodeScalar) { Span <char> trimSpan = stackalloc char[unicodeScalar.Utf16CodeUnitCount]; unicodeScalar.CopyUtf16CodeUnitsTo(trimSpan); int start = 0; for (ref int i = ref start; i < span.Length;)