diff --git a/fmt/format.h b/fmt/format.h index ed706466..3767a955 100644 --- a/fmt/format.h +++ b/fmt/format.h @@ -1016,7 +1016,7 @@ struct Value { StringValue string; StringValue sstring; StringValue ustring; - StringValue wstring; + StringValue wstring; // TODO: Char CustomValue custom; }; @@ -1114,9 +1114,9 @@ typename std::result_of::type case format_arg::CSTRING: return vis(arg.string.value); case format_arg::STRING: - return vis(arg.string); + return vis(StringRef(arg.string.value, arg.string.size)); case format_arg::WSTRING: - return vis(arg.wstring); + return vis(WStringRef(arg.wstring.value, arg.wstring.size)); case format_arg::POINTER: return vis(arg.pointer); case format_arg::CUSTOM: @@ -1954,7 +1954,7 @@ class ArgFormatterBase { } template - void write_str(format_arg::StringValue value, + void write_str(BasicStringRef value, typename EnableIf< std::is_same::value && std::is_same::value, int>::type = 0) { @@ -1962,7 +1962,7 @@ class ArgFormatterBase { } template - void write_str(format_arg::StringValue value, + void write_str(BasicStringRef value, typename EnableIf< !std::is_same::value || !std::is_same::value, int>::type = 0) { @@ -1974,16 +1974,12 @@ class ArgFormatterBase { FormatSpec &spec() { return spec_; } void write(bool value) { - const char *str_value = value ? "true" : "false"; - format_arg::StringValue str = { str_value, std::strlen(str_value) }; - writer_.write_str(str, spec_); + writer_.write_str(StringRef(value ? "true" : "false"), spec_); } void write(const char *value) { - format_arg::StringValue str = { - value, value != 0 ? std::strlen(value) : 0 - }; - writer_.write_str(str, spec_); + writer_.write_str( + StringRef(value, value != 0 ? std::strlen(value) : 0), spec_); } public: @@ -2042,11 +2038,11 @@ class ArgFormatterBase { write(value); } - void operator()(format_arg::StringValue value) { + void operator()(StringRef value) { writer_.write_str(value, spec_); } - void operator()(format_arg::StringValue value) { + void operator()(BasicStringRef value) { write_str(value); } @@ -2339,8 +2335,7 @@ class BasicWriter { CharPtr write_str(const StrChar *s, std::size_t size, const AlignSpec &spec); template - void write_str(const format_arg::StringValue &str, - const FormatSpec &spec); + void write_str(BasicStringRef str, const FormatSpec &spec); // This following methods are private to disallow writing wide characters // and strings to a char stream. If you want to print a wide string as a @@ -2563,13 +2558,13 @@ typename BasicWriter::CharPtr BasicWriter::write_str( template template void BasicWriter::write_str( - const format_arg::StringValue &s, const FormatSpec &spec) { + BasicStringRef s, const FormatSpec &spec) { // Check if StrChar is convertible to Char. internal::CharTraits::convert(StrChar()); if (spec.type_ && spec.type_ != 's') internal::report_unknown_type(spec.type_, "string"); - const StrChar *str_value = s.value; - std::size_t str_size = s.size; + const StrChar *str_value = s.data(); + std::size_t str_size = s.size(); if (str_size == 0) { if (!str_value) { FMT_THROW(format_error("string pointer is null")); diff --git a/test/util-test.cc b/test/util-test.cc index c39b0abf..f550f3ae 100644 --- a/test/util-test.cc +++ b/test/util-test.cc @@ -437,12 +437,6 @@ namespace internal { bool operator==(Value::CustomValue lhs, Value::CustomValue rhs) { return lhs.value == rhs.value; } - -template -bool operator==(Value::StringValue lhs, Value::StringValue rhs) { - return std::basic_string(lhs.value, lhs.size) == - std::basic_string(rhs.value, rhs.size); -} } } @@ -542,11 +536,10 @@ TEST(UtilTest, StringArg) { CHECK_ARG_(wchar_t, cstr, str); CHECK_ARG(cstr); - Value::StringValue strval = {str, 4}; - CHECK_ARG_(char, strval, std::string(str)); - CHECK_ARG_(wchar_t, strval, std::string(str)); - CHECK_ARG_(char, strval, fmt::StringRef(str)); - CHECK_ARG_(wchar_t, strval, fmt::StringRef(str)); + StringRef sref(str); + CHECK_ARG_(char, sref, std::string(str)); + CHECK_ARG_(wchar_t, sref, std::string(str)); + CHECK_ARG(sref); } TEST(UtilTest, WStringArg) { @@ -554,11 +547,11 @@ TEST(UtilTest, WStringArg) { wchar_t *str = str_data; const wchar_t *cstr = str; - Value::StringValue strval = {str, 4}; - CHECK_ARG_(wchar_t, strval, str); - CHECK_ARG_(wchar_t, strval, cstr); - CHECK_ARG_(wchar_t, strval, std::wstring(str)); - CHECK_ARG_(wchar_t, strval, fmt::WStringRef(str)); + fmt::WStringRef sref(str); + CHECK_ARG_(wchar_t, sref, str); + CHECK_ARG_(wchar_t, sref, cstr); + CHECK_ARG_(wchar_t, sref, std::wstring(str)); + CHECK_ARG_(wchar_t, sref, fmt::WStringRef(str)); } TEST(UtilTest, PointerArg) {