diff options
author | babenko <babenko@yandex-team.ru> | 2022-02-10 16:49:19 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:19 +0300 |
commit | cec37806d8847aa3db53bafc9e251d4aaf325c12 (patch) | |
tree | 4a61c191e93e31d9ab423e258c71ab43550ee3d2 /library/cpp/yt/string/format.h | |
parent | 58cd0b86ed99a72df22479e26a20bc1c1e57e65e (diff) | |
download | ydb-cec37806d8847aa3db53bafc9e251d4aaf325c12.tar.gz |
Restoring authorship annotation for <babenko@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/yt/string/format.h')
-rw-r--r-- | library/cpp/yt/string/format.h | 160 |
1 files changed, 80 insertions, 80 deletions
diff --git a/library/cpp/yt/string/format.h b/library/cpp/yt/string/format.h index 9708fe5906..956682b3d7 100644 --- a/library/cpp/yt/string/format.h +++ b/library/cpp/yt/string/format.h @@ -1,92 +1,92 @@ -#pragma once - -#include "string_builder.h" - -namespace NYT { - -//////////////////////////////////////////////////////////////////////////////// - -/* - * Format: a type-safe and fast formatting utility. - * - * Basically works as a type-safe analogue of |sprintf| and is expected to - * be backwards-compatible with the latter. +#pragma once + +#include "string_builder.h" + +namespace NYT { + +//////////////////////////////////////////////////////////////////////////////// + +/* + * Format: a type-safe and fast formatting utility. + * + * Basically works as a type-safe analogue of |sprintf| and is expected to + * be backwards-compatible with the latter. * - * Like Go's |Sprintf|, supports the ultimate format specifier |v| - * causing arguments to be emitted in default format. - * This is the default and preferred way of formatting things, - * which should be used in newer code. + * Like Go's |Sprintf|, supports the ultimate format specifier |v| + * causing arguments to be emitted in default format. + * This is the default and preferred way of formatting things, + * which should be used in newer code. * - * |Format| may currently invoke |sprintf| internally for emitting numeric and some other - * types. You can always write your own optimized implementation, if you wish :) + * |Format| may currently invoke |sprintf| internally for emitting numeric and some other + * types. You can always write your own optimized implementation, if you wish :) * - * In additional to the usual |sprintf|, supports a number of non-standard flags: + * In additional to the usual |sprintf|, supports a number of non-standard flags: * - * |q| Causes the argument to be surrounded with single quotes (|'|). - * Applies to all types. + * |q| Causes the argument to be surrounded with single quotes (|'|). + * Applies to all types. * - * |Q| Causes the argument to be surrounded with double quotes (|"|). - * Applies to all types. + * |Q| Causes the argument to be surrounded with double quotes (|"|). + * Applies to all types. * - * |l| The argument is emitted in "lowercase" style. - * Only applies to enums and bools. + * |l| The argument is emitted in "lowercase" style. + * Only applies to enums and bools. * - * The following argument types are supported: + * The following argument types are supported: * * Strings (including |const char*|, |TStringBuf|, and |TString|) and chars: - * Emitted as is. Fast. + * Emitted as is. Fast. * - * Numerics and pointers: - * Emitted using |sprintf|. Maybe not that fast. + * Numerics and pointers: + * Emitted using |sprintf|. Maybe not that fast. * - * |bool|: - * Emitted either as |True| and |False| or |true| and |false| (if lowercase mode is ON). + * |bool|: + * Emitted either as |True| and |False| or |true| and |false| (if lowercase mode is ON). * - * Enums: - * Emitted in either camel (|SomeName|) or in lowercase-with-underscores style - * (|some_name|, if lowercase mode is ON). + * Enums: + * Emitted in either camel (|SomeName|) or in lowercase-with-underscores style + * (|some_name|, if lowercase mode is ON). * - * Nullables: - * |std::nullopt| is emitted as |<null>|. + * Nullables: + * |std::nullopt| is emitted as |<null>|. * - * All others: - * Emitted as strings by calling |ToString|. - * - */ - -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); - -template <size_t Length, class... TArgs> -TString Format(const char (&format)[Length], TArgs&&... args); -template <class... TArgs> -TString Format(TStringBuf format, TArgs&&... args); - -//////////////////////////////////////////////////////////////////////////////// - -template <class TRange, class TFormatter> + * All others: + * Emitted as strings by calling |ToString|. + * + */ + +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); + +template <size_t Length, class... TArgs> +TString Format(const char (&format)[Length], TArgs&&... args); +template <class... TArgs> +TString Format(TStringBuf format, 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; + TFormatter Formatter; size_t Limit = std::numeric_limits<size_t>::max(); TBegin begin() const; TEnd end() const; -}; - -//! Annotates a given #range with #formatter to be applied to each item. -template <class TRange, class TFormatter> +}; + +//! Annotates a given #range with #formatter to be applied to each item. +template <class TRange, class TFormatter> TFormattableView<TRange, TFormatter> MakeFormattableView( - const TRange& range, + const TRange& range, TFormatter&& formatter); - + template <class TRange, class TFormatter> TFormattableView<TRange, TFormatter> MakeShrunkFormattableView( const TRange& range, @@ -95,20 +95,20 @@ TFormattableView<TRange, TFormatter> MakeShrunkFormattableView( //////////////////////////////////////////////////////////////////////////////// -template <class TFormatter> -struct TFormatterWrapper -{ - TFormatter Formatter; -}; - -template <class TFormatter> -TFormatterWrapper<TFormatter> MakeFormatterWrapper( - TFormatter&& formatter); - -//////////////////////////////////////////////////////////////////////////////// - -} // namespace NYT - -#define FORMAT_INL_H_ -#include "format-inl.h" -#undef FORMAT_INL_H_ +template <class TFormatter> +struct TFormatterWrapper +{ + TFormatter Formatter; +}; + +template <class TFormatter> +TFormatterWrapper<TFormatter> MakeFormatterWrapper( + TFormatter&& formatter); + +//////////////////////////////////////////////////////////////////////////////// + +} // namespace NYT + +#define FORMAT_INL_H_ +#include "format-inl.h" +#undef FORMAT_INL_H_ |