MCPcopy Create free account
hub / github.com/Kitware/VTK / read_line

Method read_line

ThirdParty/libproj/vtklibproj/src/filemanager.cpp:81–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79// ---------------------------------------------------------------------------
80
81std::string File::read_line(size_t maxLen, bool &maxLenReached,
82 bool &eofReached) {
83 constexpr size_t MAX_MAXLEN = 1024 * 1024;
84 maxLen = std::min(maxLen, MAX_MAXLEN);
85 while (true) {
86 // Consume existing lines in buffer
87 size_t pos = readLineBuffer_.find_first_of("\r\n");
88 if (pos != std::string::npos) {
89 if (pos > maxLen) {
90 std::string ret(readLineBuffer_.substr(0, maxLen));
91 readLineBuffer_ = readLineBuffer_.substr(maxLen);
92 maxLenReached = true;
93 eofReached = false;
94 return ret;
95 }
96 std::string ret(readLineBuffer_.substr(0, pos));
97 if (readLineBuffer_[pos] == '\r' &&
98 readLineBuffer_[pos + 1] == '\n') {
99 pos += 1;
100 }
101 readLineBuffer_ = readLineBuffer_.substr(pos + 1);
102 maxLenReached = false;
103 eofReached = false;
104 return ret;
105 }
106
107 const size_t prevSize = readLineBuffer_.size();
108 if (maxLen <= prevSize) {
109 std::string ret(readLineBuffer_.substr(0, maxLen));
110 readLineBuffer_ = readLineBuffer_.substr(maxLen);
111 maxLenReached = true;
112 eofReached = false;
113 return ret;
114 }
115
116 if (eofReadLine_) {
117 std::string ret = readLineBuffer_;
118 readLineBuffer_.clear();
119 maxLenReached = false;
120 eofReached = ret.empty();
121 return ret;
122 }
123
124 readLineBuffer_.resize(maxLen);
125 const size_t nRead =
126 read(&readLineBuffer_[prevSize], maxLen - prevSize);
127 if (nRead < maxLen - prevSize)
128 eofReadLine_ = true;
129 readLineBuffer_.resize(prevSize + nRead);
130 }
131}
132
133// ---------------------------------------------------------------------------
134

Callers 1

get_init_stringFunction · 0.80

Calls 5

minFunction · 0.50
sizeMethod · 0.45
clearMethod · 0.45
emptyMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected