CStringRef -> cstring_view

This commit is contained in:
Victor Zverovich
2017-03-26 15:13:10 -07:00
parent 5aa8d6ea21
commit 12252152ac
10 changed files with 78 additions and 79 deletions
+1 -1
View File
@@ -45,7 +45,7 @@ class CustomPrintfArgFormatter : public printf_arg_formatter<char> {
}
};
std::string custom_vformat(fmt::CStringRef format_str, fmt::args args) {
std::string custom_vformat(fmt::cstring_view format_str, fmt::args args) {
fmt::memory_buffer buffer;
// Pass custom argument formatter as a template arg to vwrite.
fmt::vformat_to<CustomArgFormatter>(buffer, format_str, args);
+10 -11
View File
@@ -28,7 +28,6 @@
#include <cctype>
#include <cfloat>
#include <climits>
#include <clocale>
#include <cmath>
#include <cstring>
#include <memory>
@@ -58,7 +57,7 @@ using fmt::basic_writer;
using fmt::format;
using fmt::format_error;
using fmt::string_view;
using fmt::CStringRef;
using fmt::cstring_view;
using fmt::memory_buffer;
using fmt::wmemory_buffer;
using fmt::fill;
@@ -146,9 +145,9 @@ TEST(StringViewTest, ConvertToString) {
EXPECT_EQ("abc", s);
}
TEST(CStringRefTest, Ctor) {
EXPECT_STREQ("abc", CStringRef("abc").c_str());
EXPECT_STREQ("defg", CStringRef(std::string("defg")).c_str());
TEST(CStringViewTest, Ctor) {
EXPECT_STREQ("abc", cstring_view("abc").c_str());
EXPECT_STREQ("defg", cstring_view(std::string("defg")).c_str());
}
#if FMT_USE_TYPE_TRAITS
@@ -465,7 +464,7 @@ TEST(FormatterTest, ArgErrors) {
template <int N>
struct TestFormat {
template <typename... Args>
static std::string format(fmt::CStringRef format_str, const Args & ... args) {
static std::string format(fmt::cstring_view format_str, const Args & ... args) {
return TestFormat<N - 1>::format(format_str, N - 1, args...);
}
};
@@ -473,7 +472,7 @@ struct TestFormat {
template <>
struct TestFormat<0> {
template <typename... Args>
static std::string format(fmt::CStringRef format_str, const Args & ... args) {
static std::string format(fmt::cstring_view format_str, const Args & ... args) {
return fmt::format(format_str, args...);
}
};
@@ -1230,12 +1229,12 @@ TEST(FormatterTest, FormatString) {
EXPECT_EQ("test", format("{0}", std::string("test")));
}
TEST(FormatterTest, FormatStringRef) {
TEST(FormatterTest, FormatStringView) {
EXPECT_EQ("test", format("{0}", string_view("test")));
}
TEST(FormatterTest, FormatCStringRef) {
EXPECT_EQ("test", format("{0}", CStringRef("test")));
TEST(FormatterTest, FormatCStringView) {
EXPECT_EQ("test", format("{0}", cstring_view("test")));
}
void format_value(fmt::buffer &buf, const Date &d, fmt::context &) {
@@ -1513,7 +1512,7 @@ class MockArgFormatter : public fmt::internal::arg_formatter_base<char> {
void operator()(fmt::internal::custom_value<char>) {}
};
void custom_vformat(fmt::CStringRef format_str, fmt::args args) {
void custom_vformat(fmt::cstring_view format_str, fmt::args args) {
fmt::memory_buffer buffer;
fmt::vformat_to<MockArgFormatter>(buffer, format_str, args);
}
+1 -1
View File
@@ -213,7 +213,7 @@ int (test::fileno)(FILE *stream) {
# define EXPECT_EQ_POSIX(expected, actual)
#endif
void write_file(fmt::CStringRef filename, fmt::string_view content) {
void write_file(fmt::cstring_view filename, fmt::string_view content) {
fmt::BufferedFile f(filename, "w");
f.print("{}", content);
}