// Returns the symbol type preceding thisPosition. internal static TextPointerContext GetPointerContextBackward(TextTreeNode node, ElementEdge edge) { TextPointerContext symbolType; TextTreeNode previousNode; TextTreeNode lastChildNode; switch (edge) { case ElementEdge.BeforeStart: previousNode = (TextTreeNode)node.GetPreviousNode(); if (previousNode != null) { symbolType = previousNode.GetPointerContext(LogicalDirection.Backward); } else { // The root node is special, there's no ElementStart/End, so test for null parent. Invariant.Assert(node.GetContainingNode() != null, "Bad position!"); // Illegal to be at root BeforeStart. symbolType = (node.GetContainingNode() is TextTreeRootNode) ? TextPointerContext.None : TextPointerContext.ElementStart; } break; case ElementEdge.AfterStart: // The root node is special, there's no ElementStart/End, so test for null parent. Invariant.Assert(node.ParentNode != null || node is TextTreeRootNode, "Inconsistent node.ParentNode"); symbolType = (node.ParentNode != null) ? TextPointerContext.ElementStart : TextPointerContext.None; break; case ElementEdge.BeforeEnd: lastChildNode = (TextTreeNode)node.GetLastContainedNode(); if (lastChildNode != null) { symbolType = lastChildNode.GetPointerContext(LogicalDirection.Backward); } else { goto case ElementEdge.AfterStart; } break; case ElementEdge.AfterEnd: symbolType = node.GetPointerContext(LogicalDirection.Backward); break; default: Invariant.Assert(false, "Unknown ElementEdge value"); symbolType = TextPointerContext.Text; break; } return symbolType; }
internal static TextPointerContext GetPointerContextForward(TextTreeNode node, ElementEdge edge) { TextTreeNode nextNode; TextTreeNode firstContainedNode; TextPointerContext symbolType; switch (edge) { case ElementEdge.BeforeStart: symbolType = node.GetPointerContext(LogicalDirection.Forward); break; case ElementEdge.AfterStart: if (node.ContainedNode != null) { firstContainedNode = (TextTreeNode)node.GetFirstContainedNode(); symbolType = firstContainedNode.GetPointerContext(LogicalDirection.Forward); } else { goto case ElementEdge.BeforeEnd; } break; case ElementEdge.BeforeEnd: // The root node is special, there's no ElementStart/End, so test for null parent. Invariant.Assert(node.ParentNode != null || node is TextTreeRootNode, "Inconsistent node.ParentNode"); symbolType = (node.ParentNode != null) ? TextPointerContext.ElementEnd : TextPointerContext.None; break; case ElementEdge.AfterEnd: nextNode = (TextTreeNode)node.GetNextNode(); if (nextNode != null) { symbolType = nextNode.GetPointerContext(LogicalDirection.Forward); } else { // The root node is special, there's no ElementStart/End, so test for null parent. Invariant.Assert(node.GetContainingNode() != null, "Bad position!"); // Illegal to be at root AfterEnd. symbolType = (node.GetContainingNode() is TextTreeRootNode) ? TextPointerContext.None : TextPointerContext.ElementEnd; } break; default: Invariant.Assert(false, "Unreachable code."); symbolType = TextPointerContext.Text; break; } return symbolType; }