aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorhippskill <hippskill@yandex-team.ru>2022-02-10 16:50:12 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:50:12 +0300
commitbd077d09a08e659195376ee97dc24728bb554246 (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /util
parent6362c4a2681cc317ffd22633d773f02de0d13697 (diff)
downloadydb-bd077d09a08e659195376ee97dc24728bb554246.tar.gz
Restoring authorship annotation for <hippskill@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util')
-rw-r--r--util/datetime/base.cpp82
-rw-r--r--util/datetime/base.h18
-rw-r--r--util/datetime/base_ut.cpp194
-rw-r--r--util/generic/array_ref.h2
-rw-r--r--util/generic/iterator.h52
-rw-r--r--util/generic/iterator_ut.cpp84
6 files changed, 216 insertions, 216 deletions
diff --git a/util/datetime/base.cpp b/util/datetime/base.cpp
index 6061b445d7a..38ecc3ab962 100644
--- a/util/datetime/base.cpp
+++ b/util/datetime/base.cpp
@@ -250,55 +250,55 @@ void sprint_gm_date(char* buf, time_t when, long* sec) {
struct tm theTm;
::Zero(theTm);
GmTimeR(&when, &theTm);
- DateToString(buf, theTm);
+ DateToString(buf, theTm);
if (sec) {
*sec = seconds(theTm);
}
}
-void DateToString(char* buf, const struct tm& theTm) {
- Y_ENSURE(0 <= theTm.tm_year + 1900 && theTm.tm_year + 1900 <= 9999, "invalid year " + ToString(theTm.tm_year + 1900) + ", year should be in range [0, 9999]");
-
- sprintf(buf, "%04d%02d%02d", theTm.tm_year + 1900, theTm.tm_mon + 1, theTm.tm_mday);
-}
-
-void DateToString(char* buf, time_t when, long* sec) {
- struct tm theTm;
- localtime_r(&when, &theTm);
-
- DateToString(buf, theTm);
-
- if (sec) {
- *sec = seconds(theTm);
- }
-}
-
-TString DateToString(const struct tm& theTm) {
- char buf[DATE_BUF_LEN];
- DateToString(buf, theTm);
- return buf;
-}
-
-TString DateToString(time_t when, long* sec) {
- char buf[DATE_BUF_LEN];
- DateToString(buf, when, sec);
- return buf;
-}
-
-TString YearToString(const struct tm& theTm) {
- Y_ENSURE(0 <= theTm.tm_year + 1900 && theTm.tm_year + 1900 <= 9999, "invalid year " + ToString(theTm.tm_year + 1900) + ", year should be in range [0, 9999]");
+void DateToString(char* buf, const struct tm& theTm) {
+ Y_ENSURE(0 <= theTm.tm_year + 1900 && theTm.tm_year + 1900 <= 9999, "invalid year " + ToString(theTm.tm_year + 1900) + ", year should be in range [0, 9999]");
+
+ sprintf(buf, "%04d%02d%02d", theTm.tm_year + 1900, theTm.tm_mon + 1, theTm.tm_mday);
+}
+
+void DateToString(char* buf, time_t when, long* sec) {
+ struct tm theTm;
+ localtime_r(&when, &theTm);
+
+ DateToString(buf, theTm);
+
+ if (sec) {
+ *sec = seconds(theTm);
+ }
+}
+
+TString DateToString(const struct tm& theTm) {
+ char buf[DATE_BUF_LEN];
+ DateToString(buf, theTm);
+ return buf;
+}
+
+TString DateToString(time_t when, long* sec) {
+ char buf[DATE_BUF_LEN];
+ DateToString(buf, when, sec);
+ return buf;
+}
+
+TString YearToString(const struct tm& theTm) {
+ Y_ENSURE(0 <= theTm.tm_year + 1900 && theTm.tm_year + 1900 <= 9999, "invalid year " + ToString(theTm.tm_year + 1900) + ", year should be in range [0, 9999]");
char buf[16];
sprintf(buf, "%04d", theTm.tm_year + 1900);
return buf;
-}
-
-TString YearToString(time_t when) {
- struct tm theTm;
- localtime_r(&when, &theTm);
-
- return YearToString(theTm);
-}
-
+}
+
+TString YearToString(time_t when) {
+ struct tm theTm;
+ localtime_r(&when, &theTm);
+
+ return YearToString(theTm);
+}
+
bool sscan_date(const char* date, struct tm& theTm) {
int year, mon, mday;
if (sscanf(date, "%4d%2d%2d", &year, &mon, &mday) != 3) {
diff --git a/util/datetime/base.h b/util/datetime/base.h
index d1cf52c926b..5e902b8f633 100644
--- a/util/datetime/base.h
+++ b/util/datetime/base.h
@@ -84,15 +84,15 @@ constexpr long TVdiff(timeval r1, timeval r2) {
TString Strftime(const char* format, const struct tm* tm);
-// Use functions below instead of sprint_date (check IGNIETFERRO-892 for details)
-void DateToString(char* buf, const struct tm& theTm);
-void DateToString(char* buf, time_t when, long* sec = nullptr);
-TString DateToString(const struct tm& theTm);
-TString DateToString(time_t when, long* sec = nullptr);
-// Year in format "YYYY", throws an exception if year not in range [0, 9999]
-TString YearToString(const struct tm& theTm);
-TString YearToString(time_t when);
-
+// Use functions below instead of sprint_date (check IGNIETFERRO-892 for details)
+void DateToString(char* buf, const struct tm& theTm);
+void DateToString(char* buf, time_t when, long* sec = nullptr);
+TString DateToString(const struct tm& theTm);
+TString DateToString(time_t when, long* sec = nullptr);
+// Year in format "YYYY", throws an exception if year not in range [0, 9999]
+TString YearToString(const struct tm& theTm);
+TString YearToString(time_t when);
+
template <class S>
class TTimeBase {
public:
diff --git a/util/datetime/base_ut.cpp b/util/datetime/base_ut.cpp
index 783a2636dcb..afc3f802eb2 100644
--- a/util/datetime/base_ut.cpp
+++ b/util/datetime/base_ut.cpp
@@ -46,108 +46,108 @@ namespace {
}
}
}
-
+
Y_UNIT_TEST_SUITE(TestSprintDate) {
Y_UNIT_TEST(Year9999) {
- struct tm t;
- t.tm_year = 9999 - 1900;
- t.tm_mday = 1;
- t.tm_mon = 10;
-
- char buf[DATE_BUF_LEN];
- DateToString(buf, t);
-
- TString expectedDate = "99991101";
-
- UNIT_ASSERT_VALUES_EQUAL(expectedDate, ToString(buf));
- }
+ struct tm t;
+ t.tm_year = 9999 - 1900;
+ t.tm_mday = 1;
+ t.tm_mon = 10;
+
+ char buf[DATE_BUF_LEN];
+ DateToString(buf, t);
+
+ TString expectedDate = "99991101";
+
+ UNIT_ASSERT_VALUES_EQUAL(expectedDate, ToString(buf));
+ }
Y_UNIT_TEST(YearAfter9999) {
- struct tm t;
- t.tm_year = 123456 - 1900;
- t.tm_mday = 1;
- t.tm_mon = 10;
-
- char buf[DATE_BUF_LEN];
- UNIT_ASSERT_EXCEPTION(DateToString(buf, t), yexception);
- }
+ struct tm t;
+ t.tm_year = 123456 - 1900;
+ t.tm_mday = 1;
+ t.tm_mon = 10;
+
+ char buf[DATE_BUF_LEN];
+ UNIT_ASSERT_EXCEPTION(DateToString(buf, t), yexception);
+ }
Y_UNIT_TEST(SmallYear) {
- struct tm t;
- t.tm_year = 0 - 1900;
- t.tm_mday = 1;
- t.tm_mon = 10;
-
- char buf[DATE_BUF_LEN];
- DateToString(buf, t);
-
- const TString expectedDate = TString("00001101");
-
- UNIT_ASSERT_VALUES_EQUAL(expectedDate, ToString(buf));
- }
+ struct tm t;
+ t.tm_year = 0 - 1900;
+ t.tm_mday = 1;
+ t.tm_mon = 10;
+
+ char buf[DATE_BUF_LEN];
+ DateToString(buf, t);
+
+ const TString expectedDate = TString("00001101");
+
+ UNIT_ASSERT_VALUES_EQUAL(expectedDate, ToString(buf));
+ }
Y_UNIT_TEST(SmallYearAndMonth) {
- struct tm t;
- t.tm_year = 99 - 1900;
- t.tm_mday = 1;
- t.tm_mon = 0;
-
- char buf[DATE_BUF_LEN];
- DateToString(buf, t);
-
- const TString expectedDate = TString("00990101");
-
- UNIT_ASSERT_VALUES_EQUAL(expectedDate, ToString(buf));
- }
- Y_UNIT_TEST(FromZeroTimestamp) {
- const time_t timestamp = 0;
-
- char buf[DATE_BUF_LEN];
- DateToString(buf, timestamp);
-
- const TString expectedDate = TString("19700101");
-
- UNIT_ASSERT_VALUES_EQUAL(expectedDate, ToString(buf));
- }
- Y_UNIT_TEST(FromTimestamp) {
- const time_t timestamp = 1524817858;
-
- char buf[DATE_BUF_LEN];
- DateToString(buf, timestamp);
-
- const TString expectedDate = TString("20180427");
-
- UNIT_ASSERT_VALUES_EQUAL(expectedDate, ToString(buf));
- }
- Y_UNIT_TEST(FromTimestampAsTString) {
- const time_t timestamp = 1524817858;
-
- const TString expectedDate = TString("20180427");
-
- UNIT_ASSERT_VALUES_EQUAL(expectedDate, DateToString(timestamp));
- }
- Y_UNIT_TEST(YearToString) {
- struct tm t;
- t.tm_year = 99 - 1900;
- t.tm_mday = 1;
- t.tm_mon = 0;
-
- TString expectedYear = TString("0099");
-
- UNIT_ASSERT_VALUES_EQUAL(expectedYear, YearToString(t));
- }
- Y_UNIT_TEST(YearToStringBigYear) {
- struct tm t;
- t.tm_year = 123456 - 1900;
- t.tm_mday = 1;
- t.tm_mon = 0;
-
- UNIT_ASSERT_EXCEPTION(YearToString(t), yexception);
- }
- Y_UNIT_TEST(YearToStringAsTimestamp) {
- const time_t timestamp = 1524817858;
-
- const TString expectedYear = TString("2018");
-
- UNIT_ASSERT_VALUES_EQUAL(expectedYear, YearToString(timestamp));
- }
+ struct tm t;
+ t.tm_year = 99 - 1900;
+ t.tm_mday = 1;
+ t.tm_mon = 0;
+
+ char buf[DATE_BUF_LEN];
+ DateToString(buf, t);
+
+ const TString expectedDate = TString("00990101");
+
+ UNIT_ASSERT_VALUES_EQUAL(expectedDate, ToString(buf));
+ }
+ Y_UNIT_TEST(FromZeroTimestamp) {
+ const time_t timestamp = 0;
+
+ char buf[DATE_BUF_LEN];
+ DateToString(buf, timestamp);
+
+ const TString expectedDate = TString("19700101");
+
+ UNIT_ASSERT_VALUES_EQUAL(expectedDate, ToString(buf));
+ }
+ Y_UNIT_TEST(FromTimestamp) {
+ const time_t timestamp = 1524817858;
+
+ char buf[DATE_BUF_LEN];
+ DateToString(buf, timestamp);
+
+ const TString expectedDate = TString("20180427");
+
+ UNIT_ASSERT_VALUES_EQUAL(expectedDate, ToString(buf));
+ }
+ Y_UNIT_TEST(FromTimestampAsTString) {
+ const time_t timestamp = 1524817858;
+
+ const TString expectedDate = TString("20180427");
+
+ UNIT_ASSERT_VALUES_EQUAL(expectedDate, DateToString(timestamp));
+ }
+ Y_UNIT_TEST(YearToString) {
+ struct tm t;
+ t.tm_year = 99 - 1900;
+ t.tm_mday = 1;
+ t.tm_mon = 0;
+
+ TString expectedYear = TString("0099");
+
+ UNIT_ASSERT_VALUES_EQUAL(expectedYear, YearToString(t));
+ }
+ Y_UNIT_TEST(YearToStringBigYear) {
+ struct tm t;
+ t.tm_year = 123456 - 1900;
+ t.tm_mday = 1;
+ t.tm_mon = 0;
+
+ UNIT_ASSERT_EXCEPTION(YearToString(t), yexception);
+ }
+ Y_UNIT_TEST(YearToStringAsTimestamp) {
+ const time_t timestamp = 1524817858;
+
+ const TString expectedYear = TString("2018");
+
+ UNIT_ASSERT_VALUES_EQUAL(expectedYear, YearToString(timestamp));
+ }
}
Y_UNIT_TEST_SUITE(TDateTimeTest) {
diff --git a/util/generic/array_ref.h b/util/generic/array_ref.h
index a224443bfd2..1ac60ac7d3c 100644
--- a/util/generic/array_ref.h
+++ b/util/generic/array_ref.h
@@ -73,7 +73,7 @@ public:
{
}
- template <class TT, typename = std::enable_if_t<std::is_same<std::remove_const_t<T>, std::remove_const_t<TT>>::value>>
+ template <class TT, typename = std::enable_if_t<std::is_same<std::remove_const_t<T>, std::remove_const_t<TT>>::value>>
bool operator==(const TArrayRef<TT>& other) const noexcept {
return (S_ == other.size()) && std::equal(begin(), end(), other.begin());
}
diff --git a/util/generic/iterator.h b/util/generic/iterator.h
index aa141c2d5f8..19e9d20976d 100644
--- a/util/generic/iterator.h
+++ b/util/generic/iterator.h
@@ -5,30 +5,30 @@
namespace NStlIterator {
template <class T>
- class TProxy {
- public:
- TProxy() = default;
+ class TProxy {
+ public:
+ TProxy() = default;
TProxy(T&& value)
: Value_(std::move(value))
{
- }
+ }
- const T* operator->() const noexcept {
- return &Value_;
- }
+ const T* operator->() const noexcept {
+ return &Value_;
+ }
- const T& operator*() const noexcept {
- return Value_;
- }
+ const T& operator*() const noexcept {
+ return Value_;
+ }
- bool operator==(const TProxy& rhs) const {
- return Value_ == rhs.Value_;
+ bool operator==(const TProxy& rhs) const {
+ return Value_ == rhs.Value_;
}
- private:
- T Value_;
+ private:
+ T Value_;
};
-} // namespace NStlIterator
+} // namespace NStlIterator
/**
* Range adaptor that turns a derived class with a Java-style iteration
@@ -71,9 +71,9 @@ public: // TODO: private
static constexpr bool IsNoexceptNext = noexcept(std::declval<TSlave>().Next());
using difference_type = std::ptrdiff_t;
- using pointer = decltype(std::declval<TSlave>().Next());
- using reference = decltype(*std::declval<TSlave>().Next());
- using value_type = std::remove_cv_t<std::remove_reference_t<reference>>;
+ using pointer = decltype(std::declval<TSlave>().Next());
+ using reference = decltype(*std::declval<TSlave>().Next());
+ using value_type = std::remove_cv_t<std::remove_reference_t<reference>>;
using iterator_category = std::input_iterator_tag;
inline TIterator() noexcept
@@ -97,11 +97,11 @@ public: // TODO: private
}
inline pointer operator->() const noexcept {
- return Cur_;
+ return Cur_;
}
inline reference operator*() const noexcept {
- return *Cur_;
+ return *Cur_;
}
inline TIterator& operator++() noexcept(IsNoexceptNext) {
@@ -112,18 +112,18 @@ public: // TODO: private
private:
TSlave* Slave_;
- pointer Cur_;
+ pointer Cur_;
};
public:
- using const_iterator = TIterator;
- using iterator = const_iterator;
-
- inline iterator begin() const noexcept(TIterator::IsNoexceptNext) {
+ using const_iterator = TIterator;
+ using iterator = const_iterator;
+
+ inline iterator begin() const noexcept(TIterator::IsNoexceptNext) {
return TIterator(const_cast<TSlave*>(static_cast<const TSlave*>(this)));
}
- inline iterator end() const noexcept {
+ inline iterator end() const noexcept {
return TIterator();
}
};
diff --git a/util/generic/iterator_ut.cpp b/util/generic/iterator_ut.cpp
index 5dc085c8214..00be19e10ec 100644
--- a/util/generic/iterator_ut.cpp
+++ b/util/generic/iterator_ut.cpp
@@ -9,55 +9,55 @@ Y_UNIT_TEST_SUITE(TIterator) {
UNIT_ASSERT_VALUES_EQUAL(*ToForwardIterator(std::prev(x.rend())), *x.begin());
}
}
-
-Y_UNIT_TEST_SUITE(TInputRangeAdaptor) {
+
+Y_UNIT_TEST_SUITE(TInputRangeAdaptor) {
class TSquaresGenerator: public TInputRangeAdaptor<TSquaresGenerator> {
- public:
- const i64* Next() {
- Current_ = State_ * State_;
- ++State_;
- // Never return nullptr => we have infinite range!
- return &Current_;
- }
-
- private:
- i64 State_ = 0.0;
- i64 Current_ = 0.0;
- };
-
- Y_UNIT_TEST(TSquaresGenerator) {
- i64 cur = 0;
- for (i64 sqr : TSquaresGenerator{}) {
- UNIT_ASSERT_VALUES_EQUAL(cur * cur, sqr);
-
- if (++cur > 10) {
- break;
- }
- }
- }
-
+ public:
+ const i64* Next() {
+ Current_ = State_ * State_;
+ ++State_;
+ // Never return nullptr => we have infinite range!
+ return &Current_;
+ }
+
+ private:
+ i64 State_ = 0.0;
+ i64 Current_ = 0.0;
+ };
+
+ Y_UNIT_TEST(TSquaresGenerator) {
+ i64 cur = 0;
+ for (i64 sqr : TSquaresGenerator{}) {
+ UNIT_ASSERT_VALUES_EQUAL(cur * cur, sqr);
+
+ if (++cur > 10) {
+ break;
+ }
+ }
+ }
+
class TUrlPart: public TInputRangeAdaptor<TUrlPart> {
- public:
+ public:
TUrlPart(const TStringBuf& url)
: Url_(url)
{
- }
-
- NStlIterator::TProxy<TStringBuf> Next() {
- return Url_.NextTok('/');
- }
-
- private:
- TStringBuf Url_;
- };
-
- Y_UNIT_TEST(TUrlPart) {
+ }
+
+ NStlIterator::TProxy<TStringBuf> Next() {
+ return Url_.NextTok('/');
+ }
+
+ private:
+ TStringBuf Url_;
+ };
+
+ Y_UNIT_TEST(TUrlPart) {
const TVector<TStringBuf> expected = {TStringBuf("yandex.ru"), TStringBuf("search?")};
- auto expected_part = expected.begin();
+ auto expected_part = expected.begin();
for (const TStringBuf& part : TUrlPart(TStringBuf("yandex.ru/search?"))) {
UNIT_ASSERT_VALUES_EQUAL(part, *expected_part);
++expected_part;
- }
+ }
UNIT_ASSERT(expected_part == expected.end());
- }
-}
+ }
+}