Commit 9773e441 authored by Phil Willoughby's avatar Phil Willoughby Committed by Facebook Github Bot

Run clang-format over Format*.h

Summary:
Changes are planned, this will make it easier for the new code to look good
without making the older code look weird.

Reviewed By: yfeldblum

Differential Revision: D4514839

fbshipit-source-id: 43f8cd7d85901e1915cc434a0f4b5fd6bce1ec7a
parent 3259ce0e
main v2022.02.14.00 v2022.02.07.00 v2022.01.31.00 v2022.01.24.00 v2022.01.17.00 v2022.01.10.00 v2022.01.03.00 v2021.12.27.00 v2021.12.20.00 v2021.12.13.00 v2021.12.06.00 v2021.11.29.00 v2021.11.15.00 v2021.11.08.00 v2021.11.01.00 v2021.10.25.00 v2021.10.18.00 v2021.10.11.00 v2021.10.04.00 v2021.09.27.00 v2021.09.20.00 v2021.09.13.00 v2021.09.06.00 v2021.08.30.00 v2021.08.23.00 v2021.08.02.00 v2021.07.22.00 v2021.07.20.01 v2021.07.20.00 v2021.06.28.00 v2021.06.14.00 v2021.06.07.00 v2021.05.31.00 v2021.05.24.00 v2021.05.17.00 v2021.05.10.00 v2021.05.03.00 v2021.04.26.00 v2021.04.19.00 v2021.04.12.00 v2021.04.05.00 v2021.03.29.00 v2021.03.22.00 v2021.03.15.00 v2021.03.08.00 v2021.03.01.00 v2021.02.22.00 v2021.02.15.00 v2021.02.08.00 v2021.02.01.00 v2021.01.25.00 v2021.01.18.01 v2021.01.18.00 v2021.01.11.00 v2021.01.04.00 v2020.12.28.00 v2020.12.21.00 v2020.12.14.00 v2020.12.07.00 v2020.11.30.00 v2020.11.23.00 v2020.11.16.00 v2020.11.09.00 v2020.11.02.00 v2020.10.26.00 v2020.10.19.00 v2020.10.12.00 v2020.10.05.00 v2020.09.28.00 v2020.09.21.00 v2020.09.14.00 v2020.09.07.00 v2020.08.31.00 v2020.08.24.00 v2020.08.17.00 v2020.08.10.00 v2020.08.03.00 v2020.07.27.00 v2020.07.20.00 v2020.07.13.00 v2020.07.06.00 v2020.06.29.00 v2020.06.15.00 v2020.06.08.00 v2020.06.01.00 v2020.05.25.00 v2020.05.18.00 v2020.05.11.00 v2020.05.04.00 v2020.04.27.00 v2020.04.20.00 v2020.04.13.00 v2020.04.06.00 v2020.03.30.00 v2020.03.23.00 v2020.03.16.00 v2020.03.09.00 v2020.03.02.00 v2020.02.24.00 v2020.02.17.00 v2020.02.10.00 v2020.02.03.00 v2020.01.27.00 v2020.01.20.00 v2020.01.13.00 v2020.01.06.00 v2019.12.30.00 v2019.12.23.00 v2019.12.16.00 v2019.12.09.00 v2019.12.06.00 v2019.12.02.00 v2019.11.11.00 v2019.11.04.00 v2019.10.28.00 v2019.10.21.00 v2019.10.14.00 v2019.10.07.00 v2019.09.30.00 v2019.09.23.00 v2019.09.16.00 v2019.09.09.00 v2019.09.02.00 v2019.08.26.00 v2019.08.19.00 v2019.08.12.00 v2019.08.05.00 v2019.07.29.00 v2019.07.22.00 v2019.06.17.00 v2019.06.10.00 v2019.06.03.00 v2019.05.27.00 v2019.05.20.00 v2019.05.13.00 v2019.05.06.00 v2019.04.29.00 v2019.04.22.00 v2019.04.15.00 v2019.04.08.00 v2019.04.01.00 v2019.03.25.00 v2019.03.18.00 v2019.03.04.00 v2019.02.25.00 v2019.02.18.00 v2019.02.11.00 v2019.02.04.00 v2019.01.28.00 v2019.01.21.00 v2019.01.14.00 v2019.01.07.00 v2018.12.31.00 v2018.12.24.00 v2018.12.17.00 v2018.12.10.00 v2018.12.03.00 v2018.11.26.00 v2018.11.19.00 v2018.11.12.00 v2018.11.05.00 v2018.10.29.00 v2018.10.22.00 v2018.10.15.00 v2018.10.08.00 v2018.10.01.00 v2018.09.24.00 v2018.09.17.00 v2018.09.10.01 v2018.09.10.00 v2018.09.03.01 v2018.09.03.00 v2018.08.27.00 v2018.08.20.00 v2018.08.13.00 v2018.08.09.00 v2018.08.06.00 v2018.07.30.00 v2018.07.23.00 v2018.07.16.00 v2018.07.09.00 v2018.07.02.00 v2018.06.25.00 v2018.06.18.00 v2018.06.11.00 v2018.06.04.00 v2018.05.28.00 v2018.05.21.00 v2018.05.14.00 v2018.05.07.00 v2018.04.30.00 v2018.04.23.00 v2018.04.16.00 v2018.04.09.00 v2018.04.02.00 v2018.03.26.00 v2018.03.19.00 v2018.03.12.00 v2018.03.05.00 v2018.02.26.00 v2018.02.19.00 v2018.02.12.00 v2018.02.05.00 v2018.01.29.00 v2018.01.22.00 v2018.01.15.00 v2018.01.08.00 v2018.01.01.00 v2017.12.25.00 v2017.12.18.00 v2017.12.11.00 v2017.12.04.00 v2017.11.27.00 v2017.11.20.00 v2017.11.13.00 v2017.11.06.00 v2017.10.30.00 v2017.10.23.00 v2017.10.16.00 v2017.10.09.00 v2017.10.02.00 v2017.09.25.00 v2017.09.18.00 v2017.09.11.00 v2017.09.04.00 v2017.08.28.00 v2017.08.21.00 v2017.08.14.00 v2017.08.07.00 v2017.07.31.00 v2017.07.24.00 v2017.07.17.01 v2017.07.17.00 v2017.07.10.00 v2017.07.03.00 v2017.06.26.01 v2017.06.26.00 v2017.06.19.00 v2017.06.12.00 v2017.06.05.00 v2017.05.29.00 v2017.05.22.00 v2017.05.15.00 v2017.05.08.00 v2017.05.01.00 v2017.04.24.00 v2017.04.17.00 v2017.04.10.00 v2017.04.03.00 v2017.03.27.00 v2017.03.20.00 v2017.03.13.00 v2017.03.06.00
No related merge requests found
This diff is collapsed.
...@@ -22,10 +22,10 @@ ...@@ -22,10 +22,10 @@
#include <type_traits> #include <type_traits>
#include <folly/Conv.h> #include <folly/Conv.h>
#include <folly/FormatArg.h>
#include <folly/Range.h> #include <folly/Range.h>
#include <folly/Traits.h>
#include <folly/String.h> #include <folly/String.h>
#include <folly/FormatArg.h> #include <folly/Traits.h>
// Ignore shadowing warnings within this file, so includers can use -Wshadow. // Ignore shadowing warnings within this file, so includers can use -Wshadow.
#pragma GCC diagnostic push #pragma GCC diagnostic push
...@@ -34,12 +34,14 @@ ...@@ -34,12 +34,14 @@
namespace folly { namespace folly {
// forward declarations // forward declarations
template <bool containerMode, class... Args> class Formatter; template <bool containerMode, class... Args>
class Formatter;
template <class... Args> template <class... Args>
Formatter<false, Args...> format(StringPiece fmt, Args&&... args); Formatter<false, Args...> format(StringPiece fmt, Args&&... args);
template <class C> template <class C>
Formatter<true, C> vformat(StringPiece fmt, C&& container); Formatter<true, C> vformat(StringPiece fmt, C&& container);
template <class T, class Enable=void> class FormatValue; template <class T, class Enable = void>
class FormatValue;
// meta-attribute to identify formatters in this sea of template weirdness // meta-attribute to identify formatters in this sea of template weirdness
namespace detail { namespace detail {
...@@ -71,9 +73,9 @@ class BaseFormatter { ...@@ -71,9 +73,9 @@ class BaseFormatter {
* Append to a string. * Append to a string.
*/ */
template <class Str> template <class Str>
typename std::enable_if<IsSomeString<Str>::value>::type typename std::enable_if<IsSomeString<Str>::value>::type appendTo(
appendTo(Str& str) const { Str& str) const {
auto appender = [&str] (StringPiece s) { str.append(s.data(), s.size()); }; auto appender = [&str](StringPiece s) { str.append(s.data(), s.size()); };
(*this)(appender); (*this)(appender);
} }
...@@ -102,8 +104,8 @@ class BaseFormatter { ...@@ -102,8 +104,8 @@ class BaseFormatter {
typedef BaseFormatter BaseType; typedef BaseFormatter BaseType;
private: private:
typedef std::tuple<FormatValue< typedef std::tuple<FormatValue<typename std::decay<Args>::type>...>
typename std::decay<Args>::type>...> ValueTuple; ValueTuple;
static constexpr size_t valueCount = std::tuple_size<ValueTuple>::value; static constexpr size_t valueCount = std::tuple_size<ValueTuple>::value;
template <size_t K, class Callback> template <size_t K, class Callback>
...@@ -118,7 +120,7 @@ class BaseFormatter { ...@@ -118,7 +120,7 @@ class BaseFormatter {
if (i == K) { if (i == K) {
static_cast<const Derived*>(this)->template doFormatArg<K>(arg, cb); static_cast<const Derived*>(this)->template doFormatArg<K>(arg, cb);
} else { } else {
doFormatFrom<K+1>(i, arg, cb); doFormatFrom<K + 1>(i, arg, cb);
} }
} }
...@@ -128,32 +130,36 @@ class BaseFormatter { ...@@ -128,32 +130,36 @@ class BaseFormatter {
} }
template <size_t K> template <size_t K>
typename std::enable_if<K == valueCount, int>::type typename std::enable_if<K == valueCount, int>::type getSizeArgFrom(
getSizeArgFrom(size_t i, const FormatArg& arg) const { size_t i,
const FormatArg& arg) const {
arg.error("argument index out of range, max=", i); arg.error("argument index out of range, max=", i);
} }
template <class T> template <class T>
typename std::enable_if<std::is_integral<T>::value && typename std::enable_if<
!std::is_same<T, bool>::value, int>::type std::is_integral<T>::value && !std::is_same<T, bool>::value,
int>::type
getValue(const FormatValue<T>& format, const FormatArg&) const { getValue(const FormatValue<T>& format, const FormatArg&) const {
return static_cast<int>(format.getValue()); return static_cast<int>(format.getValue());
} }
template <class T> template <class T>
typename std::enable_if<!std::is_integral<T>::value || typename std::enable_if<
std::is_same<T, bool>::value, int>::type !std::is_integral<T>::value || std::is_same<T, bool>::value,
int>::type
getValue(const FormatValue<T>&, const FormatArg& arg) const { getValue(const FormatValue<T>&, const FormatArg& arg) const {
arg.error("dynamic field width argument must be integral"); arg.error("dynamic field width argument must be integral");
} }
template <size_t K> template <size_t K>
typename std::enable_if<K < valueCount, int>::type typename std::enable_if <
getSizeArgFrom(size_t i, const FormatArg& arg) const { K<valueCount, int>::type getSizeArgFrom(size_t i, const FormatArg& arg)
const {
if (i == K) { if (i == K) {
return getValue(std::get<K>(values_), arg); return getValue(std::get<K>(values_), arg);
} }
return getSizeArgFrom<K+1>(i, arg); return getSizeArgFrom<K + 1>(i, arg);
} }
int getSizeArg(size_t i, const FormatArg& arg) const { int getSizeArg(size_t i, const FormatArg& arg) const {
...@@ -181,23 +187,26 @@ class BaseFormatter { ...@@ -181,23 +187,26 @@ class BaseFormatter {
}; };
template <bool containerMode, class... Args> template <bool containerMode, class... Args>
class Formatter : public BaseFormatter<Formatter<containerMode, Args...>, class Formatter : public BaseFormatter<
containerMode, Formatter<containerMode, Args...>,
Args...> { containerMode,
Args...> {
private: private:
explicit Formatter(StringPiece& str, Args&&... args) explicit Formatter(StringPiece& str, Args&&... args)
: BaseFormatter<Formatter<containerMode, Args...>, : BaseFormatter<
containerMode, Formatter<containerMode, Args...>,
Args...>(str, std::forward<Args>(args)...) {} containerMode,
Args...>(str, std::forward<Args>(args)...) {}
template <size_t K, class Callback> template <size_t K, class Callback>
void doFormatArg(FormatArg& arg, Callback& cb) const { void doFormatArg(FormatArg& arg, Callback& cb) const {
std::get<K>(this->values_).format(arg, cb); std::get<K>(this->values_).format(arg, cb);
} }
friend class BaseFormatter<Formatter<containerMode, Args...>, friend class BaseFormatter<
containerMode, Formatter<containerMode, Args...>,
Args...>; containerMode,
Args...>;
template <class... A> template <class... A>
friend Formatter<false, A...> format(StringPiece fmt, A&&... arg); friend Formatter<false, A...> format(StringPiece fmt, A&&... arg);
...@@ -208,9 +217,10 @@ class Formatter : public BaseFormatter<Formatter<containerMode, Args...>, ...@@ -208,9 +217,10 @@ class Formatter : public BaseFormatter<Formatter<containerMode, Args...>,
/** /**
* Formatter objects can be written to streams. * Formatter objects can be written to streams.
*/ */
template<bool containerMode, class... Args> template <bool containerMode, class... Args>
std::ostream& operator<<(std::ostream& out, std::ostream& operator<<(
const Formatter<containerMode, Args...>& formatter) { std::ostream& out,
const Formatter<containerMode, Args...>& formatter) {
auto writer = [&out](StringPiece sp) { auto writer = [&out](StringPiece sp) {
out.write(sp.data(), std::streamsize(sp.size())); out.write(sp.data(), std::streamsize(sp.size()));
}; };
...@@ -222,8 +232,9 @@ std::ostream& operator<<(std::ostream& out, ...@@ -222,8 +232,9 @@ std::ostream& operator<<(std::ostream& out,
* Formatter objects can be written to stdio FILEs. * Formatter objects can be written to stdio FILEs.
*/ */
template <class Derived, bool containerMode, class... Args> template <class Derived, bool containerMode, class... Args>
void writeTo(FILE* fp, void writeTo(
const BaseFormatter<Derived, containerMode, Args...>& formatter); FILE* fp,
const BaseFormatter<Derived, containerMode, Args...>& formatter);
/** /**
* Create a formatter object. * Create a formatter object.
...@@ -234,8 +245,7 @@ void writeTo(FILE* fp, ...@@ -234,8 +245,7 @@ void writeTo(FILE* fp,
*/ */
template <class... Args> template <class... Args>
Formatter<false, Args...> format(StringPiece fmt, Args&&... args) { Formatter<false, Args...> format(StringPiece fmt, Args&&... args) {
return Formatter<false, Args...>( return Formatter<false, Args...>(fmt, std::forward<Args>(args)...);
fmt, std::forward<Args>(args)...);
} }
/** /**
...@@ -262,8 +272,7 @@ inline std::string sformat(StringPiece fmt, Args&&... args) { ...@@ -262,8 +272,7 @@ inline std::string sformat(StringPiece fmt, Args&&... args) {
*/ */
template <class Container> template <class Container>
Formatter<true, Container> vformat(StringPiece fmt, Container&& container) { Formatter<true, Container> vformat(StringPiece fmt, Container&& container) {
return Formatter<true, Container>( return Formatter<true, Container>(fmt, std::forward<Container>(container));
fmt, std::forward<Container>(container));
} }
/** /**
...@@ -283,20 +292,20 @@ inline std::string svformat(StringPiece fmt, Container&& container) { ...@@ -283,20 +292,20 @@ inline std::string svformat(StringPiece fmt, Container&& container) {
* format("[no_such_key"], defaulted(map, 42)) -> 42 * format("[no_such_key"], defaulted(map, 42)) -> 42
*/ */
namespace detail { namespace detail {
template <class Container, class Value> struct DefaultValueWrapper { template <class Container, class Value>
struct DefaultValueWrapper {
DefaultValueWrapper(const Container& container, const Value& defaultValue) DefaultValueWrapper(const Container& container, const Value& defaultValue)
: container(container), : container(container), defaultValue(defaultValue) {}
defaultValue(defaultValue) {
}
const Container& container; const Container& container;
const Value& defaultValue; const Value& defaultValue;
}; };
} // namespace } // namespace
template <class Container, class Value> template <class Container, class Value>
detail::DefaultValueWrapper<Container, Value> detail::DefaultValueWrapper<Container, Value> defaulted(
defaulted(const Container& c, const Value& v) { const Container& c,
const Value& v) {
return detail::DefaultValueWrapper<Container, Value>(c, v); return detail::DefaultValueWrapper<Container, Value>(c, v);
} }
...@@ -345,25 +354,28 @@ void formatString(StringPiece val, FormatArg& arg, FormatCallback& cb); ...@@ -345,25 +354,28 @@ void formatString(StringPiece val, FormatArg& arg, FormatCallback& cb);
* field width") * field width")
*/ */
template <class FormatCallback> template <class FormatCallback>
void formatNumber(StringPiece val, int prefixLen, FormatArg& arg, void formatNumber(
FormatCallback& cb); StringPiece val,
int prefixLen,
FormatArg& arg,
FormatCallback& cb);
/** /**
* Format a Formatter object recursively. Behaves just like * Format a Formatter object recursively. Behaves just like
* formatString(fmt.str(), arg, cb); but avoids creating a temporary * formatString(fmt.str(), arg, cb); but avoids creating a temporary
* string if possible. * string if possible.
*/ */
template <class FormatCallback, template <
class Derived, class FormatCallback,
bool containerMode, class Derived,
class... Args> bool containerMode,
class... Args>
void formatFormatter( void formatFormatter(
const BaseFormatter<Derived, containerMode, Args...>& formatter, const BaseFormatter<Derived, containerMode, Args...>& formatter,
FormatArg& arg, FormatArg& arg,
FormatCallback& cb); FormatCallback& cb);
} // namespace format_value } // namespace format_value
/* /*
* Specialize folly::FormatValue for your type. * Specialize folly::FormatValue for your type.
...@@ -411,8 +423,9 @@ inline std::string sformatChecked(StringPiece fmt, Args&&... args) { ...@@ -411,8 +423,9 @@ inline std::string sformatChecked(StringPiece fmt, Args&&... args) {
return formatChecked(fmt, std::forward<Args>(args)...).str(); return formatChecked(fmt, std::forward<Args>(args)...).str();
} }
template <class Container> template <class Container>
Formatter<true, Container> vformatChecked(StringPiece fmt, Formatter<true, Container> vformatChecked(
Container&& container) { StringPiece fmt,
Container&& container) {
return vformat(fmt, std::forward<Container>(container)); return vformat(fmt, std::forward<Container>(container));
} }
template <class Container> template <class Container>
...@@ -430,7 +443,7 @@ vformatChecked(Str* out, StringPiece fmt, Container&& container) { ...@@ -430,7 +443,7 @@ vformatChecked(Str* out, StringPiece fmt, Container&& container) {
vformatChecked(fmt, std::forward<Container>(container)).appendTo(*out); vformatChecked(fmt, std::forward<Container>(container)).appendTo(*out);
} }
} // namespace folly } // namespace folly
#include <folly/Format-inl.h> #include <folly/Format-inl.h>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment