Function readUntil
stream
until the specified end marker is detected.
Prototypes
ubyte[] readUntil( InputStream stream, const(ubyte[]) end_marker, uint max_bytes, Allocator alloc ); void readUntil( InputStream stream, OutputStream dst, const(ubyte[]) end_marker, ulong max_bytes );
Parameters
Returns
The string variant of this function returns the complete prefix to the
end marker of the input stream
, excluding the end marker itself.
Throws
An exception if either the stream
end was hit without hitting a marker
first, or if more than max_bytes
have been read from the stream
in
case of max_bytes
!= 0.
Remarks
This function uses an algorithm inspired by the Boyer-Moore string search algorithm. However, contrary to the original algorithm, it will scan the whole input string exactly once, without jumping over portions of it. This allows the algorithm to work with constant memory requirements and without the memory copies that would be necessary for streams that do not hold their complete data in memory.
The current implementation has a run time complexity of O(n*m+m²) and O(n+m) in typical cases, with n being the length of the scanned input string and m the length of the marker.
Authors
Sönke Ludwig
Copyright
© 2012 RejectedSoftware e.K.
License
Subject to the terms of the MIT license, as written in the included LICENSE.txt file.