/// <summary> /// Parses the input stream into XRISegmentVals /// </summary> /// <param name="oPathStream">The input stream to scan from</param> protected void scanXRISegments(ParseStream oPathStream) { // sets whether colons are allowed bool bAllowColon = mbAllowColon; // loop through the XRI segments as long as we are consuming something bool bConsumed = true; while (!oPathStream.empty() && bConsumed) { bConsumed = false; ParseStream oStream = oPathStream.begin(); bool bStartsWithSlash = (oStream.getData()[0] == '/'); // if this is the first segment, it must not start with slash if ((bStartsWithSlash) && (moSegments.Count == 0)) { break; } // if this is not the first segment, we expect a slash if ((!bStartsWithSlash) && (moSegments.Count > 0)) { break; } // consume the slash if necessary if (bStartsWithSlash) { bConsumed = true; oStream.consume(1); } // if there is actually a segment, add it to the list XRISegment oSegment = new XRISegment(true, bAllowColon, true); if (oSegment.scan(oStream)) { bConsumed = true; moSegments.Add(oSegment); } // consume whatever we used (even if the segment was empty) oPathStream.end(oStream); // after the first segment, colons are allowed bAllowColon = true; } }
public bool EqualsIgnoreCase(XRISegment segment) { return ToString().Equals(segment.ToString(), StringComparison.InvariantCultureIgnoreCase); }
public bool Equals(XRISegment segment) { return ToString().Equals(segment.ToString()); }
public bool isPrefixOf(XRISegment segment) { int n = this.getNumSubSegments(); // first, return false if this segment has more subsegments than the given segment if (n > segment.getNumSubSegments()) return false; for (int i = 0; i < n; i++) { XRISubSegment subseg = this.getSubSegmentAt(i); if (!subseg.EqualsIgnoreCase(segment.getSubSegmentAt(i))) return false; } return true; }
/// <summary> /// Returns the last part of the XRI segment. Skips over the specified number /// of subsegments and returns the remainder as a XRISegment. /// For example: This XRI Segment is "!a!b!c!d" /// getSegmentRemaider(0) => !a!b!c!d /// getSegmentRemaider(1) => !b!c!d /// getSegmentRemaider(2) => !c!d /// getSegmentRemaider(3) => !d /// getSegmentRemaider(4) => null /// </summary> /// <param name="nSkip"></param> /// <returns>The number of subsegments to skip.</returns> public XRISegment getRemainder(int nSkip) { parse(); // return null if there isn't atleast nSkip subsegments if ((this.moSubSegments == null) || (this.moSubSegments.Count <= nSkip)) { return null; } // return a XRISegment without the first few subsegments XRISegment oRemainder = new XRISegment(false, mbAllowColon, mbAllowReassignable); oRemainder.msValue = ""; oRemainder.moSubSegments = new List<XRISubSegment>(); oRemainder.mbParsed = true; oRemainder.mbParseResult = this.mbParseResult; for (int i = nSkip; i < this.moSubSegments.Count; i++) { XRISubSegment oSubseg = this.moSubSegments[i]; oRemainder.moSubSegments.Add(oSubseg); oRemainder.msValue += oSubseg.ToString(); } return oRemainder; }
/// <summary> /// Returns the parent XRISegment for this obj. Equivalent to all but /// the last SubSegment. /// </summary> /// <returns>The parent XRISegment of this obj</returns> public XRISegment getParent() { parse(); // return null if there isn't atleast 2 subsegments if ((this.moSubSegments == null) || (this.moSubSegments.Count <= 1)) { return null; } // return a XRISegment with the first n-1 subsegments XRISegment oParent = new XRISegment(mbAllowImpliedDelimiter, mbAllowColon, mbAllowReassignable); oParent.msValue = ""; oParent.moSubSegments = new List<XRISubSegment>(); oParent.mbParsed = true; oParent.mbParseResult = this.mbParseResult; for (int i = 0; i < (this.moSubSegments.Count - 1); i++) { XRISubSegment oSubseg = (XRISubSegment)this.moSubSegments[i]; oParent.moSubSegments.Add(oSubseg); oParent.msValue += oSubseg.ToString(); } return oParent; }