LLVM 20.0.0git
Public Types | Public Member Functions | Friends | List of all members
llvm::line_iterator Class Reference

A forward iterator which reads text lines from a buffer. More...

#include "llvm/Support/LineIterator.h"

Public Types

using iterator_category = std::forward_iterator_tag
 
using value_type = StringRef
 
using difference_type = std::ptrdiff_t
 
using pointer = value_type *
 
using reference = value_type &
 

Public Member Functions

 line_iterator ()=default
 Default construct an "end" iterator.
 
 line_iterator (const MemoryBufferRef &Buffer, bool SkipBlanks=true, char CommentMarker='\0')
 Construct a new iterator around an unowned memory buffer.
 
 line_iterator (const MemoryBuffer &Buffer, bool SkipBlanks=true, char CommentMarker='\0')
 Construct a new iterator around some memory buffer.
 
bool is_at_eof () const
 Return true if we've reached EOF or are an "end" iterator.
 
bool is_at_end () const
 Return true if we're an "end" iterator or have reached EOF.
 
int64_t line_number () const
 Return the current line number. May return any number at EOF.
 
line_iteratoroperator++ ()
 Advance to the next (non-empty, non-comment) line.
 
line_iterator operator++ (int)
 
StringRef operator* () const
 Get the current line as a StringRef.
 
const StringRefoperator-> () const
 

Friends

bool operator== (const line_iterator &LHS, const line_iterator &RHS)
 
bool operator!= (const line_iterator &LHS, const line_iterator &RHS)
 

Detailed Description

A forward iterator which reads text lines from a buffer.

This class provides a forward iterator interface for reading one line at a time from a buffer. When default constructed the iterator will be the "end" iterator.

The iterator is aware of what line number it is currently processing. It strips blank lines by default, and comment lines given a comment-starting character.

Note that this iterator requires the buffer to be nul terminated.

Definition at line 33 of file LineIterator.h.

Member Typedef Documentation

◆ difference_type

using llvm::line_iterator::difference_type = std::ptrdiff_t

Definition at line 44 of file LineIterator.h.

◆ iterator_category

using llvm::line_iterator::iterator_category = std::forward_iterator_tag

Definition at line 42 of file LineIterator.h.

◆ pointer

Definition at line 45 of file LineIterator.h.

◆ reference

Definition at line 46 of file LineIterator.h.

◆ value_type

Definition at line 43 of file LineIterator.h.

Constructor & Destructor Documentation

◆ line_iterator() [1/3]

llvm::line_iterator::line_iterator ( )
default

Default construct an "end" iterator.

◆ line_iterator() [2/3]

line_iterator::line_iterator ( const MemoryBufferRef Buffer,
bool  SkipBlanks = true,
char  CommentMarker = '\0' 
)
explicit

Construct a new iterator around an unowned memory buffer.

Definition at line 38 of file LineIterator.cpp.

References assert(), llvm::MemoryBufferRef::getBufferEnd(), llvm::MemoryBufferRef::getBufferSize(), llvm::MemoryBufferRef::getBufferStart(), and isAtLineEnd().

◆ line_iterator() [3/3]

line_iterator::line_iterator ( const MemoryBuffer Buffer,
bool  SkipBlanks = true,
char  CommentMarker = '\0' 
)
explicit

Construct a new iterator around some memory buffer.

Definition at line 34 of file LineIterator.cpp.

Member Function Documentation

◆ is_at_end()

bool llvm::line_iterator::is_at_end ( ) const
inline

Return true if we're an "end" iterator or have reached EOF.

Definition at line 63 of file LineIterator.h.

References is_at_eof().

Referenced by llvm::TextInstrProfReader::readNextRecord(), and llvm::ForceFunctionAttrsPass::run().

◆ is_at_eof()

bool llvm::line_iterator::is_at_eof ( ) const
inline

◆ line_number()

int64_t llvm::line_iterator::line_number ( ) const
inline

Return the current line number. May return any number at EOF.

Definition at line 66 of file LineIterator.h.

Referenced by llvm::SymbolRemappingReader::read(), llvm::sampleprof::SampleProfileReaderText::readImpl(), and llvm::ForceFunctionAttrsPass::run().

◆ operator*()

StringRef llvm::line_iterator::operator* ( ) const
inline

Get the current line as a StringRef.

Definition at line 80 of file LineIterator.h.

◆ operator++() [1/2]

line_iterator & llvm::line_iterator::operator++ ( )
inline

Advance to the next (non-empty, non-comment) line.

Definition at line 69 of file LineIterator.h.

◆ operator++() [2/2]

line_iterator llvm::line_iterator::operator++ ( int  )
inline

Definition at line 73 of file LineIterator.h.

◆ operator->()

const StringRef * llvm::line_iterator::operator-> ( ) const
inline

Definition at line 81 of file LineIterator.h.

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const line_iterator LHS,
const line_iterator RHS 
)
friend

Definition at line 88 of file LineIterator.h.

◆ operator==

bool operator== ( const line_iterator LHS,
const line_iterator RHS 
)
friend

Definition at line 83 of file LineIterator.h.


The documentation for this class was generated from the following files: