TextNode
sealed class TextNode : CharacterData, IText, ICharacterData, INode, IEventTarget, IMarkupFormattable, IChildNode, INonDocumentTypeChildNode
Represents a text node.
using AngleSharp.Text;
using System.Runtime.CompilerServices;
using System.Text;
namespace AngleSharp.Dom
{
internal sealed class TextNode : CharacterData, IText, ICharacterData, INode, IEventTarget, IMarkupFormattable, IChildNode, INonDocumentTypeChildNode
{
internal bool IsEmpty {
get {
for (int i = 0; i < base.Length; i++) {
if (!base[i].IsSpaceCharacter())
return false;
}
return true;
}
}
[System.Runtime.CompilerServices.Nullable(1)]
public string Text {
[System.Runtime.CompilerServices.NullableContext(1)]
get {
Node previousSibling = base.PreviousSibling;
TextNode textNode = this;
StringBuilder stringBuilder = StringBuilderPool.Obtain();
while (previousSibling is TextNode) {
textNode = (TextNode)previousSibling;
previousSibling = textNode.PreviousSibling;
}
do {
stringBuilder.Append(textNode.Data);
textNode = (textNode.NextSibling as TextNode);
} while (textNode != null);
return stringBuilder.ToPool();
}
}
[System.Runtime.CompilerServices.Nullable(2)]
public IElement AssignedSlot {
[System.Runtime.CompilerServices.NullableContext(2)]
get {
IElement parentElement = base.ParentElement;
if (parentElement.IsShadow())
return parentElement.ShadowRoot?.GetAssignedSlot(null);
return null;
}
}
[System.Runtime.CompilerServices.NullableContext(1)]
internal TextNode(Document owner)
: this(owner, string.Empty)
{
}
[System.Runtime.CompilerServices.NullableContext(1)]
internal TextNode(Document owner, string text)
: base(owner, "#text", NodeType.Text, text)
{
}
[System.Runtime.CompilerServices.NullableContext(1)]
public IText Split(int offset)
{
int length = base.Length;
if (offset > length)
throw new DomException(DomError.IndexSizeError);
int count = length - offset;
string text = Substring(offset, count);
TextNode textNode = new TextNode(base.Owner, text);
Node parent = base.Parent;
Document owner = base.Owner;
if (parent != null) {
int num = this.Index();
parent.InsertBefore(textNode, base.NextSibling);
foreach (Range attachedReference in owner.GetAttachedReferences<Range>()) {
if (attachedReference.Head == this && attachedReference.Start > offset)
attachedReference.StartWith(textNode, attachedReference.Start - offset);
if (attachedReference.Tail == this && attachedReference.End > offset)
attachedReference.EndWith(textNode, attachedReference.End - offset);
if (attachedReference.Head == parent && attachedReference.Start == num + 1)
attachedReference.StartWith(parent, attachedReference.Start + 1);
if (attachedReference.Tail == parent && attachedReference.End == num + 1)
attachedReference.StartWith(parent, attachedReference.End + 1);
}
}
Replace(offset, count, string.Empty);
if (parent != null) {
foreach (Range attachedReference2 in owner.GetAttachedReferences<Range>()) {
if (attachedReference2.Head == this && attachedReference2.Start > offset)
attachedReference2.StartWith(this, offset);
if (attachedReference2.Tail == this && attachedReference2.End > offset)
attachedReference2.EndWith(this, offset);
}
return textNode;
}
return textNode;
}
[System.Runtime.CompilerServices.NullableContext(1)]
public override Node Clone(Document owner, bool deep)
{
TextNode textNode = new TextNode(owner, base.Data);
CloneNode(textNode, owner, deep);
return textNode;
}
}
}