123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- namespace NYT {
- ////////////////////////////////////////////////////////////////////////////////
- template <class... TArgs>
- void Format(TStringBuilderBase* builder, TStaticFormat<TArgs...> fmt, TArgs&&... args);
- template <class... TArgs>
- void Format(TStringBuilderBase* builder, TRuntimeFormat fmt, TArgs&&... args);
- template <class... TArgs>
- TString Format(TStaticFormat<TArgs...> fmt, TArgs&&... args);
- template <class... TArgs>
- TString Format(TRuntimeFormat fmt, TArgs&&... args);
- ////////////////////////////////////////////////////////////////////////////////
- template <class TRange, class TFormatter>
- struct TFormattableView
- {
- using TBegin = std::decay_t<decltype(std::declval<const TRange>().begin())>;
- using TEnd = std::decay_t<decltype(std::declval<const TRange>().end())>;
- TBegin RangeBegin;
- TEnd RangeEnd;
- TFormatter Formatter;
- size_t Limit = std::numeric_limits<size_t>::max();
- TBegin begin() const;
- TEnd end() const;
- };
- //! Annotates a given
- template <class TRange, class TFormatter>
- TFormattableView<TRange, TFormatter> MakeFormattableView(
- const TRange& range,
- TFormatter&& formatter);
- template <class TRange, class TFormatter>
- TFormattableView<TRange, TFormatter> MakeShrunkFormattableView(
- const TRange& range,
- TFormatter&& formatter,
- size_t limit);
- ////////////////////////////////////////////////////////////////////////////////
- template <class TFormatter>
- struct TFormatterWrapper
- {
- TFormatter Formatter;
- };
- // Allows insertion of text conditionally.
- // Usage:
- /*
- NYT::Format(
- "Value is %v%v",
- 42,
- MakeFormatterWrapper([&] (auto* builder) {
- If (PossiblyMissingInfo_) {
- builder->AppendString(", PossiblyMissingInfo: ");
- FormatValue(builder, PossiblyMissingInfo_, "v");
- }
- }));
- */
- template <class TFormatter>
- TFormatterWrapper<TFormatter> MakeFormatterWrapper(
- TFormatter&& formatter);
- ////////////////////////////////////////////////////////////////////////////////
- template <class... TArgs>
- class TLazyMultiValueFormatter;
- template <class... TArgs>
- void FormatValue(
- TStringBuilderBase* builder,
- const TLazyMultiValueFormatter<TArgs...>& value,
- TStringBuf /*spec*/);
- //! A wrapper for a bunch of values that formats them lazily on demand.
- template <class... TArgs>
- class TLazyMultiValueFormatter
- : private TNonCopyable
- {
- public:
- TLazyMultiValueFormatter(TStringBuf fmt, TArgs&&... args);
- // NB(arkady-e1ppa): We actually have to
- // forward declare this method as above
- // and friend-declare it as specialization
- // here because clang is stupid and would
- // treat this friend declartion as a hidden friend
- // declaration which in turn is treated as a separate symbol
- // causing linker to not find the actual definition.
- friend void FormatValue<>(
- TStringBuilderBase* builder,
- const TLazyMultiValueFormatter& value,
- TStringBuf /*spec*/);
- private:
- const TStringBuf Format_;
- const std::tuple<TArgs...> Args_;
- };
- template <class ... Args>
- auto MakeLazyMultiValueFormatter(TStringBuf fmt, Args&&... args);
- ////////////////////////////////////////////////////////////////////////////////
- /*
- Example:
- FormatVector("One: %v, Two: %v, Three: %v", {1, 2, 3})
- => "One: 1, Two: 2, Three: 3"
- */
- template <size_t Length, class TVector>
- void FormatVector(
- TStringBuilderBase* builder,
- const char (&fmt)[Length],
- const TVector& vec);
- template <class TVector>
- void FormatVector(
- TStringBuilderBase* builder,
- TStringBuf fmt,
- const TVector& vec);
- template <size_t Length, class TVector>
- TString FormatVector(
- const char (&fmt)[Length],
- const TVector& vec);
- template <class TVector>
- TString FormatVector(
- TStringBuf fmt,
- const TVector& vec);
- ////////////////////////////////////////////////////////////////////////////////
- } // namespace NYT
|