StringViewReader

StringViewReader is a subclass of StringReader that reads from a fixed-size memory buffer.

StringViewReader contains the same parse functions as StringReader as well as an additional family of functions, readView(), that take advantage of the underlying input source being a fixed-sized memory buffer.

One way to parse large files efficiently is to load the entire file in memory using TextFormat::createImporter(), create a StringViewReader to read from the loaded file, then call readView() instead of readString() to parse the contents. readView() avoids making additional string copies by returning StringViews into the already-loaded file. This is the approach taken, for example, by Plywood's built-in C++ parser.

Header File

#include <ply-runtime/io/text/StringReader.h>

Also included from <ply-runtime/Base.h>.

Member Functions

StringViewReader() [code]

Constructs an empty StringViewReader. You can replace it with a valid StringViewReader later using copy assignment.

StringViewReader(StringView view) [code]

Constructs a StringViewReader that reads the contents of view. view must remain valid for the lifetime of the StringViewReader.

void operator=(const StringViewReader& other) [code]

Copy assignment operator.

template <typename Type>
StringView readView(const decltype(fmt::TypeParser<Type>::defaultFormat())& format = fmt::TypeParser<Type>::defaultFormat()) [code]
template <typename Format, typename = void_t<decltype(fmt::FormatParser<Format>::parse)>>
StringView readView(const Format& format = {}) [code]

These functions are similar to StringReader's family of readString() functions except that they return a StringView into the existing memory buffer instead of copying data to a new String. For example, readView<fmt::Line>() returns a StringView that contains a single line of text terminated by '\n'.

StringView line = strViewReader.readView<fmt::Line>();

Members Inherited From ply::StringReader

  • StringReader()
  • StringReader(StringReader&& other)
  • StringReader(OptionallyOwned<InPipe>&& inPipe, u32 chunkSizeExp = DefaultChunkSizeExp)
  • bool anyParseError() const
  • template <typename Type>
    Type parse(const decltype(fmt::TypeParser<Type>::defaultFormat())& format = fmt::TypeParser<Type>::defaultFormat())
  • template <typename Format, typename = void_t<decltype(fmt::FormatParser<Format>::parse)>>
    auto parse(const Format& format = {})
  • template <typename Type>
    String readString(const decltype(fmt::TypeParser<Type>::defaultFormat())& format = fmt::TypeParser<Type>::defaultFormat())
  • template <typename Format, typename = void_t<decltype(fmt::FormatParser<Format>::parse)>>
    String readString(const Format& format = {})
  • String readRemainingContents()
  • StringView viewAvailable() const

Members Inherited From ply::InStream

  • u8* curByte
  • u8* endByte
  • InStream()
  • InStream(InStream&& other)
  • InStream(OptionallyOwned<InPipe>&& inPipe, u32 chunkSizeExp = DefaultChunkSizeExp)
  • void operator=(InStream&& other)
  • bool isView() const
  • bool atEOF() const
  • s32 numBytesAvailable() const
  • ConstBufferView viewAvailable() const
  • u64 getSeekPos() const
  • ChunkCursor getCursor() const
  • void rewind(ChunkCursor cursor)
  • u32 tryMakeBytesAvailable(u32 numBytes = 1)
  • char peekByte(u32 index = 0) const
  • void advanceByte(u32 numBytes = 1)
  • u8 readByte()
  • bool read(BufferView dst)
  • Buffer readRemainingContents()
  • ViewInStream* asViewInStream()
  • const ViewInStream* asViewInStream() const
  • StringReader* asStringReader()
  • StringViewReader* asStringViewReader()