/** * Returns the {@link Tag} that {@linkplain Segment#encloses(int) encloses} the specified position in the source document. * <p> * See the {@link Tag} class documentation for more details about the behaviour of this method. * * @param pos the position in the source document, may be out of bounds. * @return the {@link Tag} that {@linkplain Segment#encloses(int) encloses} the specified position in the source document, or <code>null</code> if the position is not within a tag or is out of bounds. */ public Tag getEnclosingTag(final int pos) { return getEnclosingTag(pos,null); }
/** * Returns the start tag to which this attribute belongs. * @return the start tag to which this attribute belongs, or <code>null</code> if it is not within a start tag. */ public StartTag getStartTag() { if (startTag==StartTag.NOT_CACHED) { final Tag tag=source.getEnclosingTag(begin); startTag=(tag==null || tag instanceof EndTag) ? null : (StartTag)tag; } return startTag; }
public ParserTag getEnclosingTag(int i) { Tag tag = fSource.getEnclosingTag(i); if (tag == null) { return null; } return makeParserTag(tag); }
/** * Indicates whether a tag of this type encloses the specified position of the specified source document. * <br />(<a href="TagType.html#ImplementationAssistance">implementation assistance</a> method) * <p> * This is logically equivalent to <code>source.</code>{@link Source#getEnclosingTag(int,TagType) getEnclosingTag(pos,this)}<code>!=null</code>, * but is safe to use within other implementation methods without the risk of causing an infinite recursion. * <p> * This method is called from the default implementation of the {@link #isValidPosition(Source, int pos, int[] fullSequentialParseData)} method. * * @param source the {@link Source} document. * @param pos the character position in the source document to check. * @return <code>true</code> if a tag of this type encloses the specified position of the specified source document, otherwise <code>false</code>. */ protected final boolean tagEncloses(final Source source, final int pos) { if (pos==0) return false; final Tag enclosingTag=source.getEnclosingTag(pos-1,this); // use pos-1 otherwise a tag at pos could cause infinite recursion when this is called from constructTagAt return enclosingTag!=null && pos!=enclosingTag.getEnd(); // make sure pos!=enclosingTag.getEnd() to compensate for using pos-1 above (important if the tag in question immediately follows an end tag delimiter) }
searchPos=parseText.indexOf(searchString.toLowerCase(),searchPos); if (searchPos==-1) return null; final Tag tag=source.getEnclosingTag(searchPos); if (tag==null || !(tag instanceof StartTag)) { searchPos++;
static StartTag getNext(final Source source, final int pos, final String attributeName, final Pattern valueRegexPattern) { if (attributeName==null || attributeName.length()==0) throw new IllegalArgumentException(); if (source.wasFullSequentialParseCalled()) { StartTag startTag=source.getNextStartTag(pos); while (true) { if (startTag==null) return null; if (startTag.hasAttribute(attributeName,valueRegexPattern)) return startTag; startTag=startTag.getNextStartTag(); } } else { final String searchString=attributeName; final ParseText parseText=source.getParseText(); int searchPos=pos; while (searchPos<source.end) { searchPos=parseText.indexOf(searchString.toLowerCase(),searchPos); if (searchPos==-1) return null; final Tag tag=source.getEnclosingTag(searchPos); if (tag==null || !(tag instanceof StartTag)) { searchPos++; continue; } if (tag.begin>=pos) { final StartTag startTag=(StartTag)tag; if (startTag.hasAttribute(attributeName,valueRegexPattern)) return startTag; } searchPos=tag.end; } return null; } }
public ParserTag getPreviousTag(int i) { Tag encosingTag = fSource.getEnclosingTag(i); Tag parserTag = fSource.getPreviousTag(i); if (parserTag.getBegin() == encosingTag.getBegin()) return makeParserTag(fSource.getPreviousTag(encosingTag.getBegin() - 1)); return makeParserTag(fSource.getPreviousTag(i)); }