diff options
author | aosipenko <aosipenko@yandex-team.ru> | 2022-02-10 16:48:08 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:48:08 +0300 |
commit | 948fd24d47d4b3b7815aaef1686aea00ef3f4288 (patch) | |
tree | 8ad4c39c2a5f8b341bc02e3b0c5e8f26c40373cb /util | |
parent | d2eb4aae699fa2f6901bf32d22eec019c8f29838 (diff) | |
download | ydb-948fd24d47d4b3b7815aaef1686aea00ef3f4288.tar.gz |
Restoring authorship annotation for <aosipenko@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util')
73 files changed, 557 insertions, 557 deletions
diff --git a/util/charset/wide.h b/util/charset/wide.h index 04e6928aab..cc0ac7ccd1 100644 --- a/util/charset/wide.h +++ b/util/charset/wide.h @@ -673,11 +673,11 @@ inline bool IsSpace(const wchar16* s, size_t n) { return true; } -//! returns @c true if string contains whitespace characters only +//! returns @c true if string contains whitespace characters only inline bool IsSpace(const TWtringBuf s) { return IsSpace(s.data(), s.length()); -} - +} + //! replaces multiple sequential whitespace characters with a single space character void Collapse(TUtf16String& w); diff --git a/util/charset/wide_ut.cpp b/util/charset/wide_ut.cpp index d8f3233e73..8d7360cbfa 100644 --- a/util/charset/wide_ut.cpp +++ b/util/charset/wide_ut.cpp @@ -9,7 +9,7 @@ namespace { //! three UTF8 encoded russian letters (A, B, V) - const char utext[] = "\xd0\x90\xd0\x91\xd0\x92"; + const char utext[] = "\xd0\x90\xd0\x91\xd0\x92"; const char asciiLatinAlphabet[] = "ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz"; const wchar16 wideLatinAlphabet[] = { @@ -20,15 +20,15 @@ namespace { 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F, 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F, 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F, 0x00}; - const char utf8CyrillicAlphabet[] = - "\xd0\x90\xd0\x91\xd0\x92\xd0\x93\xd0\x94\xd0\x95\xd0\x96\xd0\x97" - "\xd0\x98\xd0\x99\xd0\x9a\xd0\x9b\xd0\x9c\xd0\x9d\xd0\x9e\xd0\x9f" - "\xd0\xa0\xd0\xa1\xd0\xa2\xd0\xa3\xd0\xa4\xd0\xa5\xd0\xa6\xd0\xa7" - "\xd0\xa8\xd0\xa9\xd0\xaa\xd0\xab\xd0\xac\xd0\xad\xd0\xae\xd0\xaf" - "\xd0\xb0\xd0\xb1\xd0\xb2\xd0\xb3\xd0\xb4\xd0\xb5\xd0\xb6\xd0\xb7" - "\xd0\xb8\xd0\xb9\xd0\xba\xd0\xbb\xd0\xbc\xd0\xbd\xd0\xbe\xd0\xbf" - "\xd1\x80\xd1\x81\xd1\x82\xd1\x83\xd1\x84\xd1\x85\xd1\x86\xd1\x87" - "\xd1\x88\xd1\x89\xd1\x8a\xd1\x8b\xd1\x8c\xd1\x8d\xd1\x8e\xd1\x8f"; + const char utf8CyrillicAlphabet[] = + "\xd0\x90\xd0\x91\xd0\x92\xd0\x93\xd0\x94\xd0\x95\xd0\x96\xd0\x97" + "\xd0\x98\xd0\x99\xd0\x9a\xd0\x9b\xd0\x9c\xd0\x9d\xd0\x9e\xd0\x9f" + "\xd0\xa0\xd0\xa1\xd0\xa2\xd0\xa3\xd0\xa4\xd0\xa5\xd0\xa6\xd0\xa7" + "\xd0\xa8\xd0\xa9\xd0\xaa\xd0\xab\xd0\xac\xd0\xad\xd0\xae\xd0\xaf" + "\xd0\xb0\xd0\xb1\xd0\xb2\xd0\xb3\xd0\xb4\xd0\xb5\xd0\xb6\xd0\xb7" + "\xd0\xb8\xd0\xb9\xd0\xba\xd0\xbb\xd0\xbc\xd0\xbd\xd0\xbe\xd0\xbf" + "\xd1\x80\xd1\x81\xd1\x82\xd1\x83\xd1\x84\xd1\x85\xd1\x86\xd1\x87" + "\xd1\x88\xd1\x89\xd1\x8a\xd1\x8b\xd1\x8c\xd1\x8d\xd1\x8e\xd1\x8f"; const wchar32 LEAD_BITS_MASK_2_BYTES = 0x1F; const wchar32 LEAD_BITS_MASK_3_BYTES = 0x0F; @@ -81,31 +81,31 @@ namespace { } TString CreateUTF8Text() { - char text[] = { - '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07', '\x08', '\x09', '\x0a', '\x0b', '\x0c', '\x0d', '\x0e', '\x0f', - '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x1a', '\x1b', '\x1c', '\x1d', '\x1e', '\x1f', - '\x20', '\x21', '\x22', '\x23', '\x24', '\x25', '\x26', '\x27', '\x28', '\x29', '\x2a', '\x2b', '\x2c', '\x2d', '\x2e', '\x2f', - '\x30', '\x31', '\x32', '\x33', '\x34', '\x35', '\x36', '\x37', '\x38', '\x39', '\x3a', '\x3b', '\x3c', '\x3d', '\x3e', '\x3f', - '\x40', '\x41', '\x42', '\x43', '\x44', '\x45', '\x46', '\x47', '\x48', '\x49', '\x4a', '\x4b', '\x4c', '\x4d', '\x4e', '\x4f', - '\x50', '\x51', '\x52', '\x53', '\x54', '\x55', '\x56', '\x57', '\x58', '\x59', '\x5a', '\x5b', '\x5c', '\x5d', '\x5e', '\x5f', - '\x60', '\x61', '\x62', '\x63', '\x64', '\x65', '\x66', '\x67', '\x68', '\x69', '\x6a', '\x6b', '\x6c', '\x6d', '\x6e', '\x6f', - '\x70', '\x71', '\x72', '\x73', '\x74', '\x75', '\x76', '\x77', '\x78', '\x79', '\x7a', '\x7b', '\x7c', '\x7d', '\x7e', '\x7f', - '\xcc', '\x81', '\xc3', '\x84', '\xc3', '\x96', '\xc3', '\x9c', '\xc4', '\x84', '\xc4', '\x86', '\xc4', '\x98', '\xc5', '\x81', - '\xc3', '\xa0', '\xc3', '\xa2', '\xc3', '\xa7', '\xc3', '\xa8', '\xc3', '\xa9', '\xc3', '\xaa', '\xd2', '\x90', '\xc2', '\xad', - '\xc3', '\x9f', '\xc3', '\xa4', '\xc3', '\xb6', '\xc3', '\xbc', '\xc4', '\x85', '\xc4', '\x87', '\xc4', '\x99', '\xc5', '\x82', - '\xc3', '\xab', '\xc3', '\xae', '\xc3', '\xaf', '\xc3', '\xb4', '\xc3', '\xb9', '\xc3', '\xbb', '\xd2', '\x91', '\xe9', '\x8b', - '\x8f', '\xc2', '\xa0', '\xc5', '\x83', '\xc3', '\x93', '\xc5', '\x9a', '\xc5', '\xbb', '\xc5', '\xb9', '\xd1', '\xac', '\xc2', - '\xa7', '\xd0', '\x81', '\xd1', '\xa2', '\xd1', '\xb2', '\xd1', '\xb4', '\xd0', '\x8e', '\xd0', '\x86', '\xd0', '\x84', '\xd0', - '\x87', '\xc2', '\xb0', '\xc5', '\x84', '\xc3', '\xb3', '\xc5', '\x9b', '\xc5', '\xbc', '\xc5', '\xba', '\xd1', '\xad', '\xe2', - '\x84', '\x96', '\xd1', '\x91', '\xd1', '\xa3', '\xd1', '\xb3', '\xd1', '\xb5', '\xd1', '\x9e', '\xd1', '\x96', '\xd1', '\x94', - '\xd1', '\x97', '\xd0', '\x90', '\xd0', '\x91', '\xd0', '\x92', '\xd0', '\x93', '\xd0', '\x94', '\xd0', '\x95', '\xd0', '\x96', - '\xd0', '\x97', '\xd0', '\x98', '\xd0', '\x99', '\xd0', '\x9a', '\xd0', '\x9b', '\xd0', '\x9c', '\xd0', '\x9d', '\xd0', '\x9e', - '\xd0', '\x9f', '\xd0', '\xa0', '\xd0', '\xa1', '\xd0', '\xa2', '\xd0', '\xa3', '\xd0', '\xa4', '\xd0', '\xa5', '\xd0', '\xa6', - '\xd0', '\xa7', '\xd0', '\xa8', '\xd0', '\xa9', '\xd0', '\xaa', '\xd0', '\xab', '\xd0', '\xac', '\xd0', '\xad', '\xd0', '\xae', - '\xd0', '\xaf', '\xd0', '\xb0', '\xd0', '\xb1', '\xd0', '\xb2', '\xd0', '\xb3', '\xd0', '\xb4', '\xd0', '\xb5', '\xd0', '\xb6', - '\xd0', '\xb7', '\xd0', '\xb8', '\xd0', '\xb9', '\xd0', '\xba', '\xd0', '\xbb', '\xd0', '\xbc', '\xd0', '\xbd', '\xd0', '\xbe', - '\xd0', '\xbf', '\xd1', '\x80', '\xd1', '\x81', '\xd1', '\x82', '\xd1', '\x83', '\xd1', '\x84', '\xd1', '\x85', '\xd1', '\x86', - '\xd1', '\x87', '\xd1', '\x88', '\xd1', '\x89', '\xd1', '\x8a', '\xd1', '\x8b', '\xd1', '\x8c', '\xd1', '\x8d', '\xd1', '\x8e', + char text[] = { + '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07', '\x08', '\x09', '\x0a', '\x0b', '\x0c', '\x0d', '\x0e', '\x0f', + '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x1a', '\x1b', '\x1c', '\x1d', '\x1e', '\x1f', + '\x20', '\x21', '\x22', '\x23', '\x24', '\x25', '\x26', '\x27', '\x28', '\x29', '\x2a', '\x2b', '\x2c', '\x2d', '\x2e', '\x2f', + '\x30', '\x31', '\x32', '\x33', '\x34', '\x35', '\x36', '\x37', '\x38', '\x39', '\x3a', '\x3b', '\x3c', '\x3d', '\x3e', '\x3f', + '\x40', '\x41', '\x42', '\x43', '\x44', '\x45', '\x46', '\x47', '\x48', '\x49', '\x4a', '\x4b', '\x4c', '\x4d', '\x4e', '\x4f', + '\x50', '\x51', '\x52', '\x53', '\x54', '\x55', '\x56', '\x57', '\x58', '\x59', '\x5a', '\x5b', '\x5c', '\x5d', '\x5e', '\x5f', + '\x60', '\x61', '\x62', '\x63', '\x64', '\x65', '\x66', '\x67', '\x68', '\x69', '\x6a', '\x6b', '\x6c', '\x6d', '\x6e', '\x6f', + '\x70', '\x71', '\x72', '\x73', '\x74', '\x75', '\x76', '\x77', '\x78', '\x79', '\x7a', '\x7b', '\x7c', '\x7d', '\x7e', '\x7f', + '\xcc', '\x81', '\xc3', '\x84', '\xc3', '\x96', '\xc3', '\x9c', '\xc4', '\x84', '\xc4', '\x86', '\xc4', '\x98', '\xc5', '\x81', + '\xc3', '\xa0', '\xc3', '\xa2', '\xc3', '\xa7', '\xc3', '\xa8', '\xc3', '\xa9', '\xc3', '\xaa', '\xd2', '\x90', '\xc2', '\xad', + '\xc3', '\x9f', '\xc3', '\xa4', '\xc3', '\xb6', '\xc3', '\xbc', '\xc4', '\x85', '\xc4', '\x87', '\xc4', '\x99', '\xc5', '\x82', + '\xc3', '\xab', '\xc3', '\xae', '\xc3', '\xaf', '\xc3', '\xb4', '\xc3', '\xb9', '\xc3', '\xbb', '\xd2', '\x91', '\xe9', '\x8b', + '\x8f', '\xc2', '\xa0', '\xc5', '\x83', '\xc3', '\x93', '\xc5', '\x9a', '\xc5', '\xbb', '\xc5', '\xb9', '\xd1', '\xac', '\xc2', + '\xa7', '\xd0', '\x81', '\xd1', '\xa2', '\xd1', '\xb2', '\xd1', '\xb4', '\xd0', '\x8e', '\xd0', '\x86', '\xd0', '\x84', '\xd0', + '\x87', '\xc2', '\xb0', '\xc5', '\x84', '\xc3', '\xb3', '\xc5', '\x9b', '\xc5', '\xbc', '\xc5', '\xba', '\xd1', '\xad', '\xe2', + '\x84', '\x96', '\xd1', '\x91', '\xd1', '\xa3', '\xd1', '\xb3', '\xd1', '\xb5', '\xd1', '\x9e', '\xd1', '\x96', '\xd1', '\x94', + '\xd1', '\x97', '\xd0', '\x90', '\xd0', '\x91', '\xd0', '\x92', '\xd0', '\x93', '\xd0', '\x94', '\xd0', '\x95', '\xd0', '\x96', + '\xd0', '\x97', '\xd0', '\x98', '\xd0', '\x99', '\xd0', '\x9a', '\xd0', '\x9b', '\xd0', '\x9c', '\xd0', '\x9d', '\xd0', '\x9e', + '\xd0', '\x9f', '\xd0', '\xa0', '\xd0', '\xa1', '\xd0', '\xa2', '\xd0', '\xa3', '\xd0', '\xa4', '\xd0', '\xa5', '\xd0', '\xa6', + '\xd0', '\xa7', '\xd0', '\xa8', '\xd0', '\xa9', '\xd0', '\xaa', '\xd0', '\xab', '\xd0', '\xac', '\xd0', '\xad', '\xd0', '\xae', + '\xd0', '\xaf', '\xd0', '\xb0', '\xd0', '\xb1', '\xd0', '\xb2', '\xd0', '\xb3', '\xd0', '\xb4', '\xd0', '\xb5', '\xd0', '\xb6', + '\xd0', '\xb7', '\xd0', '\xb8', '\xd0', '\xb9', '\xd0', '\xba', '\xd0', '\xbb', '\xd0', '\xbc', '\xd0', '\xbd', '\xd0', '\xbe', + '\xd0', '\xbf', '\xd1', '\x80', '\xd1', '\x81', '\xd1', '\x82', '\xd1', '\x83', '\xd1', '\x84', '\xd1', '\x85', '\xd1', '\x86', + '\xd1', '\x87', '\xd1', '\x88', '\xd1', '\x89', '\xd1', '\x8a', '\xd1', '\x8b', '\xd1', '\x8c', '\xd1', '\x8d', '\xd1', '\x8e', '\xd1', '\x8f'}; return TString(text, Y_ARRAY_SIZE(text)); } @@ -478,7 +478,7 @@ void TConversionTest::TestUTF8ToWide() { wchar16 buffer[4] = {0}; size_t written = 0; // the function must extract 2 symbols only - bool result = UTF8ToWide(utext, 5, buffer, written); + bool result = UTF8ToWide(utext, 5, buffer, written); UNIT_ASSERT(!result); UNIT_ASSERT(buffer[0] == 0x0410); UNIT_ASSERT(buffer[1] == 0x0411); @@ -488,7 +488,7 @@ void TConversionTest::TestUTF8ToWide() { memset(buffer, 0, 4); written = 0; - result = UTF8ToWide(utext, 1, buffer, written); + result = UTF8ToWide(utext, 1, buffer, written); UNIT_ASSERT(!result); UNIT_ASSERT(buffer[0] == 0x0000); UNIT_ASSERT(buffer[1] == 0x0000); @@ -537,12 +537,12 @@ void TConversionTest::TestGetNumOfUTF8Chars() { UNIT_ASSERT(n == 256); n = 0; - result = GetNumberOfUTF8Chars(utext, 5, n); + result = GetNumberOfUTF8Chars(utext, 5, n); UNIT_ASSERT(!result); UNIT_ASSERT(n == 2); n = 0; - result = GetNumberOfUTF8Chars(utext, 1, n); + result = GetNumberOfUTF8Chars(utext, 1, n); UNIT_ASSERT(!result); UNIT_ASSERT(n == 0); diff --git a/util/datetime/base.h b/util/datetime/base.h index 5e902b8f63..91d987a865 100644 --- a/util/datetime/base.h +++ b/util/datetime/base.h @@ -24,11 +24,11 @@ #include <time.h> -#ifdef _MSC_VER +#ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 4244) // conversion from 'time_t' to 'long', possible loss of data #endif // _MSC_VER - + // Microseconds since epoch class TInstant; @@ -818,6 +818,6 @@ static inline TInstant Now() noexcept { return TInstant::Now(); } -#ifdef _MSC_VER +#ifdef _MSC_VER #pragma warning(pop) -#endif // _MSC_VER +#endif // _MSC_VER diff --git a/util/datetime/base_ut.cpp b/util/datetime/base_ut.cpp index afc3f802eb..5db2bead12 100644 --- a/util/datetime/base_ut.cpp +++ b/util/datetime/base_ut.cpp @@ -298,7 +298,7 @@ Y_UNIT_TEST_SUITE(TDateTimeTest) { } return strcmp(zone0, zone1) == 0; } - + static bool CompareTMFull(const tm* t0, const tm* t1) { return t0 && t1 && CompareTM(*t0, *t1) && @@ -320,14 +320,14 @@ Y_UNIT_TEST_SUITE(TDateTimeTest) { for (time_t t = starttime; t < finishtime; t += step) { ptm0 = GmTimeR(&t, &tms0); UNIT_ASSERT_EQUAL(ptm0, &tms0); - -#ifdef _win_ + +#ifdef _win_ if (tms0.tm_year + 1900 > 3000) { // Windows: _MAX__TIME64_T == 23:59:59. 12/31/3000 UTC continue; } -#endif - +#endif + ptm1 = gmtime_r(&t, &tms1); if (!ptm1) { continue; @@ -372,7 +372,7 @@ Y_UNIT_TEST_SUITE(DateTimeTest) { } Y_UNIT_TEST(TestFromString) { - static const struct T { + static const struct T { const char* const Str; const TDuration::TValue MicroSeconds; const bool Parseable; @@ -383,7 +383,7 @@ Y_UNIT_TEST_SUITE(DateTimeTest) { {"3ms", 3000, true}, {"x3ms", 0, false}, }; - + for (const T* t = tests; t != std::end(tests); ++t) { // FromString bool parsed = false; @@ -400,9 +400,9 @@ Y_UNIT_TEST_SUITE(DateTimeTest) { if (t->Parseable) { UNIT_ASSERT_EQUAL(t->MicroSeconds, tryTime.MicroSeconds()); } - } - } - + } + } + Y_UNIT_TEST(TestSleep) { // check does not throw Sleep(TDuration::Seconds(0)); diff --git a/util/datetime/systime.cpp b/util/datetime/systime.cpp index 6ee7e8fc6e..6425aafe0c 100644 --- a/util/datetime/systime.cpp +++ b/util/datetime/systime.cpp @@ -89,9 +89,9 @@ struct tm* GmTimeR(const time_t* timer, struct tm* tmbuf) { static const int _ytab[2][12] = { {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}}; - + i64 time = static_cast<i64>(*timer); - + ui64 dayclock, dayno; int year = EPOCH_YR; diff --git a/util/draft/holder_vector.h b/util/draft/holder_vector.h index 1c62055bd9..7c80c64453 100644 --- a/util/draft/holder_vector.h +++ b/util/draft/holder_vector.h @@ -42,9 +42,9 @@ public: } void PushBack(std::unique_ptr<T> t) { - PushBack(t.release()); - } - + PushBack(t.release()); + } + void PushBack(THolder<T> t) { PushBack(t.Release()); } @@ -78,10 +78,10 @@ public: TBase::resize(newSize); } - void Swap(THolderVector& other) { - TBase::swap(other); - } - + void Swap(THolderVector& other) { + TBase::swap(other); + } + using TBase::operator[]; using TBase::operator bool; using TBase::at; diff --git a/util/draft/holder_vector_ut.cpp b/util/draft/holder_vector_ut.cpp index f64393860a..265af73549 100644 --- a/util/draft/holder_vector_ut.cpp +++ b/util/draft/holder_vector_ut.cpp @@ -49,21 +49,21 @@ Y_UNIT_TEST_SUITE(THolderVectorTest) { UNIT_ASSERT_VALUES_EQUAL(*ints[0], 1); UNIT_ASSERT(!holder); } - + Y_UNIT_TEST(TestSwap) { - THolderVector<int> v1; - v1.PushBack(new int(1)); - - THolderVector<int> v2; - v1.Swap(v2); - UNIT_ASSERT(v1.empty() && v2.size() == 1 && *v2.front() == 1); - } - + THolderVector<int> v1; + v1.PushBack(new int(1)); + + THolderVector<int> v2; + v1.Swap(v2); + UNIT_ASSERT(v1.empty() && v2.size() == 1 && *v2.front() == 1); + } + Y_UNIT_TEST(TestUniquePtr) { THolderVector<TString> v; std::unique_ptr<TString> str(new TString("hello")); - v.PushBack(std::move(str)); - UNIT_ASSERT(v.Size() == 1); - UNIT_ASSERT(str.get() == nullptr); - } + v.PushBack(std::move(str)); + UNIT_ASSERT(v.Size() == 1); + UNIT_ASSERT(str.get() == nullptr); + } } diff --git a/util/draft/matrix.h b/util/draft/matrix.h index 154d00b35e..6383cee03d 100644 --- a/util/draft/matrix.h +++ b/util/draft/matrix.h @@ -1,15 +1,15 @@ #pragma once - + #include <util/generic/noncopyable.h> #include <util/system/yassert.h> #include <util/system/defaults.h> -#include <string.h> - +#include <string.h> + template <typename T> class TMatrix: TNonCopyable { // Constructor/Destructor -public: - TMatrix() +public: + TMatrix() : Buf(nullptr) , Arr(nullptr) , M(0) @@ -17,7 +17,7 @@ public: , BufSize(0) { } - + TMatrix(size_t m, size_t n) : Buf(new T[m * n]) , Arr(Buf) @@ -26,7 +26,7 @@ public: , BufSize(m * n) { } - + TMatrix(size_t m, size_t n, T* buf) : Buf(nullptr) , Arr(buf) @@ -35,74 +35,74 @@ public: , BufSize(m * n) { } - - ~TMatrix() { - delete[] Buf; - } - + + ~TMatrix() { + delete[] Buf; + } + // Properties/Methods -public: - void Clear() { - M = N = 0; - } - +public: + void Clear() { + M = N = 0; + } + void ReDim(size_t m, size_t n) { Y_ASSERT(m >= 1 && n >= 1); - size_t newSize = m * n; - if (newSize > BufSize) { - T* newBuf = new T[newSize]; + size_t newSize = m * n; + if (newSize > BufSize) { + T* newBuf = new T[newSize]; delete[] Buf; - Arr = Buf = newBuf; - BufSize = newSize; - } + Arr = Buf = newBuf; + BufSize = newSize; + } M = m; N = n; - } - + } + size_t Width() const { - return N; - } - + return N; + } + size_t Height() const { - return M; - } - - // Access element matrix[i][j] + return M; + } + + // Access element matrix[i][j] T* operator[](size_t i) { Y_ASSERT(i >= 0 && i < M); - return Arr + i * N; - } - - // Access element matrix[i][j] + return Arr + i * N; + } + + // Access element matrix[i][j] const T* operator[](size_t i) const { Y_ASSERT(i >= 0 && i < M); - return Arr + i * N; - } - - // Access element matrix(i, j) + return Arr + i * N; + } + + // Access element matrix(i, j) T& operator()(size_t i, size_t j) { Y_ASSERT(i >= 0 && i < M && j >= 0 && j < N); - return Arr[i * N + j]; - } - - // Access element matrix(i, j) + return Arr[i * N + j]; + } + + // Access element matrix(i, j) const T& operator()(size_t i, size_t j) const { Y_ASSERT(i >= 0 && i < M && j >= 0 && j < N); - return Arr[i * N + j]; - } - - void Zero() { + return Arr[i * N + j]; + } + + void Zero() { memset((void*)Arr, 0, M * N * sizeof(T)); - } + } - void Fill(T value) { + void Fill(T value) { for (T *p = Arr, *end = Arr + M * N; p < end; ++p) - *p = value; - } - -private: - T* Buf; - T* Arr; + *p = value; + } + +private: + T* Buf; + T* Arr; size_t M, N; - size_t BufSize; -}; + size_t BufSize; +}; diff --git a/util/folder/dirent_win.c b/util/folder/dirent_win.c index 7e6db74ce5..b945630eaa 100644 --- a/util/folder/dirent_win.c +++ b/util/folder/dirent_win.c @@ -21,13 +21,13 @@ static void SetErrno() { struct DIR* opendir(const char* dirname) { struct DIR* dir = (struct DIR*)malloc(sizeof(struct DIR)); - if (!dir) { - return NULL; + if (!dir) { + return NULL; } - dir->sh = INVALID_HANDLE_VALUE; - dir->fff_templ = NULL; - dir->file_no = 0; - dir->readdir_buf = NULL; + dir->sh = INVALID_HANDLE_VALUE; + dir->fff_templ = NULL; + dir->file_no = 0; + dir->readdir_buf = NULL; int len = strlen(dirname); //Remove trailing slashes @@ -36,31 +36,31 @@ struct DIR* opendir(const char* dirname) { } int len_converted = MultiByteToWideChar(CP_UTF8, 0, dirname, len, 0, 0); if (len_converted == 0) { - closedir(dir); - return NULL; + closedir(dir); + return NULL; } dir->fff_templ = (WCHAR*)malloc((len_converted + 5) * sizeof(WCHAR)); - if (!dir->fff_templ) { - closedir(dir); - return NULL; + if (!dir->fff_templ) { + closedir(dir); + return NULL; } MultiByteToWideChar(CP_UTF8, 0, dirname, len, dir->fff_templ, len_converted); WCHAR append[] = {'\\', '*', '.', '*', 0}; memcpy(dir->fff_templ + len_converted, append, sizeof(append)); dir->sh = FindFirstFileW(dir->fff_templ, &dir->wfd); - if (dir->sh == INVALID_HANDLE_VALUE) { + if (dir->sh == INVALID_HANDLE_VALUE) { SetErrno(); - closedir(dir); - return NULL; + closedir(dir); + return NULL; } - + return dir; } int closedir(struct DIR* dir) { - if (dir->sh != INVALID_HANDLE_VALUE) - FindClose(dir->sh); + if (dir->sh != INVALID_HANDLE_VALUE) + FindClose(dir->sh); free(dir->fff_templ); free(dir->readdir_buf); free(dir); diff --git a/util/folder/dirut.cpp b/util/folder/dirut.cpp index ffc9b09f96..c05a54831a 100644 --- a/util/folder/dirut.cpp +++ b/util/folder/dirut.cpp @@ -459,7 +459,7 @@ TString GetHomeDir() { #ifndef _win32_ passwd* pw = nullptr; s = getenv("USER"); - if (s) + if (s) pw = getpwnam(s.data()); else pw = getpwuid(getuid()); @@ -517,7 +517,7 @@ TString GetSystemTempDir() { const char* var = "TMPDIR"; const char* def = "/tmp"; const char* r = getenv(var); - const char* result = r ? r : def; + const char* result = r ? r : def; return result[0] == '/' ? result : ResolveDir(result); #endif } diff --git a/util/folder/dirut_ut.cpp b/util/folder/dirut_ut.cpp index 45ebfc842c..fcdbc96d33 100644 --- a/util/folder/dirut_ut.cpp +++ b/util/folder/dirut_ut.cpp @@ -1,5 +1,5 @@ #include "dirut.h" -#include "tempdir.h" +#include "tempdir.h" #include <library/cpp/testing/unittest/registar.h> diff --git a/util/folder/filelist_ut.cpp b/util/folder/filelist_ut.cpp index 0cdcdf3d00..b042dd1ff5 100644 --- a/util/folder/filelist_ut.cpp +++ b/util/folder/filelist_ut.cpp @@ -1,6 +1,6 @@ #include "dirut.h" #include "filelist.h" -#include "tempdir.h" +#include "tempdir.h" #include <library/cpp/testing/unittest/registar.h> diff --git a/util/folder/fts_ut.cpp b/util/folder/fts_ut.cpp index c5d59e35f4..050aa467ad 100644 --- a/util/folder/fts_ut.cpp +++ b/util/folder/fts_ut.cpp @@ -1,6 +1,6 @@ #include "fts.h" #include "dirut.h" -#include "tempdir.h" +#include "tempdir.h" #include <library/cpp/testing/unittest/registar.h> #include <library/cpp/threading/future/async.h> diff --git a/util/folder/path.cpp b/util/folder/path.cpp index bfe0c67d68..96ebdc3dbe 100644 --- a/util/folder/path.cpp +++ b/util/folder/path.cpp @@ -335,7 +335,7 @@ bool TFsPath::Exists() const { void TFsPath::CheckExists() const { if (!Exists()) { - ythrow TIoException() << "path does not exist " << Path_; + ythrow TIoException() << "path does not exist " << Path_; } } @@ -452,7 +452,7 @@ void TFsPath::CopyTo(const TString& newPath, bool force) const { void TFsPath::ForceRenameTo(const TString& newPath) const { try { RenameTo(newPath); - } catch (const TIoSystemError& /* error */) { + } catch (const TIoSystemError& /* error */) { CopyTo(newPath, true); ForceDelete(); } diff --git a/util/folder/tempdir.cpp b/util/folder/tempdir.cpp index 6fdf8f753c..760cc03fa1 100644 --- a/util/folder/tempdir.cpp +++ b/util/folder/tempdir.cpp @@ -1,34 +1,34 @@ -#include "tempdir.h" +#include "tempdir.h" -#include "dirut.h" +#include "dirut.h" -#include <util/system/fs.h> -#include <util/system/maxlen.h> - -TTempDir::TTempDir() +#include <util/system/fs.h> +#include <util/system/maxlen.h> + +TTempDir::TTempDir() : TTempDir(nullptr, TCreationToken{}) { } TTempDir::TTempDir(const char* prefix, TCreationToken) - : TempDir() + : TempDir() , Remove(true) -{ - char tempDir[MAX_PATH]; +{ + char tempDir[MAX_PATH]; if (MakeTempDir(tempDir, prefix) != 0) { ythrow TSystemError() << "Can't create temporary directory"; } - TempDir = tempDir; -} - + TempDir = tempDir; +} + TTempDir::TTempDir(const TString& tempDir) - : TempDir(tempDir) + : TempDir(tempDir) , Remove(true) -{ +{ NFs::Remove(TempDir); MakeDirIfNotExist(TempDir.c_str()); -} - +} + TTempDir TTempDir::NewTempDir(const TString& root) { return {root.c_str(), TCreationToken{}}; } @@ -37,8 +37,8 @@ void TTempDir::DoNotRemove() { Remove = false; } -TTempDir::~TTempDir() { +TTempDir::~TTempDir() { if (Remove) { RemoveDirWithContents(TempDir); } -} +} diff --git a/util/folder/tempdir.h b/util/folder/tempdir.h index ff458f83b9..1422669f02 100644 --- a/util/folder/tempdir.h +++ b/util/folder/tempdir.h @@ -1,19 +1,19 @@ -#pragma once - +#pragma once + #include "fwd.h" #include "path.h" #include <util/generic/string.h> - -class TTempDir { -public: + +class TTempDir { +public: /// Create new directory in system tmp folder. - TTempDir(); + TTempDir(); /// Create new directory with this fixed name. If it already exists, clear it. TTempDir(const TString& tempDir); - ~TTempDir(); - + ~TTempDir(); + /// Create new directory in given folder. static TTempDir NewTempDir(const TString& root); @@ -26,12 +26,12 @@ public: } const TFsPath& Path() const { - return TempDir; - } - + return TempDir; + } + void DoNotRemove(); -private: +private: struct TCreationToken {}; // Prevent people from confusing this ctor with the public one @@ -40,4 +40,4 @@ private: TFsPath TempDir; bool Remove; -}; +}; diff --git a/util/generic/algorithm.h b/util/generic/algorithm.h index badfb88993..88f6e25021 100644 --- a/util/generic/algorithm.h +++ b/util/generic/algorithm.h @@ -337,11 +337,11 @@ void StableSortUniqueBy(C& c, const TGetKey& getKey) { c.erase(UniqueBy(c.begin(), c.end(), getKey), c.end()); } -template <class C, class TValue> -void Erase(C& c, const TValue& value) { - c.erase(std::remove(c.begin(), c.end(), value), c.end()); -} - +template <class C, class TValue> +void Erase(C& c, const TValue& value) { + c.erase(std::remove(c.begin(), c.end(), value), c.end()); +} + template <class C, class P> void EraseIf(C& c, P p) { c.erase(std::remove_if(c.begin(), c.end(), p), c.end()); diff --git a/util/generic/algorithm_ut.cpp b/util/generic/algorithm_ut.cpp index 8d732fcc0c..7cb719d3b1 100644 --- a/util/generic/algorithm_ut.cpp +++ b/util/generic/algorithm_ut.cpp @@ -269,10 +269,10 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { Y_UNIT_TEST(EraseTest) { TVector<int> data = {5, 4, 3, 2, 1, 0}; TVector<int> expected = {5, 4, 2, 1, 0}; - Erase(data, 3); - UNIT_ASSERT_EQUAL(data, expected); - } - + Erase(data, 3); + UNIT_ASSERT_EQUAL(data, expected); + } + Y_UNIT_TEST(EraseIfTest) { TVector<int> data = {5, 4, 3, 2, 1, 0}; TVector<int> expected = {2, 1, 0}; diff --git a/util/generic/bitops.h b/util/generic/bitops.h index 2db15fc59b..787a5bc69d 100644 --- a/util/generic/bitops.h +++ b/util/generic/bitops.h @@ -57,7 +57,7 @@ namespace NBitOps { return (v >> 32ULL) | (v << 32ULL); } -#if defined(__GNUC__) +#if defined(__GNUC__) inline unsigned GetValueBitCountImpl(unsigned int value) noexcept { Y_ASSERT(value); // because __builtin_clz* have undefined result for zero. return std::numeric_limits<unsigned int>::digits - __builtin_clz(value); @@ -88,7 +88,7 @@ namespace NBitOps { } #endif -#if defined(__GNUC__) +#if defined(__GNUC__) inline unsigned CountTrailingZeroBitsImpl(unsigned int value) noexcept { Y_ASSERT(value); // because __builtin_ctz* have undefined result for zero. return __builtin_ctz(value); diff --git a/util/generic/strbase.h b/util/generic/strbase.h index ab39fc7537..3b16c03c72 100644 --- a/util/generic/strbase.h +++ b/util/generic/strbase.h @@ -312,8 +312,8 @@ public: inline bool StartsWith(TCharType ch) const noexcept { return !empty() && TTraits::eq(*Ptr(), ch); - } - + } + inline bool EndsWith(const TCharType* s, size_t n) const noexcept { return EndsWith(Ptr(), Len(), s, n); } @@ -324,8 +324,8 @@ public: inline bool EndsWith(TCharType ch) const noexcept { return !empty() && TTraits::eq(Ptr()[Len() - 1], ch); - } - + } + template <typename TDerived2, typename TTraits2> bool operator==(const TStringBase<TDerived2, TChar, TTraits2>& s2) const noexcept { return equal(*this, s2); @@ -473,8 +473,8 @@ public: inline size_t rfind(const TStringView str, size_t pos = npos) const { return AsStringView().rfind(str.data(), pos, str.size()); - } - + } + //~~~~Contains~~~~ /** * @returns Whether this string contains the provided substring. diff --git a/util/generic/string.h b/util/generic/string.h index 8cd8aa6917..dfbd626a4a 100644 --- a/util/generic/string.h +++ b/util/generic/string.h @@ -266,22 +266,22 @@ public: #endif } - using TBase::back; - + using TBase::back; + inline reference back() noexcept { Y_ASSERT(!this->empty()); #ifdef TSTRING_IS_STD_STRING return Storage_.back(); #else - if (Y_UNLIKELY(this->empty())) { + if (Y_UNLIKELY(this->empty())) { return reference(*this, 0); - } + } return reference(*this, length() - 1); #endif - } - + } + using TBase::front; inline reference front() noexcept { @@ -606,9 +606,9 @@ public: } TBasicString& assign(TCharType ch) { - return assign(&ch, 1); - } - + return assign(&ch, 1); + } + TBasicString& assign(const TCharType* pc, size_t len) { #if defined(address_sanitizer_enabled) || defined(thread_sanitizer_enabled) pc = (const TCharType*)HidePointerOrigin((void*)pc); @@ -704,9 +704,9 @@ public: TBasicString& operator=(std::nullptr_t) = delete; TBasicString& operator=(TExplicitType<TCharType> ch) { - return assign(ch); - } - + return assign(ch); + } + inline void reserve(size_t len) { MutRef().reserve(len); } @@ -931,12 +931,12 @@ public: friend TBasicString operator+(const TBasicStringBuf<TCharType, TTraits> s1, const TBasicString& s2) Y_WARN_UNUSED_RESULT { return Join(s1, s2); - } - + } + friend TBasicString operator+(const TCharType* s1, const TBasicString& s2) Y_WARN_UNUSED_RESULT { return Join(s1, s2); - } - + } + friend TBasicString operator+(std::basic_string<TCharType, TTraits> l, TBasicString r) { return l + r.ConstRef(); } diff --git a/util/generic/string_ut.cpp b/util/generic/string_ut.cpp index ac82e9091d..86fc6aef99 100644 --- a/util/generic/string_ut.cpp +++ b/util/generic/string_ut.cpp @@ -740,11 +740,11 @@ public: UNIT_TEST(TestJoin); UNIT_TEST(TestCopy); UNIT_TEST(TestStrCpy); - UNIT_TEST(TestPrefixSuffix); + UNIT_TEST(TestPrefixSuffix); #ifndef TSTRING_IS_STD_STRING UNIT_TEST(TestCharRef); #endif - UNIT_TEST(TestBack) + UNIT_TEST(TestBack) UNIT_TEST(TestFront) UNIT_TEST(TestIterators); UNIT_TEST(TestReverseIterators); @@ -794,7 +794,7 @@ public: UNIT_TEST(TestFind); UNIT_TEST(TestContains); UNIT_TEST(TestOperators); - UNIT_TEST(TestLetOperator) + UNIT_TEST(TestLetOperator) UNIT_TEST(TestMulOperators); UNIT_TEST(TestFuncs); UNIT_TEST(TestUtils); @@ -802,11 +802,11 @@ public: UNIT_TEST(TestJoin); UNIT_TEST(TestCopy); UNIT_TEST(TestStrCpy); - UNIT_TEST(TestPrefixSuffix); + UNIT_TEST(TestPrefixSuffix); #ifndef TSTRING_IS_STD_STRING UNIT_TEST(TestCharRef); #endif - UNIT_TEST(TestBack); + UNIT_TEST(TestBack); UNIT_TEST(TestFront) UNIT_TEST(TestDecodingMethods); UNIT_TEST(TestIterators); @@ -881,20 +881,20 @@ private: s2.AppendUtf8(text); UNIT_ASSERT(testAppend == s2); } - - void TestLetOperator() { + + void TestLetOperator() { TUtf16String str; - + str = wchar16('X'); UNIT_ASSERT(str == TUtf16String::FromAscii("X")); - + const TUtf16String hello = TUtf16String::FromAscii("hello"); str = hello.data(); - UNIT_ASSERT(str == hello); - - str = hello; - UNIT_ASSERT(str == hello); - } + UNIT_ASSERT(str == hello); + + str = hello; + UNIT_ASSERT(str == hello); + } void TestStringLiterals() { TUtf16String s1 = u"hello"; diff --git a/util/generic/string_ut.h b/util/generic/string_ut.h index 44bb10bdeb..518e6d10ea 100644 --- a/util/generic/string_ut.h +++ b/util/generic/string_ut.h @@ -699,20 +699,20 @@ public: const TStringType rs = Data._0123401234(); UNIT_ASSERT(rs.rfind(*Data._3()) == 8); - + const TStringType empty; - UNIT_ASSERT(empty.find(empty) == 0); - UNIT_ASSERT(s.find(empty, 0) == 0); - UNIT_ASSERT(s.find(empty, 1) == 1); - UNIT_ASSERT(s.find(empty, s.length()) == s.length()); + UNIT_ASSERT(empty.find(empty) == 0); + UNIT_ASSERT(s.find(empty, 0) == 0); + UNIT_ASSERT(s.find(empty, 1) == 1); + UNIT_ASSERT(s.find(empty, s.length()) == s.length()); UNIT_ASSERT(s.find(empty, s.length() + 1) == TStringType::npos); - - UNIT_ASSERT(s.rfind(empty) == s.length()); - UNIT_ASSERT(empty.rfind(empty) == 0); + + UNIT_ASSERT(s.rfind(empty) == s.length()); + UNIT_ASSERT(empty.rfind(empty) == 0); UNIT_ASSERT(empty.rfind(s) == TStringType::npos); - + UNIT_ASSERT(s2.rfind(s) == TStringType::npos); - UNIT_ASSERT(s.rfind(s2) == 0); + UNIT_ASSERT(s.rfind(s2) == 0); UNIT_ASSERT(s.rfind(TStringType(Data._345())) == 10); UNIT_ASSERT(s.rfind(TStringType(Data._345()), 13) == 10); UNIT_ASSERT(s.rfind(TStringType(Data._345()), 10) == 10); @@ -736,7 +736,7 @@ public: UNIT_ASSERT(s.Contains(empty)); UNIT_ASSERT(!empty.Contains(s)); UNIT_ASSERT(empty.Contains(empty)); - UNIT_ASSERT(s.Contains(empty, s.length())); + UNIT_ASSERT(s.Contains(empty, s.length())); } // Operators @@ -885,9 +885,9 @@ public: s2.assign(Data._0123456(), 4); UNIT_ASSERT(s2 == Data._0123()); - s2.assign('1'); - UNIT_ASSERT(s2 == Data._1()); - + s2.assign('1'); + UNIT_ASSERT(s2 == Data._1()); + s2.assign(Data._0123456()); UNIT_ASSERT(s2 == Data._0123456()); @@ -978,8 +978,8 @@ public: UNIT_ASSERT_EQUAL(data[4], 0); } } - - void TestPrefixSuffix() { + + void TestPrefixSuffix() { const TStringType emptyStr; UNIT_ASSERT_EQUAL(emptyStr.StartsWith('x'), false); UNIT_ASSERT_EQUAL(emptyStr.EndsWith('x'), false); @@ -987,7 +987,7 @@ public: UNIT_ASSERT_EQUAL(emptyStr.EndsWith(0), false); UNIT_ASSERT_EQUAL(emptyStr.StartsWith(emptyStr), true); UNIT_ASSERT_EQUAL(emptyStr.EndsWith(emptyStr), true); - + const char_type chars[] = {'h', 'e', 'l', 'l', 'o', 0}; const TStringType str(chars); UNIT_ASSERT_EQUAL(str.StartsWith('h'), true); @@ -996,7 +996,7 @@ public: UNIT_ASSERT_EQUAL(str.EndsWith('h'), false); UNIT_ASSERT_EQUAL(str.StartsWith(emptyStr), true); UNIT_ASSERT_EQUAL(str.EndsWith(emptyStr), true); - } + } #ifndef TSTRING_IS_STD_STRING void TestCharRef() { @@ -1046,20 +1046,20 @@ public: } } #endif - - void TestBack() { - const char_type chars[] = {'f', 'o', 'o', 0}; - + + void TestBack() { + const char_type chars[] = {'f', 'o', 'o', 0}; + TStringType str = chars; const TStringType constStr = str; - + UNIT_ASSERT_VALUES_EQUAL(constStr.back(), (ui8)'o'); UNIT_ASSERT_VALUES_EQUAL(str.back(), (ui8)'o'); - - str.back() = 'r'; + + str.back() = 'r'; UNIT_ASSERT_VALUES_EQUAL(constStr.back(), (ui8)'o'); UNIT_ASSERT_VALUES_EQUAL(str.back(), (ui8)'r'); - } + } void TestFront() { const char_type chars[] = {'f', 'o', 'o', 0}; diff --git a/util/generic/ymath.cpp b/util/generic/ymath.cpp index 31270728f4..ec83f696f7 100644 --- a/util/generic/ymath.cpp +++ b/util/generic/ymath.cpp @@ -1,5 +1,5 @@ -#include "ymath.h" - +#include "ymath.h" + double Exp2(double x) { return pow(2.0, x); } @@ -9,23 +9,23 @@ float Exp2f(float x) { } #ifdef _MSC_VER - -double Erf(double x) { + +double Erf(double x) { static constexpr double _M_2_SQRTPI = 1.12837916709551257390; static constexpr double eps = 1.0e-7; - if (fabs(x) >= 3.75) - return x > 0 ? 1.0 : -1.0; - double r = _M_2_SQRTPI * x; - double f = r; - for (int i = 1;; ++i) { - r *= -x * x / i; - f += r / (2 * i + 1); - if (fabs(r) < eps * (2 * i + 1)) - break; - } - return f; -} - + if (fabs(x) >= 3.75) + return x > 0 ? 1.0 : -1.0; + double r = _M_2_SQRTPI * x; + double f = r; + for (int i = 1;; ++i) { + r *= -x * x / i; + f += r / (2 * i + 1); + if (fabs(r) < eps * (2 * i + 1)) + break; + } + return f; +} + #endif // _MSC_VER double LogGammaImpl(double x) { diff --git a/util/generic/ymath.h b/util/generic/ymath.h index 9ff9ae2abe..97abaf6e31 100644 --- a/util/generic/ymath.h +++ b/util/generic/ymath.h @@ -1,7 +1,7 @@ #pragma once #include <util/system/yassert.h> -#include <util/system/defaults.h> +#include <util/system/defaults.h> #include <cmath> #include <cfloat> @@ -91,14 +91,14 @@ static inline bool IsNan(double f) { inline bool IsValidFloat(double f) { return IsFinite(f) && !IsNan(f); } - + #ifdef _MSC_VER -double Erf(double x); -#else -inline double Erf(double x) { - return erf(x); -} -#endif +double Erf(double x); +#else +inline double Erf(double x) { + return erf(x); +} +#endif /** * @returns Natural logarithm of the absolute value diff --git a/util/generic/ymath_ut.cpp b/util/generic/ymath_ut.cpp index 29190b55eb..8861c05dcd 100644 --- a/util/generic/ymath_ut.cpp +++ b/util/generic/ymath_ut.cpp @@ -123,32 +123,32 @@ void TMathTest::TestClp2() { } } } - -void TMathTest::TestErf() { - static const double a = -5.0; + +void TMathTest::TestErf() { + static const double a = -5.0; static const double b = 5.0; - static const int n = 50; - static const double step = (b - a) / n; - - static const double values[n + 1] = { - -1.0000000, -1.0000000, -1.0000000, -1.0000000, -1.0000000, - -1.0000000, -0.9999999, -0.9999996, -0.9999985, -0.9999940, - -0.9999779, -0.9999250, -0.9997640, -0.9993115, -0.9981372, - -0.9953223, -0.9890905, -0.9763484, -0.9522851, -0.9103140, - -0.8427008, -0.7421010, -0.6038561, -0.4283924, -0.2227026, + static const int n = 50; + static const double step = (b - a) / n; + + static const double values[n + 1] = { + -1.0000000, -1.0000000, -1.0000000, -1.0000000, -1.0000000, + -1.0000000, -0.9999999, -0.9999996, -0.9999985, -0.9999940, + -0.9999779, -0.9999250, -0.9997640, -0.9993115, -0.9981372, + -0.9953223, -0.9890905, -0.9763484, -0.9522851, -0.9103140, + -0.8427008, -0.7421010, -0.6038561, -0.4283924, -0.2227026, 0.0000000, 0.2227026, 0.4283924, 0.6038561, 0.7421010, 0.8427008, 0.9103140, 0.9522851, 0.9763484, 0.9890905, 0.9953223, 0.9981372, 0.9993115, 0.9997640, 0.9999250, 0.9999779, 0.9999940, 0.9999985, 0.9999996, 0.9999999, 1.0000000, 1.0000000, 1.0000000, 1.0000000, 1.0000000, 1.0000000}; - - double x = a; - for (int i = 0; i <= n; ++i, x += step) { - double f = Erf(x); - UNIT_ASSERT_DOUBLES_EQUAL(f, values[i], 1e-7); - } -} + + double x = a; + for (int i = 0; i <= n; ++i, x += step) { + double f = Erf(x); + UNIT_ASSERT_DOUBLES_EQUAL(f, values[i], 1e-7); + } +} void TMathTest::TestLogGamma() { double curVal = 0.0; diff --git a/util/memory/pool.h b/util/memory/pool.h index 13c8b6b9ed..da1b544c37 100644 --- a/util/memory/pool.h +++ b/util/memory/pool.h @@ -159,7 +159,7 @@ public: inline T* Allocate() { return (T*)this->Allocate(sizeof(T), alignof(T)); } - + template <typename T> inline T* Allocate(size_t align) { return (T*)this->Allocate(sizeof(T), Max(align, alignof(T))); @@ -175,20 +175,20 @@ public: return (T*)this->Allocate(sizeof(T) * count, Max(align, alignof(T))); } - template <typename T> - inline T* AllocateZeroArray(size_t count) { - T* ptr = AllocateArray<T>(count); - memset(ptr, 0, count * sizeof(T)); - return ptr; - } - - template <typename T> - inline T* AllocateZeroArray(size_t count, size_t align) { - T* ptr = AllocateArray<T>(count, align); - memset(ptr, 0, count * sizeof(T)); - return ptr; - } - + template <typename T> + inline T* AllocateZeroArray(size_t count) { + T* ptr = AllocateArray<T>(count); + memset(ptr, 0, count * sizeof(T)); + return ptr; + } + + template <typename T> + inline T* AllocateZeroArray(size_t count, size_t align) { + T* ptr = AllocateArray<T>(count, align); + memset(ptr, 0, count * sizeof(T)); + return ptr; + } + template <typename T, typename... Args> inline T* New(Args&&... args) { return new (Allocate<T>()) T(std::forward<Args>(args)...); diff --git a/util/memory/pool_ut.cpp b/util/memory/pool_ut.cpp index 1158a8ca42..3268ed841f 100644 --- a/util/memory/pool_ut.cpp +++ b/util/memory/pool_ut.cpp @@ -80,7 +80,7 @@ class TMemPoolTest: public TTestBase { UNIT_TEST_SUITE(TMemPoolTest); UNIT_TEST(TestMemPool) UNIT_TEST(TestAlign) - UNIT_TEST(TestZeroArray) + UNIT_TEST(TestZeroArray) UNIT_TEST(TestLargeStartingAlign) UNIT_TEST(TestMoveAlloc) UNIT_TEST(TestRoundUpToNextPowerOfTwoOption) @@ -196,22 +196,22 @@ private: UNIT_ASSERT_VALUES_EQUAL(reinterpret_cast<uintptr_t>(aligned256) & 255, 0); UNIT_ASSERT_VALUES_EQUAL(reinterpret_cast<uintptr_t>(aligned1024) & 1023, 0); } - - void TestZeroArray() { - TMemoryPool pool(1); - size_t size = 10; - i32* intArray = pool.AllocateZeroArray<i32>(size); - for (size_t i = 0; i < size; ++i) { - UNIT_ASSERT(intArray[i] == 0); - } - + + void TestZeroArray() { + TMemoryPool pool(1); + size_t size = 10; + i32* intArray = pool.AllocateZeroArray<i32>(size); + for (size_t i = 0; i < size; ++i) { + UNIT_ASSERT(intArray[i] == 0); + } + size_t align = 256; - ui8* byteArray = pool.AllocateZeroArray<ui8>(size, align); - UNIT_ASSERT(size_t(byteArray) % align == 0); - for (size_t i = 0; i < size; ++i) { - UNIT_ASSERT(byteArray[i] == 0); + ui8* byteArray = pool.AllocateZeroArray<ui8>(size, align); + UNIT_ASSERT(size_t(byteArray) % align == 0); + for (size_t i = 0; i < size; ++i) { + UNIT_ASSERT(byteArray[i] == 0); } - } + } void TestLargeStartingAlign() { TMemoryPool pool(1); diff --git a/util/network/endpoint_ut.cpp b/util/network/endpoint_ut.cpp index d5e40dd6e1..69f6365d77 100644 --- a/util/network/endpoint_ut.cpp +++ b/util/network/endpoint_ut.cpp @@ -70,20 +70,20 @@ Y_UNIT_TEST_SUITE(TEndpointTest) { he.insert(ep1); he.insert(ep2); - UNIT_ASSERT_VALUES_EQUAL(3u, he.size()); + UNIT_ASSERT_VALUES_EQUAL(3u, he.size()); he.insert(ep2_); - UNIT_ASSERT_VALUES_EQUAL(3u, he.size()); + UNIT_ASSERT_VALUES_EQUAL(3u, he.size()); he.insert(ep3); he.insert(ep3_); - UNIT_ASSERT_VALUES_EQUAL(4u, he.size()); + UNIT_ASSERT_VALUES_EQUAL(4u, he.size()); he.insert(ep4); - UNIT_ASSERT_VALUES_EQUAL(5u, he.size()); + UNIT_ASSERT_VALUES_EQUAL(5u, he.size()); } Y_UNIT_TEST(TestEqual) { diff --git a/util/network/socket.cpp b/util/network/socket.cpp index 4f6e804346..44d04424bf 100644 --- a/util/network/socket.cpp +++ b/util/network/socket.cpp @@ -713,7 +713,7 @@ static inline ssize_t DoSendV(SOCKET fd, const struct iovec* iov, size_t count) } while (ret == -1 && errno == EINTR); if (ret < 0) { - return -LastSystemError(); + return -LastSystemError(); } return ret; @@ -1092,11 +1092,11 @@ struct addrinfo* TNetworkAddress::Info() const noexcept { TNetworkResolutionError::TNetworkResolutionError(int error) { const char* errMsg = nullptr; -#ifdef _win_ +#ifdef _win_ errMsg = LastSystemErrorText(error); // gai_strerror is not thread-safe on Windows -#else - errMsg = gai_strerror(error); -#endif +#else + errMsg = gai_strerror(error); +#endif (*this) << errMsg << "(" << error; #if defined(_unix_) @@ -1106,8 +1106,8 @@ TNetworkResolutionError::TNetworkResolutionError(int error) { #endif (*this) << "): "; -} - +} + #if defined(_unix_) static inline int GetFlags(int fd) { const int ret = fcntl(fd, F_GETFL); diff --git a/util/network/socket.h b/util/network/socket.h index 40c8648b40..0e587d2fff 100644 --- a/util/network/socket.h +++ b/util/network/socket.h @@ -148,8 +148,8 @@ struct addrinfo; class TNetworkResolutionError: public yexception { public: - // @param error error code (EAI_XXX) returned by getaddrinfo or getnameinfo (not errno) - TNetworkResolutionError(int error); + // @param error error code (EAI_XXX) returned by getaddrinfo or getnameinfo (not errno) + TNetworkResolutionError(int error); }; struct TUnixSocketPath { diff --git a/util/network/socket_ut.cpp b/util/network/socket_ut.cpp index 6b20e11f70..4a826dc170 100644 --- a/util/network/socket_ut.cpp +++ b/util/network/socket_ut.cpp @@ -15,18 +15,18 @@ #endif class TSockTest: public TTestBase { - UNIT_TEST_SUITE(TSockTest); + UNIT_TEST_SUITE(TSockTest); UNIT_TEST(TestSock); UNIT_TEST(TestTimeout); -#ifndef _win_ // Test hangs on Windows +#ifndef _win_ // Test hangs on Windows UNIT_TEST_EXCEPTION(TestConnectionRefused, yexception); -#endif +#endif UNIT_TEST(TestNetworkResolutionError); UNIT_TEST(TestNetworkResolutionErrorMessage); UNIT_TEST(TestBrokenPipe); UNIT_TEST(TestClose); UNIT_TEST(TestReusePortAvailCheck); - UNIT_TEST_SUITE_END(); + UNIT_TEST_SUITE_END(); public: void TestSock(); @@ -53,45 +53,45 @@ void TSockTest::TestSock() { UNIT_ASSERT(!si.ReadLine().empty()); } -void TSockTest::TestTimeout() { - static const int timeout = 1000; - i64 startTime = millisec(); - try { - TNetworkAddress addr("localhost", 1313); - TSocket s(addr, TDuration::MilliSeconds(timeout)); +void TSockTest::TestTimeout() { + static const int timeout = 1000; + i64 startTime = millisec(); + try { + TNetworkAddress addr("localhost", 1313); + TSocket s(addr, TDuration::MilliSeconds(timeout)); } catch (const yexception&) { - } - int realTimeout = (int)(millisec() - startTime); - if (realTimeout > timeout + 2000) { + } + int realTimeout = (int)(millisec() - startTime); + if (realTimeout > timeout + 2000) { TString err = TStringBuilder() << "Timeout exceeded: " << realTimeout << " ms (expected " << timeout << " ms)"; - UNIT_FAIL(err); - } -} - -void TSockTest::TestConnectionRefused() { - TNetworkAddress addr("localhost", 1313); - TSocket s(addr); -} - -void TSockTest::TestNetworkResolutionError() { + UNIT_FAIL(err); + } +} + +void TSockTest::TestConnectionRefused() { + TNetworkAddress addr("localhost", 1313); + TSocket s(addr); +} + +void TSockTest::TestNetworkResolutionError() { TString errMsg; - try { - TNetworkAddress addr("", 0); + try { + TNetworkAddress addr("", 0); } catch (const TNetworkResolutionError& e) { - errMsg = e.what(); - } - + errMsg = e.what(); + } + if (errMsg.empty()) { - return; // on Windows getaddrinfo("", 0, ...) returns "OK" + return; // on Windows getaddrinfo("", 0, ...) returns "OK" } - - int expectedErr = EAI_NONAME; + + int expectedErr = EAI_NONAME; TString expectedErrMsg = gai_strerror(expectedErr); if (errMsg.find(expectedErrMsg) == TString::npos) { UNIT_FAIL("TNetworkResolutionError contains\nInvalid msg: " + errMsg + "\nExpected msg: " + expectedErrMsg + "\n"); - } -} - + } +} + void TSockTest::TestNetworkResolutionErrorMessage() { #ifdef _unix_ auto str = [](int code) -> TString { diff --git a/util/random/mersenne.cpp b/util/random/mersenne.cpp index 59779c1ec1..9d27da21aa 100644 --- a/util/random/mersenne.cpp +++ b/util/random/mersenne.cpp @@ -1 +1 @@ -#include "mersenne.h" +#include "mersenne.h" diff --git a/util/str_stl.h b/util/str_stl.h index f1e137181d..3ec85f5084 100644 --- a/util/str_stl.h +++ b/util/str_stl.h @@ -62,14 +62,14 @@ struct hash: public NHashPrivate::THashHelper<T, std::is_scalar<T>::value && !st }; template <typename T> -struct hash<const T*> { +struct hash<const T*> { inline size_t operator()(const T* t) const noexcept { return NumericHash(t); } }; template <class T> -struct hash<T*>: public ::hash<const T*> { +struct hash<T*>: public ::hash<const T*> { }; template <> diff --git a/util/stream/buffered.cpp b/util/stream/buffered.cpp index a00e592e1c..0455092912 100644 --- a/util/stream/buffered.cpp +++ b/util/stream/buffered.cpp @@ -396,7 +396,7 @@ void TBufferedOutputBase::DoFlush() { void TBufferedOutputBase::DoFinish() { THolder<TImpl> impl(Impl_.Release()); - if (impl) { + if (impl) { impl->Finish(); } } diff --git a/util/stream/input.cpp b/util/stream/input.cpp index 6e8170f2f9..27bdfb404e 100644 --- a/util/stream/input.cpp +++ b/util/stream/input.cpp @@ -81,7 +81,7 @@ void IInputStream::LoadOrFail(void* buf, size_t len) { size_t IInputStream::ReadLine(TString& st) { const size_t ret = ReadTo(st, '\n'); - if (ret && !st.empty() && st.back() == '\r') { + if (ret && !st.empty() && st.back() == '\r') { st.pop_back(); } @@ -170,7 +170,7 @@ namespace { const size_t ret = fread(buf, 1, len, F_); if (ret < len && ferror(F_)) { - ythrow TSystemError() << "can not read from stdin"; + ythrow TSystemError() << "can not read from stdin"; } return ret; @@ -192,7 +192,7 @@ namespace { size_t DoReadTo(TString& st, char ch) override { auto&& guard = Guard(M_); - + (void)guard; const auto r = getdelim(&B_, &L_, ch, F_); @@ -200,22 +200,22 @@ namespace { if (r < 0) { if (ferror(F_)) { ythrow TSystemError() << "can not read from stdin"; - } + } st.clear(); return 0; - } + } st.AssignNoAlias(B_, r); if (st && st.back() == ch) { st.pop_back(); - } + } return r; - } - + } + TAdaptiveLock M_; char* B_ = nullptr; size_t L_ = 0; diff --git a/util/stream/ios_ut.cpp b/util/stream/ios_ut.cpp index 139f4296e5..9fd05ebd87 100644 --- a/util/stream/ios_ut.cpp +++ b/util/stream/ios_ut.cpp @@ -304,32 +304,32 @@ namespace { size_t Index_; }; - const char Text[] = + const char Text[] = // UTF8 encoded "one \ntwo\r\nthree\n\tfour\nfive\n" in russian and ... - "один \n" - "два\r\n" - "три\n" - "\tчетыре\n" - "пять\n" + "один \n" + "два\r\n" + "три\n" + "\tчетыре\n" + "пять\n" // ... additional test cases - "\r\n" - "\n\r" // this char goes to the front of the next string - "one two\n" - "123\r\n" - "\t\r "; + "\r\n" + "\n\r" // this char goes to the front of the next string + "one two\n" + "123\r\n" + "\t\r "; - const char* Expected[] = { + const char* Expected[] = { // UTF8 encoded "one ", "two", "three", "\tfour", "five" in russian and ... - "один ", - "два", - "три", - "\tчетыре", - "пять", + "один ", + "два", + "три", + "\tчетыре", + "пять", // ... additional test cases - "", - "", - "\rone two", - "123", + "", + "", + "\rone two", + "123", "\t\r "}; void TestStreamReadTo1(IInputStream& input, const char* comment) { TString tmp; diff --git a/util/stream/output.cpp b/util/stream/output.cpp index db81b81b70..73f0e97e71 100644 --- a/util/stream/output.cpp +++ b/util/stream/output.cpp @@ -352,11 +352,11 @@ namespace { void DoWrite(const void* buf, size_t len) override { if (len != fwrite(buf, 1, len, F_)) { #if defined(_win_) - // On Windows, if 'F_' is console -- 'fwrite' returns count of written characters. - // If, for example, console output codepage is UTF-8, then returned value is - // not equal to 'len'. So, we ignore some 'errno' values... + // On Windows, if 'F_' is console -- 'fwrite' returns count of written characters. + // If, for example, console output codepage is UTF-8, then returned value is + // not equal to 'len'. So, we ignore some 'errno' values... if ((errno == 0 || errno == EINVAL || errno == EILSEQ) && _isatty(fileno(F_))) { - return; + return; } #endif ythrow TSystemError() << "write failed"; diff --git a/util/stream/output.h b/util/stream/output.h index 00eef50b95..e9fe6ef7a2 100644 --- a/util/stream/output.h +++ b/util/stream/output.h @@ -283,7 +283,7 @@ namespace NPrivate { * End-of-line output manipulator, basically the same as `std::endl`. */ static inline void Endl(IOutputStream& o) { - (o << '\n').Flush(); + (o << '\n').Flush(); } /** diff --git a/util/stream/pipe.cpp b/util/stream/pipe.cpp index 51be1934a7..abe1dcd2cb 100644 --- a/util/stream/pipe.cpp +++ b/util/stream/pipe.cpp @@ -10,11 +10,11 @@ public: inline TImpl(const TString& command, const char* mode) : Pipe_(nullptr) { -#ifndef _freebsd_ +#ifndef _freebsd_ if (strcmp(mode, "r+") == 0) { ythrow TSystemError(EINVAL) << "pipe \"r+\" mode is implemented only on FreeBSD"; } -#endif +#endif Pipe_ = ::popen(command.data(), mode); if (Pipe_ == nullptr) { ythrow TSystemError() << "failed to open pipe: " << command.Quote(); diff --git a/util/stream/printf_ut.cpp b/util/stream/printf_ut.cpp index 0eab167062..e7fb7dbe8d 100644 --- a/util/stream/printf_ut.cpp +++ b/util/stream/printf_ut.cpp @@ -14,12 +14,12 @@ Y_UNIT_TEST_SUITE(TStreamPrintfTest) { UNIT_ASSERT_EQUAL(ss.Str(), "qw er 1"); } -#ifdef __GNUC__ +#ifdef __GNUC__ #pragma GCC diagnostic ignored "-Wformat-zero-length" -#endif // __GNUC__ - +#endif // __GNUC__ + Y_UNIT_TEST(TestZeroString) { - UNIT_ASSERT_EQUAL(Printf(Cnull, ""), 0); + UNIT_ASSERT_EQUAL(Printf(Cnull, ""), 0); } Y_UNIT_TEST(TestLargePrintf) { diff --git a/util/stream/zlib.cpp b/util/stream/zlib.cpp index 60f4e9439f..958be7af2c 100644 --- a/util/stream/zlib.cpp +++ b/util/stream/zlib.cpp @@ -171,7 +171,7 @@ namespace { } ~TDecompressStream() override = default; - + private: size_t DoNext(const void** ptr, size_t len) override { void* buf = AdditionalData(); @@ -364,7 +364,7 @@ void TZLibCompress::DoWrite(const void* buf, size_t size) { } void TZLibCompress::DoFlush() { - if (Impl_) { + if (Impl_) { Impl_->Flush(); } } @@ -372,7 +372,7 @@ void TZLibCompress::DoFlush() { void TZLibCompress::DoFinish() { THolder<TImpl> impl(Impl_.Release()); - if (impl) { + if (impl) { impl->Finish(); } } diff --git a/util/string/cast.h b/util/string/cast.h index 90e925c194..af827da78b 100644 --- a/util/string/cast.h +++ b/util/string/cast.h @@ -165,11 +165,11 @@ inline T FromString(const std::string& s) { return ::FromString<T>(s.data(), s.size()); } -template <> +template <> inline TString FromString<TString>(const TString& s) { - return s; -} - + return s; +} + template <class T> inline T FromString(const TWtringBuf& s) { return ::FromString<T, typename TWtringBuf::char_type>(s.data(), s.size()); diff --git a/util/string/printf_ut.cpp b/util/string/printf_ut.cpp index 2b2f980b70..1b63d0f8bc 100644 --- a/util/string/printf_ut.cpp +++ b/util/string/printf_ut.cpp @@ -5,10 +5,10 @@ Y_UNIT_TEST_SUITE(TStringPrintf) { Y_UNIT_TEST(TestSprintf) { TString s; - int len = sprintf(s, "Hello %s", "world"); + int len = sprintf(s, "Hello %s", "world"); UNIT_ASSERT_EQUAL(s, TString("Hello world")); UNIT_ASSERT_EQUAL(len, 11); - } + } Y_UNIT_TEST(TestFcat) { TString s; diff --git a/util/string/strip_ut.cpp b/util/string/strip_ut.cpp index d1029d1498..25b6279863 100644 --- a/util/string/strip_ut.cpp +++ b/util/string/strip_ut.cpp @@ -7,7 +7,7 @@ Y_UNIT_TEST_SUITE(TStripStringTest) { Y_UNIT_TEST(TestStrip) { struct TTest { - const char* Str; + const char* Str; const char* StripLeftRes; const char* StripRightRes; const char* StripRes; @@ -25,7 +25,7 @@ Y_UNIT_TEST_SUITE(TStripStringTest) { {"abc", "abc", "abc", "abc"}, {"a c", "a c", "a c", "a c"}, }; - + for (const auto& test : tests) { TString inputStr(test.Str); @@ -41,7 +41,7 @@ Y_UNIT_TEST_SUITE(TStripStringTest) { UNIT_ASSERT_EQUAL(StripString(inputStrBuf), test.StripRes); UNIT_ASSERT_EQUAL(StripStringLeft(inputStrBuf), test.StripLeftRes); UNIT_ASSERT_EQUAL(StripStringRight(inputStrBuf), test.StripRightRes); - }; + }; } Y_UNIT_TEST(TestCustomStrip) { diff --git a/util/string/subst_ut.cpp b/util/string/subst_ut.cpp index 21eccef779..940d5195bc 100644 --- a/util/string/subst_ut.cpp +++ b/util/string/subst_ut.cpp @@ -121,13 +121,13 @@ Y_UNIT_TEST_SUITE(TStringSubst) { Y_UNIT_TEST(TestSubstGlobalOld) { TString s; - s = "aaa"; + s = "aaa"; SubstGlobal(s, "a", "bb"); UNIT_ASSERT_EQUAL(s, TString("bbbbbb")); - s = "aaa"; + s = "aaa"; SubstGlobal(s, "a", "b"); UNIT_ASSERT_EQUAL(s, TString("bbb")); - s = "aaa"; + s = "aaa"; SubstGlobal(s, "a", ""); UNIT_ASSERT_EQUAL(s, TString("")); s = "abcdefbcbcdfb"; @@ -168,7 +168,7 @@ Y_UNIT_TEST_SUITE(TStringSubst) { TString s = "aaa"; SubstGlobal(s, 'a', 'b', 1); UNIT_ASSERT_EQUAL(s, TString("abb")); - } + } Y_UNIT_TEST(TestSubstCharGlobalRet) { const TUtf16String w1 = u"abcdabcd"; diff --git a/util/string/type_ut.cpp b/util/string/type_ut.cpp index 03e7af62bd..daff2a7eec 100644 --- a/util/string/type_ut.cpp +++ b/util/string/type_ut.cpp @@ -6,11 +6,11 @@ Y_UNIT_TEST_SUITE(TStringClassify) { Y_UNIT_TEST(TestIsSpace) { - UNIT_ASSERT_EQUAL(IsSpace(" "), true); - UNIT_ASSERT_EQUAL(IsSpace("\t\r\n"), true); - UNIT_ASSERT_EQUAL(IsSpace(""), false); - UNIT_ASSERT_EQUAL(IsSpace(" a"), false); - } + UNIT_ASSERT_EQUAL(IsSpace(" "), true); + UNIT_ASSERT_EQUAL(IsSpace("\t\r\n"), true); + UNIT_ASSERT_EQUAL(IsSpace(""), false); + UNIT_ASSERT_EQUAL(IsSpace(" a"), false); + } Y_UNIT_TEST(TestIsTrue) { UNIT_ASSERT(IsTrue("1")); diff --git a/util/string/util.cpp b/util/string/util.cpp index b14f20bf75..10f265ee00 100644 --- a/util/string/util.cpp +++ b/util/string/util.cpp @@ -69,4 +69,4 @@ void Tr::Do(TString& str) const { for (auto it = str.begin() + changePosition; it != str.end(); ++it) { *it = ConvertChar(*it); } -} +} diff --git a/util/string/util.h b/util/string/util.h index 0d77a5042b..1e173ab75f 100644 --- a/util/string/util.h +++ b/util/string/util.h @@ -4,7 +4,7 @@ #include <cstring> #include <cstdarg> -#include <algorithm> +#include <algorithm> #include <util/system/defaults.h> #include <util/generic/string.h> @@ -13,7 +13,7 @@ /// @addtogroup Strings_Miscellaneous /// @{ int a2i(const TString& s); - + /// Removes the last character if it is equal to c. template <class T> inline void RemoveIfLast(T& s, int c) { @@ -170,7 +170,7 @@ public: *dst = 0; } void Do(char* s, size_t l) const { - for (size_t i = 0; i < l && s[i]; i++) + for (size_t i = 0; i < l && s[i]; i++) s[i] = ConvertChar(s[i]); } void Do(TString& str) const; @@ -180,16 +180,16 @@ private: size_t FindFirstChangePosition(const TString& str) const; }; - -// Removes all occurrences of given character from string + +// Removes all occurrences of given character from string template <typename TStringType> void RemoveAll(TStringType& str, typename TStringType::char_type ch) { size_t pos = str.find(ch); // 'find' to avoid cloning of string in 'TString.begin()' if (pos == TStringType::npos) - return; - + return; + typename TStringType::iterator begin = str.begin(); typename TStringType::iterator end = begin + str.length(); typename TStringType::iterator it = std::remove(begin + pos, end, ch); - str.erase(it, end); -} + str.erase(it, end); +} diff --git a/util/string/util_ut.cpp b/util/string/util_ut.cpp index 18a2d8e195..7012e9714c 100644 --- a/util/string/util_ut.cpp +++ b/util/string/util_ut.cpp @@ -22,25 +22,25 @@ public: UNIT_ASSERT_EQUAL(strcmp(rul.sep(s1), "+-"), 0); UNIT_ASSERT_EQUAL(rul.sep(s1), nullptr); } - - void TestRemoveAll() { - static const struct T { - const char* Str; - char Ch; - const char* Result; + + void TestRemoveAll() { + static const struct T { + const char* Str; + char Ch; + const char* Result; } tests[] = { {"", 'x', ""}, {"hello world", 'h', "ello world"}, {"hello world", 'l', "heo word"}, {"hello world", 'x', "hello world"}, }; - + for (const T* t = tests; t != std::end(tests); ++t) { TString str(t->Str); - RemoveAll(str, t->Ch); - UNIT_ASSERT_EQUAL(t->Result, str); - } - } + RemoveAll(str, t->Ch); + UNIT_ASSERT_EQUAL(t->Result, str); + } + } }; UNIT_TEST_SUITE_REGISTRATION(TStrUtilTest); diff --git a/util/string/vector.cpp b/util/string/vector.cpp index 9ba401f0a2..963186fe1e 100644 --- a/util/string/vector.cpp +++ b/util/string/vector.cpp @@ -88,4 +88,4 @@ TUtf16String JoinStrings(const TVector<TUtf16String>& v, size_t index, size_t co const size_t l = f + Min(count, v.size() - f); return JoinStrings(v.begin() + f, v.begin() + l, delim); -} +} diff --git a/util/string/vector.h b/util/string/vector.h index e36c348bbe..8322f349f1 100644 --- a/util/string/vector.h +++ b/util/string/vector.h @@ -119,14 +119,14 @@ inline TString JoinVectorIntoString(const TVector<T>& v, size_t index, size_t co TUtf16String JoinStrings(const TVector<TUtf16String>& v, const TWtringBuf delim); TUtf16String JoinStrings(const TVector<TUtf16String>& v, size_t index, size_t count, const TWtringBuf delim); - + //! Converts vector of strings to vector of type T variables template <typename T, typename TStringType> TVector<T> Scan(const TVector<TStringType>& input) { TVector<T> output; - output.reserve(input.size()); + output.reserve(input.size()); for (int i = 0; i < input.ysize(); ++i) { - output.push_back(FromString<T>(input[i])); - } - return output; -} + output.push_back(FromString<T>(input[i])); + } + return output; +} diff --git a/util/string/vector_ut.cpp b/util/string/vector_ut.cpp index 817120f268..49ed32497b 100644 --- a/util/string/vector_ut.cpp +++ b/util/string/vector_ut.cpp @@ -1,5 +1,5 @@ #include <library/cpp/testing/unittest/registar.h> -#include <util/charset/wide.h> +#include <util/charset/wide.h> #include "cast.h" #include "vector.h" @@ -28,11 +28,11 @@ Y_UNIT_TEST_SUITE(TStringJoinTest) { UNIT_ASSERT_EQUAL(JoinStrings(v, 1, 10, ToWtring(" ")), ToWtring("2")); } - + Y_UNIT_TEST(TestJoinWStrings) { const TUtf16String str = u"Яндекс"; const TVector<TUtf16String> v(1, str); - + UNIT_ASSERT_EQUAL(JoinStrings(v, TUtf16String()), str); - } + } } diff --git a/util/system/compat.h b/util/system/compat.h index c53dbcca17..67f1b2af27 100644 --- a/util/system/compat.h +++ b/util/system/compat.h @@ -28,7 +28,7 @@ extern "C" { #define SIGALRM 14 //will not receive under win? #endif -#if defined(__FreeBSD__) || defined(_darwin_) +#if defined(__FreeBSD__) || defined(_darwin_) #define HAVE_NATIVE_GETPROGNAME #endif diff --git a/util/system/compiler.h b/util/system/compiler.h index b373edcc46..de93b5240d 100644 --- a/util/system/compiler.h +++ b/util/system/compiler.h @@ -76,7 +76,7 @@ #define Y_DECLARE_UNUSED #endif -#if defined(__GNUC__) +#if defined(__GNUC__) #define Y_LIKELY(Cond) __builtin_expect(!!(Cond), 1) #define Y_UNLIKELY(Cond) __builtin_expect(!!(Cond), 0) #define Y_PREFETCH_READ(Pointer, Priority) __builtin_prefetch((const void*)(Pointer), 0, Priority) @@ -163,7 +163,7 @@ #define Y_PACKED #endif -#if defined(__GNUC__) +#if defined(__GNUC__) #define Y_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) #endif diff --git a/util/system/context.cpp b/util/system/context.cpp index ad99309088..b3ba4bf13d 100644 --- a/util/system/context.cpp +++ b/util/system/context.cpp @@ -217,7 +217,7 @@ void ContextTrampoLine(void* arg) { #endif #if defined(USE_FIBER_CONT) -TContMachineContext::TContMachineContext() +TContMachineContext::TContMachineContext() : Fiber_(ConvertThreadToFiber(this)) , MainFiber_(true) { diff --git a/util/system/daemon.cpp b/util/system/daemon.cpp index 130e6c8f45..f7c3106242 100644 --- a/util/system/daemon.cpp +++ b/util/system/daemon.cpp @@ -85,11 +85,11 @@ bool NDaemonMaker::MakeMeDaemon(ECloseDescriptors cd, EStdIoDescriptors iod, ECh return true; } - if (chd == chdirRoot) { + if (chd == chdirRoot) { if (chdir("/")) { - ythrow TSystemError() << "chdir(\"/\") failed"; + ythrow TSystemError() << "chdir(\"/\") failed"; } - } + } int fd[4] = {-1, -1, -1, -1}; switch (iod) { diff --git a/util/system/defaults.h b/util/system/defaults.h index dcd7abea38..b5b3b4569b 100644 --- a/util/system/defaults.h +++ b/util/system/defaults.h @@ -56,7 +56,7 @@ #define _must_align2_ #endif -#if defined(__GNUC__) +#if defined(__GNUC__) #define alias_hack __attribute__((__may_alias__)) #endif diff --git a/util/system/direct_io.cpp b/util/system/direct_io.cpp index f59c54b0cb..c6328127b8 100644 --- a/util/system/direct_io.cpp +++ b/util/system/direct_io.cpp @@ -87,7 +87,7 @@ void TDirectIOBufferedFile::SetDirectIO(bool value) { DirectIO = value; #else - DirectIO = value; + DirectIO = value; #endif } diff --git a/util/system/error.cpp b/util/system/error.cpp index f778ec42cb..a33c09badf 100644 --- a/util/system/error.cpp +++ b/util/system/error.cpp @@ -67,22 +67,22 @@ const char* LastSystemErrorText(int code) { #endif } -#ifdef _win_ -static char* Strip(char* s) { - size_t len = strlen(s); - const char* ptr = s; - Strip(ptr, len); - if (ptr != s) - memmove(s, ptr, len); - s[len] = 0; - return s; -} -#endif // _win_ - +#ifdef _win_ +static char* Strip(char* s) { + size_t len = strlen(s); + const char* ptr = s; + Strip(ptr, len); + if (ptr != s) + memmove(s, ptr, len); + s[len] = 0; + return s; +} +#endif // _win_ + void LastSystemErrorText(char* str, size_t size, int code) { #if defined(_win_) FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, code, 0, str, DWORD(size), 0); - Strip(str); + Strip(str); #elif defined(_sun_) strfcpy(str, strerror(code), size); #elif defined(_freebsd_) || defined(_darwin_) || defined(_musl_) || defined(_bionic_) diff --git a/util/system/file.cpp b/util/system/file.cpp index 4a261d020c..c971df64e2 100644 --- a/util/system/file.cpp +++ b/util/system/file.cpp @@ -86,10 +86,10 @@ TFileHandle::TFileHandle(const TString& fName, EOpenMode oMode) noexcept { case OpenAlways: fcMode = OPEN_ALWAYS; break; - case CreateNew: + case CreateNew: fcMode = CREATE_NEW; break; - case CreateAlways: + case CreateAlways: fcMode = CREATE_ALWAYS; break; default: @@ -152,10 +152,10 @@ TFileHandle::TFileHandle(const TString& fName, EOpenMode oMode) noexcept { case OpenAlways: fcMode = O_CREAT; break; - case CreateNew: + case CreateNew: fcMode = O_CREAT | O_EXCL; break; - case CreateAlways: + case CreateAlways: fcMode = O_CREAT | O_TRUNC; break; default: @@ -417,7 +417,7 @@ bool TFileHandle::Flush() noexcept { return false; } #if defined(_win_) - bool ok = ::FlushFileBuffers(Fd_) != 0; + bool ok = ::FlushFileBuffers(Fd_) != 0; /* * FlushFileBuffers fails if hFile is a handle to the console output. * That is because the console output is not buffered. diff --git a/util/system/file_ut.cpp b/util/system/file_ut.cpp index 941e6a50f3..d22f412b37 100644 --- a/util/system/file_ut.cpp +++ b/util/system/file_ut.cpp @@ -143,7 +143,7 @@ void TFileTest::TestOpen() { UNIT_ASSERT_VALUES_EQUAL(f1.GetLength(), 0); try { - TFile f2("f1.txt", CreateNew); + TFile f2("f1.txt", CreateNew); } catch (const yexception& e) { res = e.what(); } @@ -163,7 +163,7 @@ void TFileTest::TestOpenSync() { } void TFileTest::TestRW() { - TFile f1("f1.txt", CreateNew); + TFile f1("f1.txt", CreateNew); UNIT_ASSERT(f1.IsOpen()); UNIT_ASSERT_VALUES_EQUAL(f1.GetName(), "f1.txt"); UNIT_ASSERT_VALUES_EQUAL(f1.GetLength(), 0); diff --git a/util/system/filemap.cpp b/util/system/filemap.cpp index 7454a4cb94..41d6244e6d 100644 --- a/util/system/filemap.cpp +++ b/util/system/filemap.cpp @@ -34,7 +34,7 @@ #include <util/system/sanitizers.h> #include "filemap.h" -#undef PAGE_SIZE +#undef PAGE_SIZE #undef GRANULARITY #ifdef _win_ diff --git a/util/system/fs_win.h b/util/system/fs_win.h index 8086129828..b863c456ba 100644 --- a/util/system/fs_win.h +++ b/util/system/fs_win.h @@ -3,7 +3,7 @@ #include "winint.h" #include "defaults.h" -#include <util/generic/strbuf.h> +#include <util/generic/strbuf.h> #include <util/generic/string.h> namespace NFsPrivate { diff --git a/util/system/maxlen.h b/util/system/maxlen.h index e1ff7f5008..483c7a4fb5 100644 --- a/util/system/maxlen.h +++ b/util/system/maxlen.h @@ -1,7 +1,7 @@ #pragma once -#include <cstdlib> - +#include <cstdlib> + // http://support.microsoft.com/kb/208427 #ifndef URL_MAXLEN #define URL_MAXLEN 2083 diff --git a/util/system/shellcommand.cpp b/util/system/shellcommand.cpp index b1989b5c8c..f939953bf2 100644 --- a/util/system/shellcommand.cpp +++ b/util/system/shellcommand.cpp @@ -43,7 +43,7 @@ using TPid = HANDLE; using TWaitResult = DWORD; using TExitStatus = DWORD; #define WAIT_PROCEED WAIT_TIMEOUT - + #pragma warning(disable : 4296) // 'wait_result >= WAIT_OBJECT_0' : expression is always tru #else #error("unknown os, shell command is not implemented") @@ -618,7 +618,7 @@ void TShellCommand::TImpl::StartProcess(TShellCommand::TImpl::TPipes& pipes) { if (!res) { AtomicSet(ExecutionStatus, SHELL_ERROR); /// @todo: write to error stream if set - TStringOutput out(CollectedError); + TStringOutput out(CollectedError); out << "Process was not created: " << LastSystemErrorText() << " command text was: '" << GetAString(cmdcopy.Data()) << "'"; } Pid = process_info.hProcess; @@ -925,7 +925,7 @@ void TShellCommand::TImpl::Communicate(TProcessInfo* pi) { char* bufPos = nullptr; #endif TWaitResult waitPidResult; - TExitStatus status = 0; + TExitStatus status = 0; while (true) { { diff --git a/util/system/src_location.cpp b/util/system/src_location.cpp index 13ff1f24b3..def480add9 100644 --- a/util/system/src_location.cpp +++ b/util/system/src_location.cpp @@ -2,16 +2,16 @@ #include <util/stream/output.h> -#include <algorithm> - +#include <algorithm> + template <> void Out<TSourceLocation>(IOutputStream& o, const TSourceLocation& t) { -#if defined(_win_) +#if defined(_win_) TString file(t.File); - std::replace(file.begin(), file.vend(), '\\', '/'); - o << file; -#else - o << t.File; -#endif - o << ':' << t.Line; + std::replace(file.begin(), file.vend(), '\\', '/'); + o << file; +#else + o << t.File; +#endif + o << ':' << t.Line; } diff --git a/util/system/src_root_ut.cpp b/util/system/src_root_ut.cpp index e9a675eb9a..7b65a0a36d 100644 --- a/util/system/src_root_ut.cpp +++ b/util/system/src_root_ut.cpp @@ -1,11 +1,11 @@ #include "src_root.h" -#include <util/folder/pathsplit.h> +#include <util/folder/pathsplit.h> #include <library/cpp/testing/unittest/registar.h> Y_UNIT_TEST_SUITE(TestSourceRoot) { Y_UNIT_TEST(TestStrip) { - // Reconstruct() converts "\" -> "/" on Windows + // Reconstruct() converts "\" -> "/" on Windows const TString path = TPathSplit(__SOURCE_FILE_IMPL__.As<TStringBuf>()).Reconstruct(); UNIT_ASSERT_EQUAL(path, "util" LOCSLASH_S "system" LOCSLASH_S "src_root_ut.cpp"); } diff --git a/util/system/thread.cpp b/util/system/thread.cpp index 6236746c2d..d7615776b8 100644 --- a/util/system/thread.cpp +++ b/util/system/thread.cpp @@ -43,7 +43,7 @@ namespace { inline void SetThrName(const TParams& p) { try { - if (p.Name) { + if (p.Name) { TThread::SetCurrentThreadName(p.Name.data()); } } catch (...) { @@ -107,7 +107,7 @@ namespace { } static ui32 __stdcall Proxy(void* ptr) { - NTls::TCleaner cleaner; + NTls::TCleaner cleaner; (void)cleaner; @@ -313,7 +313,7 @@ void TThread::Detach() { } bool TThread::Running() const noexcept { - return Impl_ && Impl_->Running(); + return Impl_ && Impl_->Running(); } TThread::TId TThread::Id() const noexcept { diff --git a/util/system/types_ut.cpp b/util/system/types_ut.cpp index 19e40cef46..0ee71d6f03 100644 --- a/util/system/types_ut.cpp +++ b/util/system/types_ut.cpp @@ -1,23 +1,23 @@ -#include "types.h" - +#include "types.h" + #include <library/cpp/testing/unittest/registar.h> - + Y_UNIT_TEST_SUITE(TestTypes) { Y_UNIT_TEST(TestScanf) { - i32 val32 = 0; - sscanf("-123", "%" SCNi32, &val32); - UNIT_ASSERT(val32 == -123); - sscanf("234", "%" SCNu32, &val32); - UNIT_ASSERT(val32 == 234); - sscanf("159", "%" SCNx32, &val32); - UNIT_ASSERT(val32 == 345); - - i64 val64 = 0; - sscanf("-123", "%" SCNi64, &val64); - UNIT_ASSERT(val64 == -123); - sscanf("234", "%" SCNu64, &val64); - UNIT_ASSERT(val64 == 234); - sscanf("159", "%" SCNx64, &val64); - UNIT_ASSERT(val64 == 345); - } -} + i32 val32 = 0; + sscanf("-123", "%" SCNi32, &val32); + UNIT_ASSERT(val32 == -123); + sscanf("234", "%" SCNu32, &val32); + UNIT_ASSERT(val32 == 234); + sscanf("159", "%" SCNx32, &val32); + UNIT_ASSERT(val32 == 345); + + i64 val64 = 0; + sscanf("-123", "%" SCNi64, &val64); + UNIT_ASSERT(val64 == -123); + sscanf("234", "%" SCNu64, &val64); + UNIT_ASSERT(val64 == 234); + sscanf("159", "%" SCNx64, &val64); + UNIT_ASSERT(val64 == 345); + } +} diff --git a/util/system/ut/ya.make b/util/system/ut/ya.make index 127e7c261e..4871c632a8 100644 --- a/util/system/ut/ya.make +++ b/util/system/ut/ya.make @@ -70,7 +70,7 @@ SRCS( system/tempfile_ut.cpp system/thread_ut.cpp system/tls_ut.cpp - system/types_ut.cpp + system/types_ut.cpp system/type_name_ut.cpp system/user_ut.cpp system/unaligned_mem_ut.cpp diff --git a/util/system/yassert.cpp b/util/system/yassert.cpp index 0f586648b7..58a0bce2cf 100644 --- a/util/system/yassert.cpp +++ b/util/system/yassert.cpp @@ -67,13 +67,13 @@ namespace NPrivate { TString r; TStringOutput o(r); - if (expr) { + if (expr) { o << "VERIFY failed (" << now << "): " << errorMsg << Endl; } else { o << "FAIL (" << now << "): " << errorMsg << Endl; } o << " " << file << ":" << line << Endl; - if (expr) { + if (expr) { o << " " << function << "(): requirement " << expr << " failed" << Endl; } else { o << " " << function << "() failed" << Endl; diff --git a/util/ysafeptr.h b/util/ysafeptr.h index af7dfd4bed..94b08e9d6b 100644 --- a/util/ysafeptr.h +++ b/util/ysafeptr.h @@ -20,7 +20,7 @@ // for destruction of objects (because of 'delete this'). //////////////////////////////////////////////////////////////////////////////////////////////////// -#if defined(_MSC_VER) && defined(_DEBUG) +#if defined(_MSC_VER) && defined(_DEBUG) #include <util/system/winint.h> #define CHECK_YPTR2 #endif @@ -223,7 +223,7 @@ private: return dynamic_cast<classname*>(p); \ } \ Y_PRAGMA_DIAGNOSTIC_POP - + //////////////////////////////////////////////////////////////////////////////////////////////////// template <class TUserObj> IObjectBase* CastToObjectBaseImpl(TUserObj* p, void*); |