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

@@ -80,17 +80,19 @@ static const unsigned char pr2six[256] = {
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64};
size_t Base64Decode(raw_ostream& os, StringRef encoded) {
const unsigned char* end = encoded.bytes_begin();
while (pr2six[*end] <= 63 && end != encoded.bytes_end()) {
size_t Base64Decode(raw_ostream& os, std::string_view encoded) {
auto bytes_begin = reinterpret_cast<const unsigned char*>(encoded.data());
auto bytes_end = bytes_begin + encoded.size();
const unsigned char* end = bytes_begin;
while (pr2six[*end] <= 63 && end != bytes_end) {
++end;
}
size_t nprbytes = end - encoded.bytes_begin();
size_t nprbytes = end - bytes_begin;
if (nprbytes == 0) {
return 0;
}
const unsigned char* cur = encoded.bytes_begin();
const unsigned char* cur = bytes_begin;
while (nprbytes > 4) {
os << static_cast<unsigned char>(pr2six[cur[0]] << 2 | pr2six[cur[1]] >> 4);
@@ -111,10 +113,10 @@ size_t Base64Decode(raw_ostream& os, StringRef encoded) {
os << static_cast<unsigned char>(pr2six[cur[2]] << 6 | pr2six[cur[3]]);
}
return (end - encoded.bytes_begin()) + ((4 - nprbytes) & 3);
return (end - bytes_begin) + ((4 - nprbytes) & 3);
}
size_t Base64Decode(StringRef encoded, std::string* plain) {
size_t Base64Decode(std::string_view encoded, std::string* plain) {
plain->resize(0);
raw_string_ostream os(*plain);
size_t rv = Base64Decode(os, encoded);
@@ -122,8 +124,8 @@ size_t Base64Decode(StringRef encoded, std::string* plain) {
return rv;
}
StringRef Base64Decode(StringRef encoded, size_t* num_read,
SmallVectorImpl<char>& buf) {
std::string_view Base64Decode(std::string_view encoded, size_t* num_read,
SmallVectorImpl<char>& buf) {
buf.clear();
raw_svector_ostream os(buf);
*num_read = Base64Decode(os, encoded);
@@ -133,7 +135,7 @@ StringRef Base64Decode(StringRef encoded, size_t* num_read,
static const char basis_64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
void Base64Encode(raw_ostream& os, StringRef plain) {
void Base64Encode(raw_ostream& os, std::string_view plain) {
if (plain.empty()) {
return;
}
@@ -162,14 +164,15 @@ void Base64Encode(raw_ostream& os, StringRef plain) {
}
}
void Base64Encode(StringRef plain, std::string* encoded) {
void Base64Encode(std::string_view plain, std::string* encoded) {
encoded->resize(0);
raw_string_ostream os(*encoded);
Base64Encode(os, plain);
os.flush();
}
StringRef Base64Encode(StringRef plain, SmallVectorImpl<char>& buf) {
std::string_view Base64Encode(std::string_view plain,
SmallVectorImpl<char>& buf) {
buf.clear();
raw_svector_ostream os(buf);
Base64Encode(os, plain);