aboutsummaryrefslogtreecommitdiffstats
path: root/util/stream
diff options
context:
space:
mode:
authornga <nga@yandex-team.ru>2022-02-10 16:48:09 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:48:09 +0300
commitc2a1af049e9deca890e9923abe64fe6c59060348 (patch)
treeb222e5ac2e2e98872661c51ccceee5da0d291e13 /util/stream
parent1f553f46fb4f3c5eec631352cdd900a0709016af (diff)
downloadydb-c2a1af049e9deca890e9923abe64fe6c59060348.tar.gz
Restoring authorship annotation for <nga@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/stream')
-rw-r--r--util/stream/format.h126
-rw-r--r--util/stream/format_ut.cpp36
-rw-r--r--util/stream/output.cpp2
-rw-r--r--util/stream/output.h2
4 files changed, 83 insertions, 83 deletions
diff --git a/util/stream/format.h b/util/stream/format.h
index 30e321d377..b033208a1b 100644
--- a/util/stream/format.h
+++ b/util/stream/format.h
@@ -1,5 +1,5 @@
#pragma once
-
+
#include "mem.h"
#include "output.h"
@@ -8,7 +8,7 @@
#include <util/generic/flags.h>
#include <util/memory/tempbuf.h>
#include <util/string/cast.h>
-
+
enum ENumberFormatFlag {
HF_FULL = 0x01, /**< Output number with leading zeros. */
HF_ADDX = 0x02, /**< Output '0x' or '0b' before hex/bin digits. */
@@ -21,7 +21,7 @@ enum ESizeFormat {
SF_BYTES, /**< Base 1024, byte suffix. 1100 gets turned into "1.07KiB". */
};
-namespace NFormatPrivate {
+namespace NFormatPrivate {
template <size_t Value>
struct TLog2: std::integral_constant<size_t, TLog2<Value / 2>::value + 1> {};
@@ -29,66 +29,66 @@ namespace NFormatPrivate {
struct TLog2<1>: std::integral_constant<size_t, 0> {};
static inline void WriteChars(IOutputStream& os, char c, size_t count) {
- if (count == 0)
- return;
- TTempBuf buf(count);
- memset(buf.Data(), c, count);
- os.Write(buf.Data(), count);
- }
-
- template <typename T>
- struct TLeftPad {
+ if (count == 0)
+ return;
+ TTempBuf buf(count);
+ memset(buf.Data(), c, count);
+ os.Write(buf.Data(), count);
+ }
+
+ template <typename T>
+ struct TLeftPad {
T Value;
- size_t Width;
- char Padc;
-
+ size_t Width;
+ char Padc;
+
inline TLeftPad(const T& value, size_t width, char padc)
- : Value(value)
- , Width(width)
- , Padc(padc)
- {
- }
- };
-
- template <typename T>
+ : Value(value)
+ , Width(width)
+ , Padc(padc)
+ {
+ }
+ };
+
+ template <typename T>
IOutputStream& operator<<(IOutputStream& o, const TLeftPad<T>& lp) {
- TTempBuf buf;
- TMemoryOutput ss(buf.Data(), buf.Size());
+ TTempBuf buf;
+ TMemoryOutput ss(buf.Data(), buf.Size());
ss << lp.Value;
- size_t written = buf.Size() - ss.Avail();
- if (lp.Width > written) {
- WriteChars(o, lp.Padc, lp.Width - written);
- }
- o.Write(buf.Data(), written);
- return o;
- }
-
- template <typename T>
- struct TRightPad {
+ size_t written = buf.Size() - ss.Avail();
+ if (lp.Width > written) {
+ WriteChars(o, lp.Padc, lp.Width - written);
+ }
+ o.Write(buf.Data(), written);
+ return o;
+ }
+
+ template <typename T>
+ struct TRightPad {
T Value;
- size_t Width;
- char Padc;
-
+ size_t Width;
+ char Padc;
+
inline TRightPad(const T& value, size_t width, char padc)
- : Value(value)
- , Width(width)
- , Padc(padc)
- {
- }
- };
-
- template <typename T>
+ : Value(value)
+ , Width(width)
+ , Padc(padc)
+ {
+ }
+ };
+
+ template <typename T>
IOutputStream& operator<<(IOutputStream& o, const TRightPad<T>& lp) {
- TTempBuf buf;
- TMemoryOutput ss(buf.Data(), buf.Size());
+ TTempBuf buf;
+ TMemoryOutput ss(buf.Data(), buf.Size());
ss << lp.Value;
- size_t written = buf.Size() - ss.Avail();
- o.Write(buf.Data(), written);
- if (lp.Width > written) {
- WriteChars(o, lp.Padc, lp.Width - written);
- }
- return o;
- }
+ size_t written = buf.Size() - ss.Avail();
+ o.Write(buf.Data(), written);
+ if (lp.Width > written) {
+ WriteChars(o, lp.Padc, lp.Width - written);
+ }
+ return o;
+ }
template <typename T, size_t Base>
struct TBaseNumber {
@@ -184,8 +184,8 @@ namespace NFormatPrivate {
double Value;
ESizeFormat Format;
};
-}
-
+}
+
/**
* Output manipulator basically equivalent to `std::setw` and `std::setfill`
* combined.
@@ -203,11 +203,11 @@ namespace NFormatPrivate {
* @param padc Character to use for padding.
* @see RightPad
*/
-template <typename T>
+template <typename T>
static constexpr ::NFormatPrivate::TLeftPad<T> LeftPad(const T& value, const size_t width, const char padc = ' ') noexcept {
return ::NFormatPrivate::TLeftPad<T>(value, width, padc);
-}
-
+}
+
template <typename T, int N>
static constexpr ::NFormatPrivate::TLeftPad<const T*> LeftPad(const T (&value)[N], const size_t width, const char padc = ' ') noexcept {
return ::NFormatPrivate::TLeftPad<const T*>(value, width, padc);
@@ -229,11 +229,11 @@ static constexpr ::NFormatPrivate::TLeftPad<const T*> LeftPad(const T (&value)[N
* @param padc Character to use for padding.
* @see LeftPad
*/
-template <typename T>
+template <typename T>
static constexpr ::NFormatPrivate::TRightPad<T> RightPad(const T& value, const size_t width, const char padc = ' ') noexcept {
return ::NFormatPrivate::TRightPad<T>(value, width, padc);
-}
-
+}
+
template <typename T, int N>
static constexpr ::NFormatPrivate::TRightPad<const T*> RightPad(const T (&value)[N], const size_t width, const char padc = ' ') noexcept {
return ::NFormatPrivate::TRightPad<const T*>(value, width, padc);
diff --git a/util/stream/format_ut.cpp b/util/stream/format_ut.cpp
index 2e50f0f9c5..43245aeb48 100644
--- a/util/stream/format_ut.cpp
+++ b/util/stream/format_ut.cpp
@@ -2,28 +2,28 @@
#include <library/cpp/testing/unittest/registar.h>
#include <util/charset/wide.h>
-
+
Y_UNIT_TEST_SUITE(TOutputStreamFormattingTest) {
Y_UNIT_TEST(TestLeftPad) {
- TStringStream ss;
- ss << LeftPad(10, 4, '0');
- UNIT_ASSERT_VALUES_EQUAL("0010", ss.Str());
-
+ TStringStream ss;
+ ss << LeftPad(10, 4, '0');
+ UNIT_ASSERT_VALUES_EQUAL("0010", ss.Str());
+
ss.Clear();
- ss << LeftPad(222, 1);
- UNIT_ASSERT_VALUES_EQUAL("222", ss.Str());
- }
-
+ ss << LeftPad(222, 1);
+ UNIT_ASSERT_VALUES_EQUAL("222", ss.Str());
+ }
+
Y_UNIT_TEST(TestRightPad) {
- TStringStream ss;
- ss << RightPad("aa", 4);
- UNIT_ASSERT_VALUES_EQUAL("aa ", ss.Str());
-
+ TStringStream ss;
+ ss << RightPad("aa", 4);
+ UNIT_ASSERT_VALUES_EQUAL("aa ", ss.Str());
+
ss.Clear();
- ss << RightPad("aa", 1);
- UNIT_ASSERT_VALUES_EQUAL("aa", ss.Str());
- }
-
+ ss << RightPad("aa", 1);
+ UNIT_ASSERT_VALUES_EQUAL("aa", ss.Str());
+ }
+
Y_UNIT_TEST(TestTime) {
TStringStream ss;
@@ -179,4 +179,4 @@ Y_UNIT_TEST_SUITE(TOutputStreamFormattingTest) {
UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadable(TDuration::Seconds(3672))), "1h 1m 12s");
UNIT_ASSERT_VALUES_EQUAL(ToString(HumanReadable(TDuration::Seconds(4220))), "1h 10m 20s");
}
-}
+}
diff --git a/util/stream/output.cpp b/util/stream/output.cpp
index c193889e7f..db81b81b70 100644
--- a/util/stream/output.cpp
+++ b/util/stream/output.cpp
@@ -99,7 +99,7 @@ void Out<std::string>(IOutputStream& o, const std::string& p) {
o.Write(p.data(), p.length());
}
-template <>
+template <>
void Out<std::string_view>(IOutputStream& o, const std::string_view& p) {
o.Write(p.data(), p.length());
}
diff --git a/util/stream/output.h b/util/stream/output.h
index 8d904b5ecf..00eef50b95 100644
--- a/util/stream/output.h
+++ b/util/stream/output.h
@@ -296,7 +296,7 @@ static inline void Flush(IOutputStream& o) {
/*
* Also see format.h for additional manipulators.
*/
-
+
#include "debug.h"
void RedirectStdioToAndroidLog(bool redirect);