CharReadOnlySpanExtensions Class
Provides extension methods for read-only spans of characters.
public static class CharReadOnlySpanExtensionsMethods
| Name | Description |
|---|---|
| ReadOnlySpan<char>.ApplyEdits(IEnumerable<TextEdit>) | Applies a set of edits to a span of characters, and returns the resulting string. |
| ReadOnlySpan<char>.ComputeLineClipping(int, int) | Finds the first and the last lines of a span of characters, and counts the lines between them. |
| ReadOnlySpan<char>.ComputeLiteralLength(StringLiteralKind) | Computes the length of the representation of a span of characters as a string literal. |
| ReadOnlySpan<char>.ComputeQuotedLiteralLength() | Computes the length of the quoted literal representation of a span of characters. |
| ReadOnlySpan<char>.ComputeVerbatimLiteralLength() | Computes the length of the verbatim literal representation of a span of characters. |
| ReadOnlySpan<char>.ToClippedLiteral(StringLiteralKind, int, int, bool) | Builds and returns a string representing a given span of characters as a C# string literal. If the string is longer than the sum of headLength, tailLength, and the length of an ellipsis (1 if useUnicodeEllipsis is true, 3 otherwise), then it is clipped, taking only the first headLength characters, followed by an ellipsis (either the Unicode character '\x2026' (…), or three dots ...) and the last tailLength characters. |
| ReadOnlySpan<char>.ToClippedQuotedLiteral(int, int, bool) | Builds and returns a string representing a given span of characters as a C# quoted string literal. If the string is longer than the sum of headLength, tailLength, and the length of an ellipsis (1 if useUnicodeEllipsis is true, 3 otherwise), then it is clipped, taking only the first headLength characters, followed by an ellipsis (either the Unicode character '\x2026' (…), or three dots ...) and the last tailLength characters. |
| ReadOnlySpan<char>.ToClippedVerbatimLiteral(int, int, bool) | Builds and returns a string representing a given span of characters as a C# verbatim string literal. If the string is longer than the sum of headLength, tailLength, and the length of an ellipsis (1 if useUnicodeEllipsis is true, 3 otherwise), then it is clipped, taking only the first headLength characters, followed by an ellipsis (either the Unicode character '\x2026' (…), or three dots ...) and the last tailLength characters. |
| ReadOnlySpan<char>.ToLiteral(StringLiteralKind) | Builds and returns a string representing a given span of characters as a C# string literal. |
| ReadOnlySpan<char>.ToQuotedLiteral() | Builds and returns a string representing a given span of characters as a C# quoted string literal. |
| ReadOnlySpan<char>.ToVerbatimLiteral() | Builds and returns a string representing a given span of characters as a C# verbatim string literal. |
ReadOnlySpan<char>.ApplyEdits(IEnumerable<TextEdit>)
Applies a set of edits to a span of characters, and returns the resulting string.
extension(ReadOnlySpan<char> @this)
{
public string ApplyEdits(IEnumerable<TextEdit> edits)
}Parameters
thisReadOnlySpan<char>- The ReadOnlySpan<char> on which this method is called.
editsIEnumerable<TextEdit>- The edits to apply. The
TextEdit.Startof every edit is an index inthis, whatever the other edits do.
Returns
string A newly-constructed string, in which TextEdit.Text has replaced the characters of each edit.
Exceptions
ArgumentNullExceptioneditsisnull.ArgumentOutOfRangeException- An edit has a negative
TextEdit.Start, aTextEdit.Startgreater than the length ofthis, a negativeTextEdit.Length, or characters to replace after the end ofthis. ArgumentException- Two edits overlap.
Remarks
The order of edits matters only for insertions at one index: their texts appear in the result in the order of edits.
Two edits overlap when both replace one character, or when one inserts a text between two characters that the other replaces.
An insertion at the first character that another edit replaces overlaps nothing: the inserted text precedes the replacing text in the result. An insertion just after the last character that another edit replaces follows the replacing text.
See also
ReadOnlySpan<char>.ComputeLineClipping(int, int)
Finds the first and the last lines of a span of characters, and counts the lines between them.
extension(ReadOnlySpan<char> @this)
{
public LineClipping ComputeLineClipping(int headLines, int tailLines)
}Parameters
thisReadOnlySpan<char>- The ReadOnlySpan<char> on which this method is called.
headLinesint- The number of lines to keep at the start of the span, when the span is clipped.
tailLinesint- The number of lines to keep at the end of the span, when the span is clipped.
Returns
LineClipping A LineClipping value, whose ranges refer to this.
Exceptions
ArgumentOutOfRangeExceptionheadLinesis less than 0. - or -tailLinesis less than 0.
Remarks
A line ends at a line feed (\n), at a carriage return (\r), at a CR-LF pair (\r\n), or at the end of the span, as in TextReader.ReadLine.
A line terminator at the end of the span does not start a new line.
A blank line is a line that is empty, or holds white-space characters alone, as Char.IsWhiteSpace defines them. This method ignores the blank lines at the start and at the end of the span, and the rest of these remarks does not count them among the lines of the span. A blank line between two other lines is not ignored.
An empty span and a span of blank lines alone have no lines.
A span of more than (headLines + tailLines + 1) lines is clipped: LineClipping.Head holds its first headLines lines, and LineClipping.Tail its last tailLines lines. The reason for the +1 above is that a clipped text is usually displayed with a placeholder line (e.g., "--- more... ---") between head and tail.
When a span is not clipped, LineClipping.Head holds all of its lines, and LineClipping.Tail is empty.
This method copies no characters and allocates no memory.
See also
ReadOnlySpan<char>.ComputeLiteralLength(StringLiteralKind)
Computes the length of the representation of a span of characters as a string literal.
extension(ReadOnlySpan<char> @this)
{
public int ComputeLiteralLength(StringLiteralKind literalKind)
}Parameters
thisReadOnlySpan<char>- The ReadOnlySpan<char> on which this method is called.
literalKindStringLiteralKind- A
StringLiteralKindconstant specifying the kind of string literal that would be built.
Returns
int The length of the string that would result from calling ReadOnlySpan<char>.ToLiteral on this with literalKind as last parameter.
Exceptions
ArgumentExceptionliteralKindis neitherStringLiteralKind.QuotednorStringLiteralKind.Verbatim.
ReadOnlySpan<char>.ComputeQuotedLiteralLength()
Computes the length of the quoted literal representation of a span of characters.
extension(ReadOnlySpan<char> @this)
{
public int ComputeQuotedLiteralLength()
}Parameters
thisReadOnlySpan<char>- The ReadOnlySpan<char> on which this method is called.
Returns
int The length of the string that would result from calling ReadOnlySpan<char>.ToQuotedLiteral on this.
ReadOnlySpan<char>.ComputeVerbatimLiteralLength()
Computes the length of the verbatim literal representation of a span of characters.
extension(ReadOnlySpan<char> @this)
{
public int ComputeVerbatimLiteralLength()
}Parameters
thisReadOnlySpan<char>- The ReadOnlySpan<char> on which this method is called.
Returns
int The length of the string that would result from calling ReadOnlySpan<char>.ToVerbatimLiteral on this.
ReadOnlySpan<char>.ToClippedLiteral(StringLiteralKind, int, int, bool)
Builds and returns a string representing a given span of characters as a C# string literal. If the string is longer than the sum of headLength, tailLength, and the length of an ellipsis (1 if useUnicodeEllipsis is true, 3 otherwise), then it is clipped, taking only the first headLength characters, followed by an ellipsis (either the Unicode character '\x2026' (…), or three dots ...) and the last tailLength characters.
extension(ReadOnlySpan<char> @this)
{
public string ToClippedLiteral(StringLiteralKind literalKind, int headLength, int tailLength, bool useUnicodeEllipsis = false)
}Parameters
thisReadOnlySpan<char>- The ReadOnlySpan<char> on which this method is called.
literalKindStringLiteralKind- A
StringLiteralKindconstant specifying the kind of string literal to build. headLengthint- The number of characters to leave before clipping.
tailLengthint- The number of characters to leave after clipping.
useUnicodeEllipsisbooltrueto use a single Unicode character Ellipsis ('\x2026',…) to replace the clipped part;falseto use three dots (...) instead. Default isfalse.
Returns
string A newly-constructed string.
Exceptions
ArgumentExceptionliteralKindis neitherStringLiteralKind.QuotednorStringLiteralKind.Verbatim.ArgumentOutOfRangeExceptionheadLengthis less than 0. - or -tailLengthis less than 0.
See also
ReadOnlySpan<char>.ToClippedQuotedLiteral(int, int, bool)
Builds and returns a string representing a given span of characters as a C# quoted string literal. If the string is longer than the sum of headLength, tailLength, and the length of an ellipsis (1 if useUnicodeEllipsis is true, 3 otherwise), then it is clipped, taking only the first headLength characters, followed by an ellipsis (either the Unicode character '\x2026' (…), or three dots ...) and the last tailLength characters.
extension(ReadOnlySpan<char> @this)
{
public string ToClippedQuotedLiteral(int headLength, int tailLength, bool useUnicodeEllipsis = false)
}Parameters
thisReadOnlySpan<char>- The ReadOnlySpan<char> on which this method is called.
headLengthint- The number of characters to leave before clipping.
tailLengthint- The number of characters to leave after clipping.
useUnicodeEllipsisbooltrueto use a single Unicode character Ellipsis ('\x2026',…) to replace the clipped part;falseto use three dots (...) instead. Default isfalse.
Returns
string A newly-constructed string.
Exceptions
ArgumentOutOfRangeExceptionheadLengthis less than 0. - or -tailLengthis less than 0.
See also
ReadOnlySpan<char>.ToClippedVerbatimLiteral(int, int, bool)
Builds and returns a string representing a given span of characters as a C# verbatim string literal. If the string is longer than the sum of headLength, tailLength, and the length of an ellipsis (1 if useUnicodeEllipsis is true, 3 otherwise), then it is clipped, taking only the first headLength characters, followed by an ellipsis (either the Unicode character '\x2026' (…), or three dots ...) and the last tailLength characters.
extension(ReadOnlySpan<char> @this)
{
public string ToClippedVerbatimLiteral(int headLength, int tailLength, bool useUnicodeEllipsis = false)
}Parameters
thisReadOnlySpan<char>- The ReadOnlySpan<char> on which this method is called.
headLengthint- The number of characters to leave before clipping.
tailLengthint- The number of characters to leave after clipping.
useUnicodeEllipsisbooltrueto use a single Unicode character Ellipsis ('\x2026',…) to replace the clipped part;falseto use three dots (...) instead. Default isfalse.
Returns
string A newly-constructed string.
Exceptions
ArgumentOutOfRangeExceptionheadLengthis less than 0. - or -tailLengthis less than 0.
See also
ReadOnlySpan<char>.ToLiteral(StringLiteralKind)
Builds and returns a string representing a given span of characters as a C# string literal.
extension(ReadOnlySpan<char> @this)
{
public string ToLiteral(StringLiteralKind literalKind)
}Parameters
thisReadOnlySpan<char>- The ReadOnlySpan<char> on which this method is called.
literalKindStringLiteralKind- A
StringLiteralKindconstant specifying the kind of string literal to build.
Returns
string A newly-constructed string.
Exceptions
ArgumentExceptionliteralKindis neitherStringLiteralKind.QuotednorStringLiteralKind.Verbatim.
See also
ReadOnlySpan<char>.ToQuotedLiteral()
Builds and returns a string representing a given span of characters as a C# quoted string literal.
extension(ReadOnlySpan<char> @this)
{
public string ToQuotedLiteral()
}Parameters
thisReadOnlySpan<char>- The ReadOnlySpan<char> on which this method is called.
Returns
string A newly-constructed string.
See also
ReadOnlySpan<char>.ToVerbatimLiteral()
Builds and returns a string representing a given span of characters as a C# verbatim string literal.
extension(ReadOnlySpan<char> @this)
{
public string ToVerbatimLiteral()
}Parameters
thisReadOnlySpan<char>- The ReadOnlySpan<char> on which this method is called.
Returns
string A newly-constructed string.