/// <summary> /// Reads a stringe from the input and advances the position by the number of characters read. /// </summary> /// <param name="length">The number of characters to read.</param> /// <returns></returns> public Stringe ReadStringe(int length) { int p = _pos; _pos += length; return(_stringe.Substringe(p, length)); }
/// <summary> /// Returns a stringe whose endpoints are the specified stringes. The stringes must both belong to the same parent string. /// </summary> /// <param name="a">The first stringe.</param> /// <param name="b">The second stringe.</param> /// <returns></returns> public static Stringe Range(Stringe a, Stringe b) { if (a == null) { throw new ArgumentNullException("a"); } if (b == null) { throw new ArgumentNullException("b"); } if (a._stref != b._stref) { throw new ArgumentException("The stringes do not belong to the same parent."); } if (a == b) { return(a); } if (a.IsSubstringeOf(b)) { return(b); } if (b.IsSubstringeOf(a)) { return(a); } // Right side of A intersects left side of B. if (a._offset > b._offset && a._offset + a._length < b._offset + b._length) { return(a.Substringe(0, b._offset + b._length - a._offset)); } // Left side of A intersects right side of B. if (a._offset < b._offset + b._length && a._offset > b._offset) { return(b.Substringe(0, a._offset + a._length - b._offset)); } // A is to the left of B. if (a._offset + a._length <= b._offset) { return(a.Substringe(0, b._offset + b._length - a._offset)); } // B is to the left of A. if (b._offset + b._length <= a._offset) { return(b.Substringe(0, a._offset + a._length - b._offset)); } return(null); }