Use std::string_view and fmtlib across all libraries (#3402)

- Twine, StringRef, Format, and NativeFormatting have been removed
- Logging now uses fmtlib style formatting
- Nearly all uses of wpi::outs/errs have been replaced with fmt::print() or
std::puts()/std::fputs() (for unformatted strings).
- A wpi/fmt/raw_ostream.h header has been added to enable
fmt::print() with wpi::raw_ostream
This commit is contained in:
Peter Johnson
2021-06-06 16:13:58 -07:00
committed by GitHub
parent 4f1cecb8e7
commit b2c3b2dd8e
441 changed files with 5061 additions and 9749 deletions

View File

@@ -14,9 +14,9 @@
#include <cstdlib>
#include <cstring>
#include <string_view>
#include "wpi/SmallVector.h"
#include "wpi/StringRef.h"
#include "wpi/fs.h"
#if defined(_MSC_VER)
@@ -33,13 +33,13 @@
using namespace wpi;
StringRef raw_istream::getline(SmallVectorImpl<char>& buf, int maxLen) {
std::string_view raw_istream::getline(SmallVectorImpl<char>& buf, int maxLen) {
buf.clear();
for (int i = 0; i < maxLen; ++i) {
char c;
read(c);
if (has_error()) {
return StringRef{buf.data(), buf.size()};
return {buf.data(), buf.size()};
}
if (c == '\r') {
continue;
@@ -49,7 +49,7 @@ StringRef raw_istream::getline(SmallVectorImpl<char>& buf, int maxLen) {
break;
}
}
return StringRef{buf.data(), buf.size()};
return {buf.data(), buf.size()};
}
void raw_mem_istream::close() {}
@@ -69,16 +69,16 @@ void raw_mem_istream::read_impl(void* data, size_t len) {
set_read_count(len);
}
static int getFD(const Twine& Filename, std::error_code& EC) {
static int getFD(std::string_view Filename, std::error_code& EC) {
// Handle "-" as stdin. Note that when we do this, we consider ourself
// the owner of stdin. This means that we can do things like close the
// file descriptor when we're done and set the "binary" flag globally.
if (Filename.isSingleStringRef() && Filename.getSingleStringRef() == "-") {
if (Filename == "-") {
EC = std::error_code();
return STDIN_FILENO;
}
fs::file_t F = fs::OpenFileForRead(Filename.str(), EC);
fs::file_t F = fs::OpenFileForRead(Filename, EC);
if (EC) {
return -1;
}
@@ -89,7 +89,7 @@ static int getFD(const Twine& Filename, std::error_code& EC) {
return FD;
}
raw_fd_istream::raw_fd_istream(const Twine& filename, std::error_code& ec,
raw_fd_istream::raw_fd_istream(std::string_view filename, std::error_code& ec,
size_t bufSize)
: raw_fd_istream(getFD(filename, ec), true, bufSize) {}