MCPcopy Create free account
hub / github.com/OSGeo/PROJ / read_line

Method read_line

src/filemanager.cpp:93–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 2

get_init_stringFunction · 0.80
mainFunction · 0.80

Calls 3

sizeMethod · 0.80
clearMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected