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

@@ -38,7 +38,7 @@ SOFTWARE.
#include <cmath>
#include <cstdlib>
#include "wpi/Format.h"
#include "fmt/format.h"
#include "wpi/SmallString.h"
#include "wpi/raw_istream.h"
#include "wpi/raw_ostream.h"
@@ -336,7 +336,7 @@ class json::lexer
}
/// return current string value
StringRef get_string()
std::string_view get_string()
{
return token_buffer;
}
@@ -1407,7 +1407,7 @@ std::string json::lexer::get_token_string() const
if (c <= '\x1F')
{
// escape control characters
ss << "<U+" << format_hex_no_prefix(c, 4, true) << '>';
ss << fmt::format("<U+{:04X}>", c);
}
else
{
@@ -1605,7 +1605,7 @@ void json::parser::parse_internal(bool keep, json& result)
if (keep and keep_tag and not value.is_discarded())
{
result.m_value.object->try_emplace(StringRef(key.data(), key.size()), std::move(value));
result.m_value.object->try_emplace(std::string_view(key.data(), key.size()), std::move(value));
}
// comma -> next value
@@ -1757,8 +1757,8 @@ void json::parser::parse_internal(bool keep, json& result)
{
if (allow_exceptions)
{
JSON_THROW(out_of_range::create(406, "number overflow parsing '" +
Twine(m_lexer.get_token_string()) + "'"));
JSON_THROW(out_of_range::create(406,
fmt::format("number overflow parsing '{}'", m_lexer.get_token_string())));
}
expect(token_type::uninitialized);
}
@@ -1917,7 +1917,7 @@ void json::parser::throw_exception() const
JSON_THROW(parse_error::create(101, m_lexer.get_position(), error_msg));
}
json json::parse(StringRef s,
json json::parse(std::string_view s,
const parser_callback_t cb,
const bool allow_exceptions)
{
@@ -1942,7 +1942,7 @@ json json::parse(raw_istream& i,
return result;
}
bool json::accept(StringRef s)
bool json::accept(std::string_view s)
{
raw_mem_istream is(makeArrayRef(s.data(), s.size()));
return parser(is).accept(true);