/// <summary> Constructor. </summary> /// <param name="source"> Source for the. </param> public CharStream(Stream source) { sourceReader = new BinaryReader(source, Encoding); memory = new MemoryStream(); memoryReader = new BinaryReader(memory, Encoding); memoryWriter = new BinaryWriter(memory, Encoding); Position = new CharStreamPosition(0, 1, 1); }
private CharStream(MemoryStream memory, BinaryReader memoryReader, BinaryWriter memoryWriter, BinaryReader sourceReader, CharStreamPosition position) { this.sourceReader = sourceReader; this.memory = memory; this.memoryReader = memoryReader; this.memoryWriter = memoryWriter; Position = position; }
/// <summary> At position. </summary> /// <param name="position"> The position. </param> /// <returns> A CharStream. </returns> public CharStream AtPosition(CharStreamPosition position) { return(new CharStream(memory, memoryReader, memoryWriter, sourceReader, position)); }
private long CharsNeeded(long count, CharStreamPosition pos) { return(Math.Max(0, count - CharsAvalaible(pos))); }
private long CharsAvalaible(CharStreamPosition pos) { return(memory.Length - pos.Index); }