public static void MakeIndent(this ITreeNode indentNode, string indent)
{
var lastSpace = indentNode.PrevSibling as IWhitespaceNode;
if (lastSpace != null && lastSpace.GetTokenType() != NTriplesTokenType.NEW_LINE)
{
ITreeNode firstSpace =
lastSpace.LeftWhitespaces().TakeWhile(ws => ws.GetTokenType() != NTriplesTokenType.NEW_LINE).LastOrDefault() ??
lastSpace;
Debug.Assert(firstSpace != null, "firstSpace != null");
if (firstSpace != lastSpace)
{
while ((firstSpace != null) && (firstSpace.GetTokenType() != NTriplesTokenType.NEW_LINE) &&
(firstSpace.GetNextToken() != lastSpace))
{
firstSpace = firstSpace.GetNextToken();
}
firstSpace = firstSpace.GetNextToken();
}
if (firstSpace != null)
{
if ((firstSpace != lastSpace || lastSpace.GetText() != indent) && (firstSpace.Parent == lastSpace.Parent))
{
if (indent.IsEmpty())
{
LowLevelModificationUtil.DeleteChildRange(firstSpace, lastSpace);
}
else
{
LowLevelModificationUtil.ReplaceChildRange(firstSpace, lastSpace, CreateSpace(indent));
}
}
}
}
else if (!indent.IsEmpty())
{
LowLevelModificationUtil.AddChildBefore(indentNode, CreateSpace(indent));
}
}