Move ReadLine into raw_istream class as getline. (#20)

This commit is contained in:
Peter Johnson
2017-08-13 00:56:35 -07:00
committed by GitHub
parent 17b5cace5b
commit 7d9e6b7e22
4 changed files with 35 additions and 33 deletions

View File

@@ -16,8 +16,25 @@
#include <unistd.h>
#endif
#include "llvm/SmallVector.h"
#include "llvm/StringRef.h"
using namespace wpi;
llvm::StringRef raw_istream::getline(llvm::SmallVectorImpl<char>& buf,
int maxLen) {
buf.clear();
for (int i = 0; i < maxLen; ++i) {
char c;
read(c);
if (has_error()) return llvm::StringRef{buf.data(), buf.size()};
if (c == '\r') continue;
buf.push_back(c);
if (c == '\n') break;
}
return llvm::StringRef{buf.data(), buf.size()};
}
void raw_mem_istream::close() {}
std::size_t raw_mem_istream::in_avail() const { return m_left; }