OGS
ChemistryLib::PhreeqcIOData::anonymous_namespace{PhreeqcIO.cpp}::StringViewLineIterator Class Reference

Detailed Description

Definition at line 48 of file PhreeqcIO.cpp.

Public Member Functions

 StringViewLineIterator (std::string_view text, std::size_t pos=0)
bool getline (std::string_view &line)
void skip (int num_lines)

Private Attributes

std::string_view text_
std::size_t pos_

Constructor & Destructor Documentation

◆ StringViewLineIterator()

ChemistryLib::PhreeqcIOData::anonymous_namespace{PhreeqcIO.cpp}::StringViewLineIterator::StringViewLineIterator ( std::string_view text,
std::size_t pos = 0 )
inline

Member Function Documentation

◆ getline()

bool ChemistryLib::PhreeqcIOData::anonymous_namespace{PhreeqcIO.cpp}::StringViewLineIterator::getline ( std::string_view & line)
inline

Definition at line 56 of file PhreeqcIO.cpp.

57 {
58 if (pos_ >= text_.size())
59 {
60 return false;
61 }
62
63 if (const auto newline_pos = text_.find('\n', pos_);
64 newline_pos == std::string_view::npos)
65 {
66 line = text_.substr(pos_);
67 pos_ = text_.size();
68 }
69 else
70 {
71 line = text_.substr(pos_, newline_pos - pos_);
72 pos_ = newline_pos + 1;
73 }
74
75 // Remove trailing \r if present (Windows line endings)
76 if (!line.empty() && line.back() == '\r')
77 {
78 line.remove_suffix(1);
79 }
80
81 return true;
82 }

References pos_, and text_.

◆ skip()

void ChemistryLib::PhreeqcIOData::anonymous_namespace{PhreeqcIO.cpp}::StringViewLineIterator::skip ( int num_lines)
inline

Definition at line 84 of file PhreeqcIO.cpp.

85 {
86 for (int i = 0; i < num_lines && pos_ < text_.size(); ++i)
87 {
88 const auto newline_pos = text_.find('\n', pos_);
89 pos_ = (newline_pos == std::string_view::npos) ? text_.size()
90 : newline_pos + 1;
91 }
92 }

References pos_, and text_.

Member Data Documentation

◆ pos_

std::size_t ChemistryLib::PhreeqcIOData::anonymous_namespace{PhreeqcIO.cpp}::StringViewLineIterator::pos_
private

Definition at line 96 of file PhreeqcIO.cpp.

Referenced by StringViewLineIterator(), getline(), and skip().

◆ text_

std::string_view ChemistryLib::PhreeqcIOData::anonymous_namespace{PhreeqcIO.cpp}::StringViewLineIterator::text_
private

Definition at line 95 of file PhreeqcIO.cpp.

Referenced by StringViewLineIterator(), getline(), and skip().


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