Debian Codegraph @

net/sf/saxon/tree/tiny/TinyCommentImpl.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.tree.tiny;
9
10 import net.sf.saxon.event.Receiver;
11 import net.sf.saxon.expr.parser.Location;
12 import net.sf.saxon.om.AtomicSequence;
13 import net.sf.saxon.trans.XPathException;
14 import net.sf.saxon.type.Type;
15 import net.sf.saxon.value.StringValue;
16
17
18 /**
19 * TinyCommentImpl is an implementation of CommentInfo
20 *
21 * @author Michael H. Kay
22 */
23
24
25 final class TinyCommentImpl extends TinyNodeImpl {
26
27 public TinyCommentImpl(TinyTree tree, int nodeNr) {
28 this.tree = tree;
29 this.nodeNr = nodeNr;
30 }
31
32 /**
33 * Get the XPath string value of the comment
34 */
35
36 public final String getStringValue() {
37 int start = tree.alpha[nodeNr];
38 int len = tree.beta[nodeNr];
39 if (len == 0) return "";
40 char[] dest = new char[len];
41 tree.commentBuffer.getChars(start, start + len, dest, 0);
42 return new String(dest, 0, len);
43 }
44
45 /**
46 * Get the typed value of this node.
47 * Returns the string value, as an instance of xs:string
48 */
49
50 public AtomicSequence atomize() {
51 return new StringValue(getStringValue());
52 }
53
54
55 /**
56 * Get the node type
57 *
58 * @return Type.COMMENT
59 */
60
61 public final int getNodeKind() {
62 return Type.COMMENT;
63 }
64
65 /**
66 * Copy this node to a given outputter
67 */
68
69 public void copy(/*@NotNull*/ Receiver out, int copyOptions, Location locationId) throws XPathException {
70 out.comment(getStringValue(), locationId, 0);
71 }
72
73 }
74