Struct LineBreak
A place where a line may or must end.
public readonly record struct LineBreak : IEquatable<LineBreak>
- Implements
- Inherited Members
Examples
// Where lines may end: after spaces and hyphens, and always at the end; a line must end after a newline.
List<int> breaks = [];
foreach (LineBreak b in LineBreaks.Enumerate("A well-known fact.\nNext"))
{
breaks.Add(b.Index); // 2, 7, 13, 19 (mandatory), 23
}
// CSS switches: break-all lets letters break like ideographs.
LineBreakOptions breakAll = new(WordBreak: WordBreak.BreakAll);
int count = 0;
foreach (LineBreak b in LineBreaks.Enumerate("word", breakAll))
{
count++; // 4: after every letter
}
Constructors
LineBreak(int, bool, bool)
A place where a line may or must end.
public LineBreak(int Index, bool IsMandatory, bool IsSoftHyphen)
Parameters
IndexintThe UTF-16 index the next line would start at.
IsMandatoryboolWhether the line must end here: after a hard line break (LF, CR, CR LF, NEL, VT, FF, U+2028 or U+2029) or at the end of text after one.
IsSoftHyphenboolWhether the break follows a soft hyphen (U+00AD), which shows a hyphen when the line ends there.
Examples
// Where lines may end: after spaces and hyphens, and always at the end; a line must end after a newline.
List<int> breaks = [];
foreach (LineBreak b in LineBreaks.Enumerate("A well-known fact.\nNext"))
{
breaks.Add(b.Index); // 2, 7, 13, 19 (mandatory), 23
}
// CSS switches: break-all lets letters break like ideographs.
LineBreakOptions breakAll = new(WordBreak: WordBreak.BreakAll);
int count = 0;
foreach (LineBreak b in LineBreaks.Enumerate("word", breakAll))
{
count++; // 4: after every letter
}
Properties
Index
The UTF-16 index the next line would start at.
public int Index { get; init; }
Property Value
IsMandatory
Whether the line must end here: after a hard line break (LF, CR, CR LF, NEL, VT, FF, U+2028 or U+2029) or at the end of text after one.
public bool IsMandatory { get; init; }
Property Value
IsSoftHyphen
Whether the break follows a soft hyphen (U+00AD), which shows a hyphen when the line ends there.
public bool IsSoftHyphen { get; init; }