|
@@ -54,15 +54,15 @@ namespace NYT {
|
|
|
*
|
|
|
*/
|
|
|
|
|
|
-template <size_t Length, class... TArgs>
|
|
|
-void Format(TStringBuilderBase* builder, const char (&format)[Length], TArgs&&... args);
|
|
|
template <class... TArgs>
|
|
|
-void Format(TStringBuilderBase* builder, TStringBuf format, TArgs&&... args);
|
|
|
+void Format(TStringBuilderBase* builder, TStaticFormat<TArgs...> fmt, TArgs&&... args);
|
|
|
+template <class... TArgs>
|
|
|
+void Format(TStringBuilderBase* builder, TRuntimeFormat fmt, TArgs&&... args);
|
|
|
|
|
|
-template <size_t Length, class... TArgs>
|
|
|
-TString Format(const char (&format)[Length], TArgs&&... args);
|
|
|
template <class... TArgs>
|
|
|
-TString Format(TStringBuf format, TArgs&&... args);
|
|
|
+TString Format(TStaticFormat<TArgs...> fmt, TArgs&&... args);
|
|
|
+template <class... TArgs>
|
|
|
+TString Format(TRuntimeFormat fmt, TArgs&&... args);
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
@@ -101,6 +101,19 @@ 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);
|
|
@@ -114,7 +127,7 @@ template <class... TArgs>
|
|
|
void FormatValue(
|
|
|
TStringBuilderBase* builder,
|
|
|
const TLazyMultiValueFormatter<TArgs...>& value,
|
|
|
- TStringBuf /*format*/);
|
|
|
+ TStringBuf /*spec*/);
|
|
|
|
|
|
//! A wrapper for a bunch of values that formats them lazily on demand.
|
|
|
/*!
|
|
@@ -129,12 +142,19 @@ class TLazyMultiValueFormatter
|
|
|
: private TNonCopyable
|
|
|
{
|
|
|
public:
|
|
|
- TLazyMultiValueFormatter(TStringBuf format, TArgs&&... args);
|
|
|
-
|
|
|
+ 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 /*format*/);
|
|
|
+ TStringBuf /*spec*/);
|
|
|
|
|
|
private:
|
|
|
const TStringBuf Format_;
|
|
@@ -142,7 +162,37 @@ private:
|
|
|
};
|
|
|
|
|
|
template <class ... Args>
|
|
|
-auto MakeLazyMultiValueFormatter(TStringBuf format, Args&&... 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);
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|