aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authordanlark <danlark@yandex-team.ru>2022-02-10 16:46:08 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:08 +0300
commit3426a9bc7f169ae9da54cef557ad2a33f6e8eee0 (patch)
tree26154e1e9990f1bb4525d3e3fb5b6dac2c2c1da2 /util
parentcb68f224c46a8ee52ac3fdd2a32534b8bb8dc134 (diff)
downloadydb-3426a9bc7f169ae9da54cef557ad2a33f6e8eee0.tar.gz
Restoring authorship annotation for <danlark@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util')
-rw-r--r--util/charset/utf8.cpp22
-rw-r--r--util/charset/utf8.h6
-rw-r--r--util/charset/utf8_ut.cpp8
-rw-r--r--util/datetime/cputimer.cpp6
-rw-r--r--util/datetime/parser.rl652
-rw-r--r--util/digest/fnv.h2
-rw-r--r--util/draft/date.cpp4
-rw-r--r--util/draft/datetime.h2
-rw-r--r--util/draft/enum.h6
-rw-r--r--util/draft/holder_vector.h2
-rw-r--r--util/draft/matrix.h2
-rw-r--r--util/draft/memory.h2
-rw-r--r--util/folder/dirut.cpp34
-rw-r--r--util/folder/dirut.h4
-rw-r--r--util/folder/filelist.cpp2
-rw-r--r--util/folder/filelist_ut.cpp18
-rw-r--r--util/folder/fts_ut.cpp38
-rw-r--r--util/folder/iterator_ut.cpp2
-rw-r--r--util/folder/path.cpp20
-rw-r--r--util/folder/path.h6
-rw-r--r--util/folder/pathsplit.cpp20
-rw-r--r--util/folder/pathsplit.h2
-rw-r--r--util/folder/tempdir.cpp2
-rw-r--r--util/generic/algorithm.h22
-rw-r--r--util/generic/algorithm_ut.cpp66
-rw-r--r--util/generic/bitops.h38
-rw-r--r--util/generic/bitops_ut.cpp16
-rw-r--r--util/generic/buffer.h24
-rw-r--r--util/generic/buffer_ut.cpp26
-rw-r--r--util/generic/function.h38
-rw-r--r--util/generic/guid.cpp4
-rw-r--r--util/generic/is_in_ut.cpp6
-rw-r--r--util/generic/iterator_range.h26
-rw-r--r--util/generic/iterator_range_ut.cpp36
-rw-r--r--util/generic/strbase.h2
-rw-r--r--util/generic/strbuf.h4
-rw-r--r--util/generic/strbuf_ut.cpp18
-rw-r--r--util/generic/string.cpp2
-rw-r--r--util/generic/string_ut.cpp18
-rw-r--r--util/generic/string_ut.h14
-rw-r--r--util/generic/vector_ut.cpp14
-rw-r--r--util/memory/blob.cpp2
-rw-r--r--util/memory/pool.h4
-rw-r--r--util/memory/segmented_string_pool.h4
-rw-r--r--util/network/ip.h4
-rw-r--r--util/network/socket.cpp4
-rw-r--r--util/network/socket_ut.cpp2
-rw-r--r--util/random/entropy.cpp2
-rw-r--r--util/random/normal_ut.cpp4
-rw-r--r--util/str_stl.h4
-rw-r--r--util/stream/buffer.cpp2
-rw-r--r--util/stream/buffer_ut.cpp6
-rw-r--r--util/stream/buffered_ut.cpp2
-rw-r--r--util/stream/format.h2
-rw-r--r--util/stream/hex_ut.cpp6
-rw-r--r--util/stream/input_ut.cpp2
-rw-r--r--util/stream/ios_ut.cpp20
-rw-r--r--util/stream/length_ut.cpp2
-rw-r--r--util/stream/mem.cpp4
-rw-r--r--util/stream/output.cpp2
-rw-r--r--util/stream/output.h6
-rw-r--r--util/stream/pipe.cpp2
-rw-r--r--util/stream/printf_ut.cpp2
-rw-r--r--util/stream/str.h4
-rw-r--r--util/stream/tokenizer_ut.cpp2
-rw-r--r--util/stream/zlib.cpp4
-rw-r--r--util/string/ascii_ut.cpp6
-rw-r--r--util/string/cast.h24
-rw-r--r--util/string/cast_ut.cpp8
-rw-r--r--util/string/escape.cpp16
-rw-r--r--util/string/escape.h2
-rw-r--r--util/string/escape_ut.cpp2
-rw-r--r--util/string/hex.h4
-rw-r--r--util/string/split.cpp2
-rw-r--r--util/string/split.h1068
-rw-r--r--util/string/split_ut.cpp1024
-rw-r--r--util/string/strip.cpp2
-rw-r--r--util/string/strip.h2
-rw-r--r--util/string/subst.cpp2
-rw-r--r--util/string/subst_ut.cpp14
-rw-r--r--util/string/type.h2
-rw-r--r--util/string/vector.cpp8
-rw-r--r--util/string/vector.h10
-rw-r--r--util/system/atexit.cpp2
-rw-r--r--util/system/compat.cpp2
-rw-r--r--util/system/dynlib.cpp6
-rw-r--r--util/system/dynlib.h4
-rw-r--r--util/system/env.cpp10
-rw-r--r--util/system/file.cpp2
-rw-r--r--util/system/filemap.h2
-rw-r--r--util/system/fs.cpp16
-rw-r--r--util/system/fs_ut.cpp4
-rw-r--r--util/system/fs_win.cpp6
-rw-r--r--util/system/fstat.cpp6
-rw-r--r--util/system/fstat_ut.cpp4
-rw-r--r--util/system/hi_lo.h2
-rw-r--r--util/system/hostname.cpp4
-rw-r--r--util/system/progname.cpp2
-rw-r--r--util/system/protect.cpp2
-rw-r--r--util/system/shellcommand.cpp22
-rw-r--r--util/system/shellcommand_ut.cpp16
-rw-r--r--util/system/shmat.cpp2
-rw-r--r--util/system/unaligned_mem.h8
-rw-r--r--util/system/unaligned_mem_ut.cpp16
-rw-r--r--util/ysaveload_ut.cpp10
105 files changed, 1539 insertions, 1539 deletions
diff --git a/util/charset/utf8.cpp b/util/charset/utf8.cpp
index efe3a52f61..a18a84dad1 100644
--- a/util/charset/utf8.cpp
+++ b/util/charset/utf8.cpp
@@ -55,19 +55,19 @@ namespace {
// before each iteration (including the first one) variable 'cNew' contains unwritten symbol
while (true) {
size_t cNewLen;
- Y_ASSERT((writePtr - newString.data()) + destSpace == newString.size());
+ Y_ASSERT((writePtr - newString.data()) + destSpace == newString.size());
if (RECODE_EOOUTPUT ==
SafeWriteUTF8Char(cNew, cNewLen, (unsigned char*)writePtr, destSpace)) {
- destSpace += newString.size();
- newString.resize(newString.size() * 2);
- writePtr = newString.begin() + (newString.size() - destSpace);
+ destSpace += newString.size();
+ newString.resize(newString.size() * 2);
+ writePtr = newString.begin() + (newString.size() - destSpace);
continue;
}
destSpace -= cNewLen;
writePtr += cNewLen;
p += cLen;
if (p == end) {
- newString.resize(newString.size() - destSpace);
+ newString.resize(newString.size() - destSpace);
return true;
}
wchar32 c = 0;
@@ -135,14 +135,14 @@ bool ToLowerUTF8Impl(const char* beg, size_t n, TString& newString) {
TString ToLowerUTF8(const TString& s) {
TString newString;
- bool changed = ToLowerUTF8Impl(s.data(), s.size(), newString);
+ bool changed = ToLowerUTF8Impl(s.data(), s.size(), newString);
return changed ? newString : s;
}
TString ToLowerUTF8(TStringBuf s) {
TString newString;
- bool changed = ToLowerUTF8Impl(s.data(), s.size(), newString);
- return changed ? newString : TString(s.data(), s.size());
+ bool changed = ToLowerUTF8Impl(s.data(), s.size(), newString);
+ return changed ? newString : TString(s.data(), s.size());
}
TString ToLowerUTF8(const char* s) {
@@ -155,14 +155,14 @@ bool ToUpperUTF8Impl(const char* beg, size_t n, TString& newString) {
TString ToUpperUTF8(const TString& s) {
TString newString;
- bool changed = ToUpperUTF8Impl(s.data(), s.size(), newString);
+ bool changed = ToUpperUTF8Impl(s.data(), s.size(), newString);
return changed ? newString : s;
}
TString ToUpperUTF8(TStringBuf s) {
TString newString;
- bool changed = ToUpperUTF8Impl(s.data(), s.size(), newString);
- return changed ? newString : TString(s.data(), s.size());
+ bool changed = ToUpperUTF8Impl(s.data(), s.size(), newString);
+ return changed ? newString : TString(s.data(), s.size());
}
TString ToUpperUTF8(const char* s) {
diff --git a/util/charset/utf8.h b/util/charset/utf8.h
index 5039b46ae9..c4708be9be 100644
--- a/util/charset/utf8.h
+++ b/util/charset/utf8.h
@@ -133,7 +133,7 @@ inline bool GetNumberOfUTF8Chars(const char* text, size_t len, size_t& number) {
inline size_t GetNumberOfUTF8Chars(TStringBuf text) {
size_t number;
- if (!GetNumberOfUTF8Chars(text.data(), text.size(), number)) {
+ if (!GetNumberOfUTF8Chars(text.data(), text.size(), number)) {
ythrow yexception() << "GetNumberOfUTF8Chars failed on invalid utf-8 " << TString(text.substr(0, 50)).Quote();
}
return number;
@@ -356,7 +356,7 @@ enum EUTF8Detect {
EUTF8Detect UTF8Detect(const char* s, size_t len);
inline EUTF8Detect UTF8Detect(const TStringBuf input) {
- return UTF8Detect(input.data(), input.size());
+ return UTF8Detect(input.data(), input.size());
}
inline bool IsUtf(const char* input, size_t len) {
@@ -364,7 +364,7 @@ inline bool IsUtf(const char* input, size_t len) {
}
inline bool IsUtf(const TStringBuf input) {
- return IsUtf(input.data(), input.size());
+ return IsUtf(input.data(), input.size());
}
//! returns true, if result is not the same as input, and put it in newString
diff --git a/util/charset/utf8_ut.cpp b/util/charset/utf8_ut.cpp
index 9e68881cca..8f8e6996c5 100644
--- a/util/charset/utf8_ut.cpp
+++ b/util/charset/utf8_ut.cpp
@@ -21,8 +21,8 @@ Y_UNIT_TEST_SUITE(TUtfUtilTest) {
TString s = "привет!";
TString q = "ПРИВЕТ!";
TString tmp;
- UNIT_ASSERT(ToLowerUTF8Impl(s.data(), s.size(), tmp) == false);
- UNIT_ASSERT(ToLowerUTF8Impl(q.data(), q.size(), tmp) == true);
+ UNIT_ASSERT(ToLowerUTF8Impl(s.data(), s.size(), tmp) == false);
+ UNIT_ASSERT(ToLowerUTF8Impl(q.data(), q.size(), tmp) == true);
}
{
@@ -61,8 +61,8 @@ Y_UNIT_TEST_SUITE(TUtfUtilTest) {
TString s = "ПРИВЕТ!";
TString q = "привет!";
TString tmp;
- UNIT_ASSERT(ToUpperUTF8Impl(s.data(), s.size(), tmp) == false);
- UNIT_ASSERT(ToUpperUTF8Impl(q.data(), q.size(), tmp) == true);
+ UNIT_ASSERT(ToUpperUTF8Impl(s.data(), s.size(), tmp) == false);
+ UNIT_ASSERT(ToUpperUTF8Impl(q.data(), q.size(), tmp) == true);
}
{
diff --git a/util/datetime/cputimer.cpp b/util/datetime/cputimer.cpp
index 516d372c37..b8434b419f 100644
--- a/util/datetime/cputimer.cpp
+++ b/util/datetime/cputimer.cpp
@@ -111,7 +111,7 @@ TTimeLogger::TTimeLogger(const TString& message, bool verbose)
{
if (Verbose) {
fprintf(stderr, "=========================================================\n");
- fprintf(stderr, "%s started: %.24s (%lu) (%d)\n", Message.data(), ctime(&Begin), (unsigned long)Begin, (int)getpid());
+ fprintf(stderr, "%s started: %.24s (%lu) (%d)\n", Message.data(), ctime(&Begin), (unsigned long)Begin, (int)getpid());
}
}
@@ -129,8 +129,8 @@ TTimeLogger::~TTimeLogger() {
if (Verbose) {
const char* prefix = (OK) ? "" : "!";
fprintf(stderr, "%s%s ended: %.24s (%lu) (%d) (took %lus = %s)\n",
- prefix, Message.data(), ctime(&tim), (unsigned long)tim, (int)getpid(),
- (unsigned long)tim - (unsigned long)Begin, FormatCycles(endCycles - BeginCycles).data());
+ prefix, Message.data(), ctime(&tim), (unsigned long)tim, (int)getpid(),
+ (unsigned long)tim - (unsigned long)Begin, FormatCycles(endCycles - BeginCycles).data());
fprintf(stderr, "%s=========================================================\n", prefix);
}
}
diff --git a/util/datetime/parser.rl6 b/util/datetime/parser.rl6
index 931f09eae1..cb6ec3bcfa 100644
--- a/util/datetime/parser.rl6
+++ b/util/datetime/parser.rl6
@@ -461,30 +461,30 @@ static inline TResult ParseUnsafe(const char* input, size_t len) {
}
TInstant TInstant::ParseIso8601Deprecated(const TStringBuf input) {
- return ParseUnsafe<TIso8601DateTimeParserDeprecated, TInstant>(input.data(), input.size());
+ return ParseUnsafe<TIso8601DateTimeParserDeprecated, TInstant>(input.data(), input.size());
}
TInstant TInstant::ParseRfc822Deprecated(const TStringBuf input) {
- return ParseUnsafe<TRfc822DateTimeParserDeprecated, TInstant>(input.data(), input.size());
+ return ParseUnsafe<TRfc822DateTimeParserDeprecated, TInstant>(input.data(), input.size());
}
TInstant TInstant::ParseHttpDeprecated(const TStringBuf input) {
- return ParseUnsafe<THttpDateTimeParserDeprecated, TInstant>(input.data(), input.size());
+ return ParseUnsafe<THttpDateTimeParserDeprecated, TInstant>(input.data(), input.size());
}
TInstant TInstant::ParseX509ValidityDeprecated(const TStringBuf input) {
- switch (input.size()) {
+ switch (input.size()) {
case 13:
- return ParseUnsafe<TX509ValidityDateTimeParserDeprecated, TInstant>(input.data(), 13);
+ return ParseUnsafe<TX509ValidityDateTimeParserDeprecated, TInstant>(input.data(), 13);
case 15:
- return ParseUnsafe<TX509Validity4yDateTimeParserDeprecated, TInstant>(input.data(), 15);
+ return ParseUnsafe<TX509Validity4yDateTimeParserDeprecated, TInstant>(input.data(), 15);
default:
ythrow TDateTimeParseException();
}
}
bool TInstant::TryParseIso8601Deprecated(const TStringBuf input, TInstant& instant) {
- const auto parsed = ParseUnsafe<TIso8601DateTimeParserDeprecated, TInstant, false>(input.data(), input.size());
+ const auto parsed = ParseUnsafe<TIso8601DateTimeParserDeprecated, TInstant, false>(input.data(), input.size());
if (TInstant::Max() == parsed) {
return false;
}
@@ -493,7 +493,7 @@ bool TInstant::TryParseIso8601Deprecated(const TStringBuf input, TInstant& insta
}
bool TInstant::TryParseRfc822Deprecated(const TStringBuf input, TInstant& instant) {
- const auto parsed = ParseUnsafe<TRfc822DateTimeParserDeprecated, TInstant, false>(input.data(), input.size());
+ const auto parsed = ParseUnsafe<TRfc822DateTimeParserDeprecated, TInstant, false>(input.data(), input.size());
if (TInstant::Max() == parsed) {
return false;
}
@@ -502,7 +502,7 @@ bool TInstant::TryParseRfc822Deprecated(const TStringBuf input, TInstant& instan
}
bool TInstant::TryParseHttpDeprecated(const TStringBuf input, TInstant& instant) {
- const auto parsed = ParseUnsafe<THttpDateTimeParserDeprecated, TInstant, false>(input.data(), input.size());
+ const auto parsed = ParseUnsafe<THttpDateTimeParserDeprecated, TInstant, false>(input.data(), input.size());
if (TInstant::Max() == parsed) {
return false;
}
@@ -512,12 +512,12 @@ bool TInstant::TryParseHttpDeprecated(const TStringBuf input, TInstant& instant)
bool TInstant::TryParseX509Deprecated(const TStringBuf input, TInstant& instant) {
TInstant parsed;
- switch (input.size()) {
+ switch (input.size()) {
case 13:
- parsed = ParseUnsafe<TX509ValidityDateTimeParserDeprecated, TInstant, false>(input.data(), 13);
+ parsed = ParseUnsafe<TX509ValidityDateTimeParserDeprecated, TInstant, false>(input.data(), 13);
break;
case 15:
- parsed = ParseUnsafe<TX509Validity4yDateTimeParserDeprecated, TInstant, false>(input.data(), 15);
+ parsed = ParseUnsafe<TX509Validity4yDateTimeParserDeprecated, TInstant, false>(input.data(), 15);
break;
default:
return false;
@@ -530,30 +530,30 @@ bool TInstant::TryParseX509Deprecated(const TStringBuf input, TInstant& instant)
}
TInstant TInstant::ParseIso8601(const TStringBuf input) {
- return ParseUnsafe<TIso8601DateTimeParser, TInstant>(input.data(), input.size());
+ return ParseUnsafe<TIso8601DateTimeParser, TInstant>(input.data(), input.size());
}
TInstant TInstant::ParseRfc822(const TStringBuf input) {
- return ParseUnsafe<TRfc822DateTimeParser, TInstant>(input.data(), input.size());
+ return ParseUnsafe<TRfc822DateTimeParser, TInstant>(input.data(), input.size());
}
TInstant TInstant::ParseHttp(const TStringBuf input) {
- return ParseUnsafe<THttpDateTimeParser, TInstant>(input.data(), input.size());
+ return ParseUnsafe<THttpDateTimeParser, TInstant>(input.data(), input.size());
}
TInstant TInstant::ParseX509Validity(const TStringBuf input) {
- switch (input.size()) {
+ switch (input.size()) {
case 13:
- return ParseUnsafe<TX509ValidityDateTimeParser, TInstant>(input.data(), 13);
+ return ParseUnsafe<TX509ValidityDateTimeParser, TInstant>(input.data(), 13);
case 15:
- return ParseUnsafe<TX509Validity4yDateTimeParser, TInstant>(input.data(), 15);
+ return ParseUnsafe<TX509Validity4yDateTimeParser, TInstant>(input.data(), 15);
default:
ythrow TDateTimeParseException();
}
}
bool TInstant::TryParseIso8601(const TStringBuf input, TInstant& instant) {
- const auto parsed = ParseUnsafe<TIso8601DateTimeParser, TInstant, false>(input.data(), input.size());
+ const auto parsed = ParseUnsafe<TIso8601DateTimeParser, TInstant, false>(input.data(), input.size());
if (TInstant::Max() == parsed) {
return false;
}
@@ -562,7 +562,7 @@ bool TInstant::TryParseIso8601(const TStringBuf input, TInstant& instant) {
}
bool TInstant::TryParseRfc822(const TStringBuf input, TInstant& instant) {
- const auto parsed = ParseUnsafe<TRfc822DateTimeParser, TInstant, false>(input.data(), input.size());
+ const auto parsed = ParseUnsafe<TRfc822DateTimeParser, TInstant, false>(input.data(), input.size());
if (TInstant::Max() == parsed) {
return false;
}
@@ -571,7 +571,7 @@ bool TInstant::TryParseRfc822(const TStringBuf input, TInstant& instant) {
}
bool TInstant::TryParseHttp(const TStringBuf input, TInstant& instant) {
- const auto parsed = ParseUnsafe<THttpDateTimeParser, TInstant, false>(input.data(), input.size());
+ const auto parsed = ParseUnsafe<THttpDateTimeParser, TInstant, false>(input.data(), input.size());
if (TInstant::Max() == parsed) {
return false;
}
@@ -581,12 +581,12 @@ bool TInstant::TryParseHttp(const TStringBuf input, TInstant& instant) {
bool TInstant::TryParseX509(const TStringBuf input, TInstant& instant) {
TInstant parsed;
- switch (input.size()) {
+ switch (input.size()) {
case 13:
- parsed = ParseUnsafe<TX509ValidityDateTimeParser, TInstant, false>(input.data(), 13);
+ parsed = ParseUnsafe<TX509ValidityDateTimeParser, TInstant, false>(input.data(), 13);
break;
case 15:
- parsed = ParseUnsafe<TX509Validity4yDateTimeParser, TInstant, false>(input.data(), 15);
+ parsed = ParseUnsafe<TX509Validity4yDateTimeParser, TInstant, false>(input.data(), 15);
break;
default:
return false;
@@ -789,7 +789,7 @@ TDuration TDurationParser::GetResult(TDuration defaultValue) const {
}
bool TDuration::TryParse(const TStringBuf input, TDuration& result) {
- TDuration r = ::Parse<TDurationParser, TDuration>(input.data(), input.size(), TDuration::Max());
+ TDuration r = ::Parse<TDurationParser, TDuration>(input.data(), input.size(), TDuration::Max());
if (r == TDuration::Max())
return false;
result = r;
@@ -797,5 +797,5 @@ bool TDuration::TryParse(const TStringBuf input, TDuration& result) {
}
TDuration TDuration::Parse(const TStringBuf input) {
- return ParseUnsafe<TDurationParser, TDuration>(input.data(), input.size());
+ return ParseUnsafe<TDurationParser, TDuration>(input.data(), input.size());
}
diff --git a/util/digest/fnv.h b/util/digest/fnv.h
index 87b41a3de7..8773246ee0 100644
--- a/util/digest/fnv.h
+++ b/util/digest/fnv.h
@@ -69,5 +69,5 @@ static constexpr T FnvHash(const void* buf, size_t len) {
template <class T, class Buf>
static constexpr T FnvHash(const Buf& buf) {
- return FnvHash<T>(buf.data(), buf.size() * sizeof(*buf.data()));
+ return FnvHash<T>(buf.data(), buf.size() * sizeof(*buf.data()));
}
diff --git a/util/draft/date.cpp b/util/draft/date.cpp
index a290c46050..e06926bfc2 100644
--- a/util/draft/date.cpp
+++ b/util/draft/date.cpp
@@ -36,7 +36,7 @@ static time_t ParseDate(const char* dateStr) {
template <>
TDate FromStringImpl<TDate>(const char* data, size_t len) {
- return TDate(ParseDate(TString(data, len).data()));
+ return TDate(ParseDate(TString(data, len).data()));
}
TDate::TDate(const char* yyyymmdd)
@@ -55,7 +55,7 @@ TDate::TDate(time_t ts)
}
TDate::TDate(const TString& date, const TString& format)
- : Timestamp(GetDateStart(ParseDate(date.data(), format.data())))
+ : Timestamp(GetDateStart(ParseDate(date.data(), format.data())))
{
}
diff --git a/util/draft/datetime.h b/util/draft/datetime.h
index 8a387ea6f1..912d63fe1e 100644
--- a/util/draft/datetime.h
+++ b/util/draft/datetime.h
@@ -145,7 +145,7 @@ inline TString date2str(const time_t date) {
inline time_t str2date(const TString& dateStr) {
struct tm dateTm;
memset(&dateTm, 0, sizeof(tm));
- strptime(dateStr.data(), "%Y%m%d", &dateTm);
+ strptime(dateStr.data(), "%Y%m%d", &dateTm);
return mktime(&dateTm);
}
diff --git a/util/draft/enum.h b/util/draft/enum.h
index 18002b7df2..efea2c93a4 100644
--- a/util/draft/enum.h
+++ b/util/draft/enum.h
@@ -5,7 +5,7 @@
#include <util/generic/strbuf.h>
#include <util/stream/str.h>
#include <util/string/cast.h>
-#include <util/string/split.h>
+#include <util/string/split.h>
#include <utility>
class TEnumNotFoundException: public yexception {
@@ -98,7 +98,7 @@ inline void SetEnumFlags(const std::pair<const char*, E> (&str2Enum)[N], TString
} else {
flags.reset();
for (const auto& it : StringSplitter(optSpec).Split(',')) {
- E e = *EnumFromStringImpl(ToString(it.Token()).data(), str2Enum, N);
+ E e = *EnumFromStringImpl(ToString(it.Token()).data(), str2Enum, N);
flags.set(e);
}
}
@@ -113,7 +113,7 @@ inline void SetEnumFlags(const std::pair<const char*, E>* str2Enum, TStringBuf o
} else {
flags.reset();
for (const auto& it : StringSplitter(optSpec).Split(',')) {
- E e = *EnumFromStringImpl(ToString(it.Token()).data(), str2Enum, size);
+ E e = *EnumFromStringImpl(ToString(it.Token()).data(), str2Enum, size);
flags.set(e);
}
}
diff --git a/util/draft/holder_vector.h b/util/draft/holder_vector.h
index 1c62055bd9..0ca1d044d8 100644
--- a/util/draft/holder_vector.h
+++ b/util/draft/holder_vector.h
@@ -5,7 +5,7 @@
#include <util/generic/noncopyable.h>
template <class T, class D = TDelete>
-class THolderVector: public TVector<T*>, public TNonCopyable {
+class THolderVector: public TVector<T*>, public TNonCopyable {
using TBase = TVector<T*>;
public:
diff --git a/util/draft/matrix.h b/util/draft/matrix.h
index 154d00b35e..d4087c76df 100644
--- a/util/draft/matrix.h
+++ b/util/draft/matrix.h
@@ -1,6 +1,6 @@
#pragma once
-#include <util/generic/noncopyable.h>
+#include <util/generic/noncopyable.h>
#include <util/system/yassert.h>
#include <util/system/defaults.h>
#include <string.h>
diff --git a/util/draft/memory.h b/util/draft/memory.h
index 0a9722bb36..51edf683cf 100644
--- a/util/draft/memory.h
+++ b/util/draft/memory.h
@@ -8,7 +8,7 @@
template <class T>
inline bool IsZero(const T* begin, const T* end) {
- return std::find_if(begin, end, [](const T& other) { return other != T(0); }) == end;
+ return std::find_if(begin, end, [](const T& other) { return other != T(0); }) == end;
}
template <size_t Size>
diff --git a/util/folder/dirut.cpp b/util/folder/dirut.cpp
index ffc9b09f96..57bc56003f 100644
--- a/util/folder/dirut.cpp
+++ b/util/folder/dirut.cpp
@@ -19,7 +19,7 @@ void SlashFolderLocal(TString& folder) {
while ((pos = folder.find('/')) != TString::npos)
folder.replace(pos, 1, LOCSLASH_S);
#endif
- if (folder[folder.size() - 1] != LOCSLASH_C)
+ if (folder[folder.size() - 1] != LOCSLASH_C)
folder.append(LOCSLASH_S);
}
@@ -41,10 +41,10 @@ bool resolvepath(TString& folder, const TString& home) {
if (folder.at(0) == '~') {
if (folder.length() == 1 || folder.at(1) == '/') {
- folder = GetHomeDir() + (folder.data() + 1);
+ folder = GetHomeDir() + (folder.data() + 1);
} else {
char* buf = (char*)alloca(folder.length() + 1);
- strcpy(buf, folder.data() + 1);
+ strcpy(buf, folder.data() + 1);
char* p = strchr(buf, '/');
if (p)
*p++ = 0;
@@ -62,10 +62,10 @@ bool resolvepath(TString& folder, const TString& home) {
int len = folder.length() + home.length() + 1;
char* path = (char*)alloca(len);
if (folder.at(0) != '/') {
- strcpy(path, home.data());
- strcpy(strrchr(path, '/') + 1, folder.data()); // the last char must be '/' if it's a dir
+ strcpy(path, home.data());
+ strcpy(strrchr(path, '/') + 1, folder.data()); // the last char must be '/' if it's a dir
} else {
- strcpy(path, folder.data());
+ strcpy(path, folder.data());
}
len = strlen(path) + 1;
// grabbed from url.cpp
@@ -349,8 +349,8 @@ int resolvepath(char* apath, const char* rpath, const char* cpath) {
}
bool correctpath(TString& filename) {
- char* ptr = (char*)alloca(filename.size() + 2);
- if (correctpath(ptr, filename.data())) {
+ char* ptr = (char*)alloca(filename.size() + 2);
+ if (correctpath(ptr, filename.data())) {
filename = ptr;
return true;
}
@@ -358,8 +358,8 @@ bool correctpath(TString& filename) {
}
bool resolvepath(TString& folder, const TString& home) {
- char* ptr = (char*)alloca(folder.size() + 3 + home.size());
- if (resolvepath(ptr, folder.data(), home.data())) {
+ char* ptr = (char*)alloca(folder.size() + 3 + home.size());
+ if (resolvepath(ptr, folder.data(), home.data())) {
folder = ptr;
return true;
}
@@ -406,9 +406,9 @@ TString RealPath(const TString& path) {
TTempBuf result;
Y_ASSERT(result.Size() > MAX_PATH); //TMP_BUF_LEN > MAX_PATH
#ifdef _win_
- if (GetFullPathName(path.data(), result.Size(), result.Data(), nullptr) == 0)
+ if (GetFullPathName(path.data(), result.Size(), result.Data(), nullptr) == 0)
#else
- if (realpath(path.data(), result.Data()) == nullptr)
+ if (realpath(path.data(), result.Data()) == nullptr)
#endif
ythrow TFileError() << "RealPath failed \"" << path << "\"";
return result.Data();
@@ -419,7 +419,7 @@ TString RealLocation(const TString& path) {
return RealPath(path);
TString dirpath = GetDirName(path);
if (NFs::Exists(dirpath))
- return RealPath(dirpath) + GetDirectorySeparatorS() + GetFileNameComponent(path.data());
+ return RealPath(dirpath) + GetDirectorySeparatorS() + GetFileNameComponent(path.data());
ythrow TFileError() << "RealLocation failed \"" << path << "\"";
}
@@ -434,7 +434,7 @@ int MakeTempDir(char path[/*FILENAME_MAX*/], const char* prefix) {
if (!prefix) {
#endif
sysTmp = GetSystemTempDir();
- prefix = sysTmp.data();
+ prefix = sysTmp.data();
}
if ((ret = ResolvePath(prefix, nullptr, path, 1)) != 0)
@@ -460,7 +460,7 @@ TString GetHomeDir() {
passwd* pw = nullptr;
s = getenv("USER");
if (s)
- pw = getpwnam(s.data());
+ pw = getpwnam(s.data());
else
pw = getpwuid(getuid());
if (pw)
@@ -580,13 +580,13 @@ int ResolvePath(const char* rel, const char* abs, char res[/*MAXPATHLEN*/], bool
t[len] = 0;
}
if (!realpath(t, res)) {
- if (!isdir && realpath(GetDirName(t).data(), res)) {
+ if (!isdir && realpath(GetDirName(t).data(), res)) {
len = strlen(res);
if (res[len - 1] != LOCSLASH_C) {
res[len++] = LOCSLASH_C;
res[len] = 0;
}
- strcpy(res + len, GetBaseName(t).data());
+ strcpy(res + len, GetBaseName(t).data());
return 0;
}
return errno ? errno : ENOENT;
diff --git a/util/folder/dirut.h b/util/folder/dirut.h
index 2537027b12..c707838d81 100644
--- a/util/folder/dirut.h
+++ b/util/folder/dirut.h
@@ -46,7 +46,7 @@ TString GetHomeDir();
void MakeDirIfNotExist(const char* path, int mode = 0777);
inline void MakeDirIfNotExist(const TString& path, int mode = 0777) {
- MakeDirIfNotExist(path.data(), mode);
+ MakeDirIfNotExist(path.data(), mode);
}
/// Create path making parent directories as needed
@@ -64,7 +64,7 @@ void RemoveDirWithContents(TString dirName);
const char* GetFileNameComponent(const char* f);
inline TString GetFileNameComponent(const TString& f) {
- return GetFileNameComponent(f.data());
+ return GetFileNameComponent(f.data());
}
/// RealPath doesn't guarantee trailing separator to be stripped or left in place for directories.
diff --git a/util/folder/filelist.cpp b/util/folder/filelist.cpp
index b21fcdbf20..9e33b567e7 100644
--- a/util/folder/filelist.cpp
+++ b/util/folder/filelist.cpp
@@ -32,7 +32,7 @@ void TFileEntitiesList::Fill(const TString& dirname, TStringBuf prefix, TStringB
if (((Mask & EM_FILES) && file->fts_info == FTS_F) || ((Mask & EM_DIRS) && file->fts_info == FTS_D) || ((Mask & EM_SLINKS) && file->fts_info == FTS_SL)) {
++FileNamesSize;
- FileNames.Append(filename.data(), filename.size() + 1);
+ FileNames.Append(filename.data(), filename.size() + 1);
}
}
diff --git a/util/folder/filelist_ut.cpp b/util/folder/filelist_ut.cpp
index 0cdcdf3d00..f06a5ba332 100644
--- a/util/folder/filelist_ut.cpp
+++ b/util/folder/filelist_ut.cpp
@@ -20,11 +20,11 @@ public:
void TFileListTest::TestSimple() {
TTempDir tempDir("nonexistingdir");
- MakeDirIfNotExist((tempDir() + LOCSLASH_S "subdir").data());
- TFile((tempDir() + LOCSLASH_S "subdir" LOCSLASH_S "file").data(), CreateAlways);
+ MakeDirIfNotExist((tempDir() + LOCSLASH_S "subdir").data());
+ TFile((tempDir() + LOCSLASH_S "subdir" LOCSLASH_S "file").data(), CreateAlways);
TFileList fileList;
- fileList.Fill(tempDir().data(), "", "", 1000);
+ fileList.Fill(tempDir().data(), "", "", 1000);
TString fileName(fileList.Next());
UNIT_ASSERT_EQUAL(fileName, "subdir" LOCSLASH_S "file");
UNIT_ASSERT_EQUAL(fileList.Next(), nullptr);
@@ -32,21 +32,21 @@ void TFileListTest::TestSimple() {
void TFileListTest::TestPrefix() {
TTempDir tempDir("nonexistingdir");
- TFile((tempDir() + LOCSLASH_S "good_file1").data(), CreateAlways);
- TFile((tempDir() + LOCSLASH_S "good_file2").data(), CreateAlways);
- TFile((tempDir() + LOCSLASH_S "bad_file1").data(), CreateAlways);
- TFile((tempDir() + LOCSLASH_S "bad_file2").data(), CreateAlways);
+ TFile((tempDir() + LOCSLASH_S "good_file1").data(), CreateAlways);
+ TFile((tempDir() + LOCSLASH_S "good_file2").data(), CreateAlways);
+ TFile((tempDir() + LOCSLASH_S "bad_file1").data(), CreateAlways);
+ TFile((tempDir() + LOCSLASH_S "bad_file2").data(), CreateAlways);
const bool SORT = true;
TFileList fileList;
{
- fileList.Fill(tempDir().data(), "good_file", SORT);
+ fileList.Fill(tempDir().data(), "good_file", SORT);
UNIT_ASSERT_EQUAL(TString(fileList.Next()), "good_file1");
UNIT_ASSERT_EQUAL(TString(fileList.Next()), "good_file2");
UNIT_ASSERT_EQUAL(fileList.Next(), nullptr);
}
{
- fileList.Fill(tempDir().data(), "bad_file", SORT);
+ fileList.Fill(tempDir().data(), "bad_file", SORT);
UNIT_ASSERT_EQUAL(TString(fileList.Next()), "bad_file1");
UNIT_ASSERT_EQUAL(TString(fileList.Next()), "bad_file2");
UNIT_ASSERT_EQUAL(fileList.Next(), nullptr);
diff --git a/util/folder/fts_ut.cpp b/util/folder/fts_ut.cpp
index c5d59e35f4..02622aff4e 100644
--- a/util/folder/fts_ut.cpp
+++ b/util/folder/fts_ut.cpp
@@ -58,27 +58,27 @@ void TFtsTest::TestSimple() {
TFileTree currentDirTree((char* const*)dotPath, 0, FtsCmp);
UNIT_ASSERT(currentDirTree());
TTempDir tempDir = MakeTempName(yfts_read(currentDirTree())->fts_path);
- MakeDirIfNotExist(tempDir().data());
- MakeDirIfNotExist((tempDir() + LOCSLASH_S "dir1").data());
- MakeFile((tempDir() + LOCSLASH_S "dir1" LOCSLASH_S "file1").data());
- MakeFile((tempDir() + LOCSLASH_S "dir1" LOCSLASH_S "file2").data());
- MakeDirIfNotExist((tempDir() + LOCSLASH_S "dir2").data());
- MakeFile((tempDir() + LOCSLASH_S "dir2" LOCSLASH_S "file3").data());
- MakeFile((tempDir() + LOCSLASH_S "dir2" LOCSLASH_S "file4").data());
-
- const char* path[2] = {tempDir().data(), nullptr};
+ MakeDirIfNotExist(tempDir().data());
+ MakeDirIfNotExist((tempDir() + LOCSLASH_S "dir1").data());
+ MakeFile((tempDir() + LOCSLASH_S "dir1" LOCSLASH_S "file1").data());
+ MakeFile((tempDir() + LOCSLASH_S "dir1" LOCSLASH_S "file2").data());
+ MakeDirIfNotExist((tempDir() + LOCSLASH_S "dir2").data());
+ MakeFile((tempDir() + LOCSLASH_S "dir2" LOCSLASH_S "file3").data());
+ MakeFile((tempDir() + LOCSLASH_S "dir2" LOCSLASH_S "file4").data());
+
+ const char* path[2] = {tempDir().data(), nullptr};
TFileTree fileTree((char* const*)path, 0, FtsCmp);
UNIT_ASSERT(fileTree());
- CheckEnt(yfts_read(fileTree()), tempDir().data(), FTS_D);
- CheckEnt(yfts_read(fileTree()), (tempDir() + LOCSLASH_S "dir1").data(), FTS_D);
- CheckEnt(yfts_read(fileTree()), (tempDir() + LOCSLASH_S "dir1" LOCSLASH_S "file1").data(), FTS_F);
- CheckEnt(yfts_read(fileTree()), (tempDir() + LOCSLASH_S "dir1" LOCSLASH_S "file2").data(), FTS_F);
- CheckEnt(yfts_read(fileTree()), (tempDir() + LOCSLASH_S "dir1").data(), FTS_DP);
- CheckEnt(yfts_read(fileTree()), (tempDir() + LOCSLASH_S "dir2").data(), FTS_D);
- CheckEnt(yfts_read(fileTree()), (tempDir() + LOCSLASH_S "dir2" LOCSLASH_S "file3").data(), FTS_F);
- CheckEnt(yfts_read(fileTree()), (tempDir() + LOCSLASH_S "dir2" LOCSLASH_S "file4").data(), FTS_F);
- CheckEnt(yfts_read(fileTree()), (tempDir() + LOCSLASH_S "dir2").data(), FTS_DP);
- CheckEnt(yfts_read(fileTree()), (tempDir()).data(), FTS_DP);
+ CheckEnt(yfts_read(fileTree()), tempDir().data(), FTS_D);
+ CheckEnt(yfts_read(fileTree()), (tempDir() + LOCSLASH_S "dir1").data(), FTS_D);
+ CheckEnt(yfts_read(fileTree()), (tempDir() + LOCSLASH_S "dir1" LOCSLASH_S "file1").data(), FTS_F);
+ CheckEnt(yfts_read(fileTree()), (tempDir() + LOCSLASH_S "dir1" LOCSLASH_S "file2").data(), FTS_F);
+ CheckEnt(yfts_read(fileTree()), (tempDir() + LOCSLASH_S "dir1").data(), FTS_DP);
+ CheckEnt(yfts_read(fileTree()), (tempDir() + LOCSLASH_S "dir2").data(), FTS_D);
+ CheckEnt(yfts_read(fileTree()), (tempDir() + LOCSLASH_S "dir2" LOCSLASH_S "file3").data(), FTS_F);
+ CheckEnt(yfts_read(fileTree()), (tempDir() + LOCSLASH_S "dir2" LOCSLASH_S "file4").data(), FTS_F);
+ CheckEnt(yfts_read(fileTree()), (tempDir() + LOCSLASH_S "dir2").data(), FTS_DP);
+ CheckEnt(yfts_read(fileTree()), (tempDir()).data(), FTS_DP);
UNIT_ASSERT_EQUAL(yfts_read(fileTree()), nullptr);
}
diff --git a/util/folder/iterator_ut.cpp b/util/folder/iterator_ut.cpp
index 936becd139..c6c756b999 100644
--- a/util/folder/iterator_ut.cpp
+++ b/util/folder/iterator_ut.cpp
@@ -56,7 +56,7 @@ private:
break;
case 1:
- MakeDirIfNotExist(path.Path.data());
+ MakeDirIfNotExist(path.Path.data());
break;
case 2:
diff --git a/util/folder/path.cpp b/util/folder/path.cpp
index bfe0c67d68..0d5400fd14 100644
--- a/util/folder/path.cpp
+++ b/util/folder/path.cpp
@@ -93,11 +93,11 @@ TFsPath TFsPath::RelativePath(const TFsPath& root) const {
for (size_t i = 0; i < rsplit.size() - cnt; i++) {
r += i == 0 ? ".." : "/..";
}
- for (size_t i = cnt; i < split.size(); i++) {
- r += (i == 0 || i == cnt && rsplit.size() - cnt == 0 ? "" : "/");
+ for (size_t i = cnt; i < split.size(); i++) {
+ r += (i == 0 || i == cnt && rsplit.size() - cnt == 0 ? "" : "/");
r += split[i];
}
- return r.size() ? TFsPath(r) : TFsPath();
+ return r.size() ? TFsPath(r) : TFsPath();
}
TFsPath TFsPath::Parent() const {
@@ -230,7 +230,7 @@ struct TClosedir {
void TFsPath::ListNames(TVector<TString>& children) const {
CheckDefined();
- THolder<DIR, TClosedir> dir(opendir(this->c_str()));
+ THolder<DIR, TClosedir> dir(opendir(this->c_str()));
if (!dir) {
ythrow TIoSystemError() << "failed to opendir " << Path_;
}
@@ -340,15 +340,15 @@ void TFsPath::CheckExists() const {
}
bool TFsPath::IsDirectory() const {
- return IsDefined() && TFileStat(GetPath().data()).IsDir();
+ return IsDefined() && TFileStat(GetPath().data()).IsDir();
}
bool TFsPath::IsFile() const {
- return IsDefined() && TFileStat(GetPath().data()).IsFile();
+ return IsDefined() && TFileStat(GetPath().data()).IsFile();
}
bool TFsPath::IsSymlink() const {
- return IsDefined() && TFileStat(GetPath().data(), true).IsSymlink();
+ return IsDefined() && TFileStat(GetPath().data(), true).IsSymlink();
}
void TFsPath::DeleteIfExists() const {
@@ -356,8 +356,8 @@ void TFsPath::DeleteIfExists() const {
return;
}
- ::unlink(this->c_str());
- ::rmdir(this->c_str());
+ ::unlink(this->c_str());
+ ::rmdir(this->c_str());
if (Exists()) {
ythrow TIoException() << "failed to delete " << Path_;
}
@@ -366,7 +366,7 @@ void TFsPath::DeleteIfExists() const {
void TFsPath::MkDir(const int mode) const {
CheckDefined();
if (!Exists()) {
- int r = Mkdir(this->c_str(), mode);
+ int r = Mkdir(this->c_str(), mode);
if (r != 0) {
// TODO (stanly) will still fail on Windows because
// LastSystemError() returns windows specific ERROR_ALREADY_EXISTS
diff --git a/util/folder/path.h b/util/folder/path.h
index 2fb4d6b4ef..f90f0b70e9 100644
--- a/util/folder/path.h
+++ b/util/folder/path.h
@@ -44,8 +44,8 @@ public:
return IsDefined();
}
- inline const char* c_str() const {
- return Path_.c_str();
+ inline const char* c_str() const {
+ return Path_.c_str();
}
inline operator const TString&() const {
@@ -166,7 +166,7 @@ public:
// XXX: ino
inline bool Stat(TFileStat& stat) const {
- stat = TFileStat(Path_.data());
+ stat = TFileStat(Path_.data());
return stat.Mode;
}
diff --git a/util/folder/pathsplit.cpp b/util/folder/pathsplit.cpp
index 81d439a727..e24ca90203 100644
--- a/util/folder/pathsplit.cpp
+++ b/util/folder/pathsplit.cpp
@@ -31,7 +31,7 @@ void TPathSplitTraitsUnix::DoParseFirstPart(const TStringBuf part) {
}
void TPathSplitTraitsUnix::DoParsePart(const TStringBuf part0) {
- DoAppendHint(part0.size() / 8);
+ DoAppendHint(part0.size() / 8);
TStringBuf next(part0);
TStringBuf part;
@@ -55,7 +55,7 @@ void TPathSplitTraitsWindows::DoParseFirstPart(const TStringBuf part0) {
if (IsAbsolutePath(part)) {
IsAbsolute = true;
- if (part.size() > 1 && part[1] == ':') {
+ if (part.size() > 1 && part[1] == ':') {
Drive = part.SubStr(0, 2);
part = part.SubStr(2);
}
@@ -65,23 +65,23 @@ void TPathSplitTraitsWindows::DoParseFirstPart(const TStringBuf part0) {
}
void TPathSplitTraitsWindows::DoParsePart(const TStringBuf part0) {
- DoAppendHint(part0.size() / 8);
+ DoAppendHint(part0.size() / 8);
size_t pos = 0;
TStringBuf part(part0);
- while (pos < part.size()) {
- while (pos < part.size() && this->IsPathSep(part[pos])) {
+ while (pos < part.size()) {
+ while (pos < part.size() && this->IsPathSep(part[pos])) {
++pos;
}
- const char* begin = part.data() + pos;
+ const char* begin = part.data() + pos;
- while (pos < part.size() && !this->IsPathSep(part[pos])) {
+ while (pos < part.size() && !this->IsPathSep(part[pos])) {
++pos;
}
- AppendComponent(TStringBuf(begin, part.data() + pos));
+ AppendComponent(TStringBuf(begin, part.data() + pos));
}
}
@@ -135,14 +135,14 @@ TString JoinPaths(const TPathSplit& p1, const TPathSplit& p2) {
}
TStringBuf CutExtension(const TStringBuf fileName) {
- if (fileName.empty()) {
+ if (fileName.empty()) {
return fileName;
}
TStringBuf name;
TStringBuf extension;
fileName.RSplit('.', name, extension);
- if (name.empty()) {
+ if (name.empty()) {
// dot at a start or not found
return name;
} else {
diff --git a/util/folder/pathsplit.h b/util/folder/pathsplit.h
index d134338e35..94eacb49a7 100644
--- a/util/folder/pathsplit.h
+++ b/util/folder/pathsplit.h
@@ -52,7 +52,7 @@ struct TPathSplitTraitsWindows: public TPathSplitStore {
}
static inline bool IsAbsolutePath(const TStringBuf path) noexcept {
- return path && (IsPathSep(path[0]) || (path.size() > 1 && path[1] == ':' && IsAsciiAlpha(path[0]) && (path.size() == 2 || IsPathSep(path[2]))));
+ return path && (IsPathSep(path[0]) || (path.size() > 1 && path[1] == ':' && IsAsciiAlpha(path[0]) && (path.size() == 2 || IsPathSep(path[2]))));
}
void DoParseFirstPart(const TStringBuf part);
diff --git a/util/folder/tempdir.cpp b/util/folder/tempdir.cpp
index 6fdf8f753c..f66d41bf5f 100644
--- a/util/folder/tempdir.cpp
+++ b/util/folder/tempdir.cpp
@@ -26,7 +26,7 @@ TTempDir::TTempDir(const TString& tempDir)
, Remove(true)
{
NFs::Remove(TempDir);
- MakeDirIfNotExist(TempDir.c_str());
+ MakeDirIfNotExist(TempDir.c_str());
}
TTempDir TTempDir::NewTempDir(const TString& root) {
diff --git a/util/generic/algorithm.h b/util/generic/algorithm.h
index badfb88993..0b24a74a92 100644
--- a/util/generic/algorithm.h
+++ b/util/generic/algorithm.h
@@ -347,17 +347,17 @@ void EraseIf(C& c, P p) {
c.erase(std::remove_if(c.begin(), c.end(), p), c.end());
}
-template <class C, class P>
-void EraseNodesIf(C& c, P p) {
- for (auto iter = c.begin(), last = c.end(); iter != last;) {
- if (p(*iter)) {
- c.erase(iter++);
- } else {
- ++iter;
- }
- }
-}
-
+template <class C, class P>
+void EraseNodesIf(C& c, P p) {
+ for (auto iter = c.begin(), last = c.end(); iter != last;) {
+ if (p(*iter)) {
+ c.erase(iter++);
+ } else {
+ ++iter;
+ }
+ }
+}
+
template <class T1, class T2>
static inline bool Equal(T1 f1, T1 l1, T2 f2) {
return std::equal(f1, l1, f2);
diff --git a/util/generic/algorithm_ut.cpp b/util/generic/algorithm_ut.cpp
index 8d732fcc0c..0925eb354d 100644
--- a/util/generic/algorithm_ut.cpp
+++ b/util/generic/algorithm_ut.cpp
@@ -281,37 +281,37 @@ Y_UNIT_TEST_SUITE(TAlgorithm) {
}
Y_UNIT_TEST(EraseNodesIfTest) {
- TMap<int, int> map{{1, 1}, {2, 2}, {3, 5}};
- TMap<int, int> expectedMap{{1, 1}};
- EraseNodesIf(map, [](auto p) { return p.first >= 2; });
- UNIT_ASSERT_EQUAL(map, expectedMap);
-
- TMultiMap<int, int> multiMap{{1, 1}, {1, 3}, {2, 2}, {3, 5}};
- TMultiMap<int, int> expectedMultiMap{{1, 1}, {1, 3}};
- EraseNodesIf(multiMap, [](auto p) { return p.first >= 2; });
- UNIT_ASSERT_EQUAL(multiMap, expectedMultiMap);
-
- TSet<int> set{1, 2, 3, 4, 5, 6, 7};
- TSet<int> expectedSet{1, 3, 5, 7};
- EraseNodesIf(set, [](int i) { return i % 2 == 0; });
- UNIT_ASSERT_EQUAL(set, expectedSet);
-
- TMultiSet<int> multiSet{1, 1, 2, 3, 4, 4, 4, 5, 5, 5, 6, 7};
- TMultiSet<int> expectedMultiSet{1, 1, 3, 5, 5, 5, 7};
- EraseNodesIf(multiSet, [](int i) { return i % 2 == 0; });
- UNIT_ASSERT_EQUAL(multiSet, expectedMultiSet);
-
- THashMap<int, int> hashMap{{1, 0}, {3, 0}, {4, 0}, {10, 0}, {2, 0}, {5, 2}};
- THashMap<int, int> expectedHashMap{{1, 0}, {3, 0}, {5, 2}};
- EraseNodesIf(hashMap, [](auto p) { return p.first % 2 == 0; });
- UNIT_ASSERT_EQUAL(hashMap, expectedHashMap);
-
- THashMultiMap<int, int> hashMultiMap{{1, 0}, {3, 0}, {4, 0}, {10, 0}, {2, 0}, {5, 0}, {1, 0}, {1, 0}, {2, 0}, {2, 2}};
- THashMultiMap<int, int> expectedHashMultiMap{{1, 0}, {1, 0}, {1, 0}, {3, 0}, {5, 0}};
- EraseNodesIf(hashMultiMap, [](auto p) { return p.first % 2 == 0; });
- UNIT_ASSERT_EQUAL(hashMultiMap, expectedHashMultiMap);
- }
-
+ TMap<int, int> map{{1, 1}, {2, 2}, {3, 5}};
+ TMap<int, int> expectedMap{{1, 1}};
+ EraseNodesIf(map, [](auto p) { return p.first >= 2; });
+ UNIT_ASSERT_EQUAL(map, expectedMap);
+
+ TMultiMap<int, int> multiMap{{1, 1}, {1, 3}, {2, 2}, {3, 5}};
+ TMultiMap<int, int> expectedMultiMap{{1, 1}, {1, 3}};
+ EraseNodesIf(multiMap, [](auto p) { return p.first >= 2; });
+ UNIT_ASSERT_EQUAL(multiMap, expectedMultiMap);
+
+ TSet<int> set{1, 2, 3, 4, 5, 6, 7};
+ TSet<int> expectedSet{1, 3, 5, 7};
+ EraseNodesIf(set, [](int i) { return i % 2 == 0; });
+ UNIT_ASSERT_EQUAL(set, expectedSet);
+
+ TMultiSet<int> multiSet{1, 1, 2, 3, 4, 4, 4, 5, 5, 5, 6, 7};
+ TMultiSet<int> expectedMultiSet{1, 1, 3, 5, 5, 5, 7};
+ EraseNodesIf(multiSet, [](int i) { return i % 2 == 0; });
+ UNIT_ASSERT_EQUAL(multiSet, expectedMultiSet);
+
+ THashMap<int, int> hashMap{{1, 0}, {3, 0}, {4, 0}, {10, 0}, {2, 0}, {5, 2}};
+ THashMap<int, int> expectedHashMap{{1, 0}, {3, 0}, {5, 2}};
+ EraseNodesIf(hashMap, [](auto p) { return p.first % 2 == 0; });
+ UNIT_ASSERT_EQUAL(hashMap, expectedHashMap);
+
+ THashMultiMap<int, int> hashMultiMap{{1, 0}, {3, 0}, {4, 0}, {10, 0}, {2, 0}, {5, 0}, {1, 0}, {1, 0}, {2, 0}, {2, 2}};
+ THashMultiMap<int, int> expectedHashMultiMap{{1, 0}, {1, 0}, {1, 0}, {3, 0}, {5, 0}};
+ EraseNodesIf(hashMultiMap, [](auto p) { return p.first % 2 == 0; });
+ UNIT_ASSERT_EQUAL(hashMultiMap, expectedHashMultiMap);
+ }
+
Y_UNIT_TEST(NthElementTest) {
{
TVector<TString> v;
@@ -551,7 +551,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) {
TVector<int>::iterator iter = CopyN(data, toCopy, result.begin());
UNIT_ASSERT_VALUES_EQUAL(iter - result.begin(), toCopy);
- UNIT_ASSERT_VALUES_EQUAL(result.size(), 10);
+ UNIT_ASSERT_VALUES_EQUAL(result.size(), 10);
for (size_t idx = 0; idx < toCopy; ++idx) {
UNIT_ASSERT_VALUES_EQUAL(data[idx], result[idx]);
}
@@ -582,7 +582,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) {
TVector<int> v(vSize, 0);
TVector<int>::iterator iter = CopyIf(data, data + count, v.begin(), [](int x) { return !(x % 3); });
- UNIT_ASSERT_VALUES_EQUAL(v.size(), vSize);
+ UNIT_ASSERT_VALUES_EQUAL(v.size(), vSize);
UNIT_ASSERT_VALUES_EQUAL(iter - v.begin(), 3);
v.resize(iter - v.begin());
for (size_t idx = 0; idx < v.size(); ++idx) {
diff --git a/util/generic/bitops.h b/util/generic/bitops.h
index 2db15fc59b..add0b75a17 100644
--- a/util/generic/bitops.h
+++ b/util/generic/bitops.h
@@ -424,31 +424,31 @@ constexpr T RotateBitsRightCT(T value, const ui8 shift) noexcept {
// do trick with mask to avoid undefined behaviour
return (value >> shift) | (value << ((-shift) & (sizeof(T) * 8 - 1)));
}
-
-/* Remain `size` bits to current `offset` of `value`
- size, offset are less than number of bits in size_type
- */
+
+/* Remain `size` bits to current `offset` of `value`
+ size, offset are less than number of bits in size_type
+ */
template <size_t Offset, size_t Size, class T>
-Y_FORCE_INLINE T SelectBits(T value) {
+Y_FORCE_INLINE T SelectBits(T value) {
static_assert(Size < sizeof(T) * 8, "violated: Size < sizeof(T) * 8");
static_assert(Offset < sizeof(T) * 8, "violated: Offset < sizeof(T) * 8");
- T id = 1;
- return (value >> Offset) & ((id << Size) - id);
-}
-
-/* Set `size` bits of `bits` to current offset of `value`. Requires that bits <= (1 << size) - 1
- size, offset are less than number of bits in size_type
- */
+ T id = 1;
+ return (value >> Offset) & ((id << Size) - id);
+}
+
+/* Set `size` bits of `bits` to current offset of `value`. Requires that bits <= (1 << size) - 1
+ size, offset are less than number of bits in size_type
+ */
template <size_t Offset, size_t Size, class T>
-void SetBits(T& value, T bits) {
+void SetBits(T& value, T bits) {
static_assert(Size < sizeof(T) * 8, "violated: Size < sizeof(T) * 8");
static_assert(Offset < sizeof(T) * 8, "violated: Offset < sizeof(T) * 8");
- T id = 1;
- T maxValue = ((id << Size) - id);
- Y_ASSERT(bits <= maxValue);
- value &= ~(maxValue << Offset);
- value |= bits << Offset;
-}
+ T id = 1;
+ T maxValue = ((id << Size) - id);
+ Y_ASSERT(bits <= maxValue);
+ value &= ~(maxValue << Offset);
+ value |= bits << Offset;
+}
inline constexpr ui64 NthBit64(int bit) {
return ui64(1) << bit;
diff --git a/util/generic/bitops_ut.cpp b/util/generic/bitops_ut.cpp
index d23c2b5c27..0f7872b8b0 100644
--- a/util/generic/bitops_ut.cpp
+++ b/util/generic/bitops_ut.cpp
@@ -293,29 +293,29 @@ Y_UNIT_TEST_SUITE(TBitOpsTest) {
UNIT_ASSERT_VALUES_EQUAL(RotateBitsRight<ui64>(0b1010000000000000000000000000000000000000000000000000000000000000u, 1), 0b0101000000000000000000000000000000000000000000000000000000000000u);
UNIT_ASSERT_VALUES_EQUAL(RotateBitsRight<ui64>(0b0000000000000000000000000000000000000000000000000000000000000001u, 63), 0b0000000000000000000000000000000000000000000000000000000000000010u);
}
-
+
Y_UNIT_TEST(TestSelectBits) {
ui8 firstui8Test = SelectBits<3, 4, ui8>(0b11111111u);
ui8 secondui8Test = SelectBits<2, 5, ui8>(0b11101101u);
UNIT_ASSERT_VALUES_EQUAL(firstui8Test, 0b00001111u);
UNIT_ASSERT_VALUES_EQUAL(secondui8Test, 0b00011011u);
-
+
ui16 firstui16Test = SelectBits<9, 2, ui16>(0b1111111111111111u);
ui16 secondui16Test = SelectBits<3, 6, ui16>(0b1010011111010001u);
UNIT_ASSERT_VALUES_EQUAL(firstui16Test, 0b0000000000000011u);
UNIT_ASSERT_VALUES_EQUAL(secondui16Test, 0b0000000000111010u);
-
+
ui32 firstui32Test = SelectBits<23, 31, ui32>(0b11111111111111111111111111111111u);
ui32 secondui32Test = SelectBits<0, 31, ui32>(0b10001011101010011111010000111111u);
UNIT_ASSERT_VALUES_EQUAL(firstui32Test, 0b00000000000000000000000111111111u);
UNIT_ASSERT_VALUES_EQUAL(secondui32Test, 0b00001011101010011111010000111111);
-
+
ui64 firstui64Test = SelectBits<1, 62, ui64>(0b1111000000000000000000000000000000000000000000000000000000000000u);
ui64 secondui64Test = SelectBits<32, 43, ui64>(0b1111111111111111111111111111111111111111111111111111111111111111u);
UNIT_ASSERT_VALUES_EQUAL(firstui64Test, 0b0011100000000000000000000000000000000000000000000000000000000000u);
UNIT_ASSERT_VALUES_EQUAL(secondui64Test, 0b0000000000000000000000000000000011111111111111111111111111111111u);
}
-
+
Y_UNIT_TEST(TestSetBits) {
ui8 firstui8Test = 0b11111111u;
SetBits<3, 4, ui8>(firstui8Test, 0b00001111u);
@@ -323,21 +323,21 @@ Y_UNIT_TEST_SUITE(TBitOpsTest) {
SetBits<2, 7, ui8>(secondui8Test, 0b01110111u);
UNIT_ASSERT_VALUES_EQUAL(firstui8Test, 0b11111111u);
UNIT_ASSERT_VALUES_EQUAL(secondui8Test, 0b11011101u);
-
+
ui16 firstui16Test = 0b1111111111111111u;
SetBits<9, 4, ui16>(firstui16Test, 0b000000000000111u);
ui16 secondui16Test = 0b1010011111010001u;
SetBits<3, 15, ui16>(secondui16Test, 0b0010011111010001u);
UNIT_ASSERT_VALUES_EQUAL(firstui16Test, 0b1110111111111111u);
UNIT_ASSERT_VALUES_EQUAL(secondui16Test, 0b0011111010001001u);
-
+
ui32 firstui32Test = 0b11111111111111111111111111111111u;
SetBits<23, 31, ui32>(firstui32Test, 0b01100001111111111001111101111111u);
ui32 secondui32Test = 0b10001011101010011111010000111111u;
SetBits<0, 31, ui32>(secondui32Test, 0b01111111111111111111111111111111u);
UNIT_ASSERT_VALUES_EQUAL(firstui32Test, 0b10111111111111111111111111111111u);
UNIT_ASSERT_VALUES_EQUAL(secondui32Test, 0b11111111111111111111111111111111u);
-
+
ui64 firstui64Test = 0b1111000000000000000000000000000000000000000000000000000000000000u;
SetBits<1, 62, ui64>(firstui64Test, 0b0001000000000000000000000000000000000000000000000000000001010101u);
ui64 secondui64Test = 0b1111111111111111111111111111111111111111111111111111111111111111u;
diff --git a/util/generic/buffer.h b/util/generic/buffer.h
index 9576467404..38355d5258 100644
--- a/util/generic/buffer.h
+++ b/util/generic/buffer.h
@@ -181,18 +181,18 @@ public:
}
}
- inline char* data() noexcept {
- return Data();
- }
-
- inline const char* data() const noexcept {
- return Data();
- }
-
- inline size_t size() const noexcept {
- return Size();
- }
-
+ inline char* data() noexcept {
+ return Data();
+ }
+
+ inline const char* data() const noexcept {
+ return Data();
+ }
+
+ inline size_t size() const noexcept {
+ return Size();
+ }
+
inline void Swap(TBuffer& r) noexcept {
DoSwap(Data_, r.Data_);
DoSwap(Len_, r.Len_);
diff --git a/util/generic/buffer_ut.cpp b/util/generic/buffer_ut.cpp
index 437d7122ec..df500cf1eb 100644
--- a/util/generic/buffer_ut.cpp
+++ b/util/generic/buffer_ut.cpp
@@ -14,7 +14,7 @@ Y_UNIT_TEST_SUITE(TBufferTest) {
buf.Resize(6);
buf.EraseBack(2);
- UNIT_ASSERT_EQUAL(TString(buf.data(), buf.size()), "1234");
+ UNIT_ASSERT_EQUAL(TString(buf.data(), buf.size()), "1234");
}
Y_UNIT_TEST(TestAppend) {
@@ -32,7 +32,7 @@ Y_UNIT_TEST_SUITE(TBufferTest) {
}
}
- UNIT_ASSERT_EQUAL(TString(buf.data(), buf.size()), str);
+ UNIT_ASSERT_EQUAL(TString(buf.data(), buf.size()), str);
}
Y_UNIT_TEST(TestReset) {
@@ -55,17 +55,17 @@ Y_UNIT_TEST_SUITE(TBufferTest) {
TBuffer buf;
buf.Resize(10);
- UNIT_ASSERT_VALUES_EQUAL(buf.size(), 10u);
+ UNIT_ASSERT_VALUES_EQUAL(buf.size(), 10u);
buf.Resize(0);
- UNIT_ASSERT_VALUES_EQUAL(buf.size(), 0u);
+ UNIT_ASSERT_VALUES_EQUAL(buf.size(), 0u);
buf.Resize(9);
- memcpy(buf.data(), content, 9);
- UNIT_ASSERT_VALUES_EQUAL(TString(buf.data(), buf.size()), "some text");
+ memcpy(buf.data(), content, 9);
+ UNIT_ASSERT_VALUES_EQUAL(TString(buf.data(), buf.size()), "some text");
buf.Resize(4);
- UNIT_ASSERT_VALUES_EQUAL(TString(buf.data(), buf.size()), "some");
+ UNIT_ASSERT_VALUES_EQUAL(TString(buf.data(), buf.size()), "some");
}
Y_UNIT_TEST(TestReserve) {
@@ -92,12 +92,12 @@ Y_UNIT_TEST_SUITE(TBufferTest) {
buf.Append('a');
UNIT_ASSERT_EQUAL(buf.Capacity(), 256);
TString tmp1 = "abcdef";
- buf.Append(tmp1.data(), tmp1.size());
+ buf.Append(tmp1.data(), tmp1.size());
UNIT_ASSERT_EQUAL(buf.Capacity(), 256);
TString tmp2 = "30498290sfokdsflj2308w";
buf.Resize(1020);
- buf.Append(tmp2.data(), tmp2.size());
+ buf.Append(tmp2.data(), tmp2.size());
UNIT_ASSERT_EQUAL(buf.Capacity(), 2048);
}
@@ -105,14 +105,14 @@ Y_UNIT_TEST_SUITE(TBufferTest) {
TBuffer buf;
TString content = "some text";
- buf.Append(content.data(), content.size());
+ buf.Append(content.data(), content.size());
UNIT_ASSERT_EQUAL(buf.Size(), 9);
UNIT_ASSERT_EQUAL(buf.Capacity(), 16);
buf.ShrinkToFit();
UNIT_ASSERT_EQUAL(buf.Size(), 9);
UNIT_ASSERT_EQUAL(buf.Capacity(), 9);
- UNIT_ASSERT_EQUAL(TString(buf.data(), buf.size()), content);
+ UNIT_ASSERT_EQUAL(TString(buf.data(), buf.size()), content);
const size_t MB = 1024 * 1024;
buf.Resize(MB);
@@ -184,10 +184,10 @@ Y_UNIT_TEST(TestSpeed) {
buf.Append("Some ", 5);
buf.Fill('!', 5);
buf.Append(" text.", 6);
- UNIT_ASSERT_VALUES_EQUAL(TString(buf.data(), buf.size()), "Some !!!!! text.");
+ UNIT_ASSERT_VALUES_EQUAL(TString(buf.data(), buf.size()), "Some !!!!! text.");
buf.Chop(5, 6);
- UNIT_ASSERT_VALUES_EQUAL(TString(buf.data(), buf.size()), "Some text.");
+ UNIT_ASSERT_VALUES_EQUAL(TString(buf.data(), buf.size()), "Some text.");
}
Y_UNIT_TEST(TestComparison) {
diff --git a/util/generic/function.h b/util/generic/function.h
index 62fa84e0cb..aa7bf8aa13 100644
--- a/util/generic/function.h
+++ b/util/generic/function.h
@@ -21,26 +21,26 @@ namespace NPrivate {
typedef R TSignature(Args...);
};
- template <class T>
- struct TRemoveNoExceptImpl {
- using Type = T;
- };
-
- template <typename R, typename... Args>
- struct TRemoveNoExceptImpl<R(Args...) noexcept> {
- using Type = R(Args...);
- };
-
- template <typename R, typename C, typename... Args>
- struct TRemoveNoExceptImpl<R (C::*)(Args...) noexcept> {
- using Type = R (C::*)(Args...);
- };
-
- template <class T>
- using TRemoveNoExcept = typename TRemoveNoExceptImpl<T>::Type;
-
+ template <class T>
+ struct TRemoveNoExceptImpl {
+ using Type = T;
+ };
+
+ template <typename R, typename... Args>
+ struct TRemoveNoExceptImpl<R(Args...) noexcept> {
+ using Type = R(Args...);
+ };
+
+ template <typename R, typename C, typename... Args>
+ struct TRemoveNoExceptImpl<R (C::*)(Args...) noexcept> {
+ using Type = R (C::*)(Args...);
+ };
+
+ template <class T>
+ using TRemoveNoExcept = typename TRemoveNoExceptImpl<T>::Type;
+
template <class F>
- using TRemoveClass = typename TRemoveClassImpl<TRemoveNoExcept<F>>::TSignature;
+ using TRemoveClass = typename TRemoveClassImpl<TRemoveNoExcept<F>>::TSignature;
template <class C>
struct TFuncInfo {
diff --git a/util/generic/guid.cpp b/util/generic/guid.cpp
index 8b907457bc..a0a25619bb 100644
--- a/util/generic/guid.cpp
+++ b/util/generic/guid.cpp
@@ -44,8 +44,8 @@ TGUID TGUID::Create() {
void CreateGuid(TGUID* res) {
ui64* dw = reinterpret_cast<ui64*>(res->dw);
- WriteUnaligned<ui64>(&dw[0], RandomNumber<ui64>());
- WriteUnaligned<ui64>(&dw[1], RandomNumber<ui64>());
+ WriteUnaligned<ui64>(&dw[0], RandomNumber<ui64>());
+ WriteUnaligned<ui64>(&dw[1], RandomNumber<ui64>());
}
TGUID TGUID::CreateTimebased() {
diff --git a/util/generic/is_in_ut.cpp b/util/generic/is_in_ut.cpp
index c668bce807..4fc257797e 100644
--- a/util/generic/is_in_ut.cpp
+++ b/util/generic/is_in_ut.cpp
@@ -91,7 +91,7 @@ Y_UNIT_TEST_SUITE(TIsIn) {
const TStringBuf str = "abc////";
- UNIT_ASSERT(IsIn({"abc", "def"}, TStringBuf{str.data(), 3}));
+ UNIT_ASSERT(IsIn({"abc", "def"}, TStringBuf{str.data(), 3}));
}
Y_UNIT_TEST(ConfOfTest) {
@@ -100,8 +100,8 @@ Y_UNIT_TEST_SUITE(TIsIn) {
const TString b = "b";
- UNIT_ASSERT(!IsIn({"a", "b", "c"}, b.data())); // compares pointers by value. Whether it's good or not.
- UNIT_ASSERT(IsIn(TVector<TStringBuf>({"a", "b", "c"}), b.data()));
+ UNIT_ASSERT(!IsIn({"a", "b", "c"}, b.data())); // compares pointers by value. Whether it's good or not.
+ UNIT_ASSERT(IsIn(TVector<TStringBuf>({"a", "b", "c"}), b.data()));
UNIT_ASSERT(IsIn(TVector<TStringBuf>({"a", "b", "c"}), "b"));
}
diff --git a/util/generic/iterator_range.h b/util/generic/iterator_range.h
index 9f4d02da29..d89eaf7559 100644
--- a/util/generic/iterator_range.h
+++ b/util/generic/iterator_range.h
@@ -1,7 +1,7 @@
#pragma once
-#include <util/system/yassert.h>
-
+#include <util/system/yassert.h>
+
#include <iterator>
#include <utility>
@@ -43,10 +43,10 @@ class TIteratorRange<TIterator, TIterator> {
public:
using iterator = TIterator;
using const_iterator = TIterator;
- using value_type = typename std::iterator_traits<iterator>::value_type;
- using reference = typename std::iterator_traits<iterator>::reference;
- using const_reference = typename std::iterator_traits<const_iterator>::reference;
- using difference_type = typename std::iterator_traits<iterator>::difference_type;
+ using value_type = typename std::iterator_traits<iterator>::value_type;
+ using reference = typename std::iterator_traits<iterator>::reference;
+ using const_reference = typename std::iterator_traits<const_iterator>::reference;
+ using difference_type = typename std::iterator_traits<iterator>::difference_type;
using size_type = std::size_t;
TIteratorRange()
@@ -74,15 +74,15 @@ public:
}
size_type size() const {
- return End_ - Begin_;
- }
-
- reference operator[](size_t at) const {
- Y_ASSERT(at < size());
-
- return *(Begin_ + at);
+ return End_ - Begin_;
}
+ reference operator[](size_t at) const {
+ Y_ASSERT(at < size());
+
+ return *(Begin_ + at);
+ }
+
private:
TIterator Begin_;
TIterator End_;
diff --git a/util/generic/iterator_range_ut.cpp b/util/generic/iterator_range_ut.cpp
index a7e3670ae1..a93dc2e119 100644
--- a/util/generic/iterator_range_ut.cpp
+++ b/util/generic/iterator_range_ut.cpp
@@ -2,7 +2,7 @@
#include <library/cpp/testing/unittest/registar.h>
#include <util/generic/algorithm.h>
-#include <util/generic/vector.h>
+#include <util/generic/vector.h>
Y_UNIT_TEST_SUITE(IteratorRange) {
Y_UNIT_TEST(DefaultConstructor) {
@@ -70,24 +70,24 @@ Y_UNIT_TEST_SUITE(IteratorRange) {
Y_UNIT_TEST(OperatorsAndReferences) {
TVector<size_t> values{1, 2, 3, 4, 5};
- auto range = MakeIteratorRange(values.begin(), values.end());
- UNIT_ASSERT_VALUES_EQUAL(range[2], 3);
- UNIT_ASSERT_VALUES_EQUAL(range[range[2]], 4);
- *values.begin() = 100500;
- UNIT_ASSERT_VALUES_EQUAL(range[0], 100500);
- range[0] = 100501;
- UNIT_ASSERT_VALUES_EQUAL(range[0], 100501);
-
+ auto range = MakeIteratorRange(values.begin(), values.end());
+ UNIT_ASSERT_VALUES_EQUAL(range[2], 3);
+ UNIT_ASSERT_VALUES_EQUAL(range[range[2]], 4);
+ *values.begin() = 100500;
+ UNIT_ASSERT_VALUES_EQUAL(range[0], 100500);
+ range[0] = 100501;
+ UNIT_ASSERT_VALUES_EQUAL(range[0], 100501);
+
TVector<bool> valuesBool{false, true, false, false, false, false, true};
- auto rangeBVector = MakeIteratorRange(valuesBool.begin(), valuesBool.end());
- UNIT_ASSERT_VALUES_EQUAL(rangeBVector[1], true);
- rangeBVector[0] = true;
- valuesBool.back() = false;
- UNIT_ASSERT_VALUES_EQUAL(rangeBVector[0], true);
- UNIT_ASSERT_VALUES_EQUAL(rangeBVector[2], false);
- UNIT_ASSERT_VALUES_EQUAL(rangeBVector[6], false);
- }
-
+ auto rangeBVector = MakeIteratorRange(valuesBool.begin(), valuesBool.end());
+ UNIT_ASSERT_VALUES_EQUAL(rangeBVector[1], true);
+ rangeBVector[0] = true;
+ valuesBool.back() = false;
+ UNIT_ASSERT_VALUES_EQUAL(rangeBVector[0], true);
+ UNIT_ASSERT_VALUES_EQUAL(rangeBVector[2], false);
+ UNIT_ASSERT_VALUES_EQUAL(rangeBVector[6], false);
+ }
+
Y_UNIT_TEST(CanUseInAlgorithms) {
const int values[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
auto range = MakeIteratorRange(values, values + Y_ARRAY_SIZE(values));
diff --git a/util/generic/strbase.h b/util/generic/strbase.h
index ab39fc7537..7289e651ba 100644
--- a/util/generic/strbase.h
+++ b/util/generic/strbase.h
@@ -439,7 +439,7 @@ public:
}
inline TCharType operator[](size_t pos) const noexcept {
- Y_ASSERT(pos < this->size());
+ Y_ASSERT(pos < this->size());
return Ptr()[pos];
}
diff --git a/util/generic/strbuf.h b/util/generic/strbuf.h
index 70b9360d58..595db8114c 100644
--- a/util/generic/strbuf.h
+++ b/util/generic/strbuf.h
@@ -214,7 +214,7 @@ public:
* @returns Whether the split was actually performed.
*/
inline bool TrySplit(TdSelf delim, TdSelf& l, TdSelf& r) const noexcept {
- return TrySplitOn(TBase::find(delim), l, r, delim.size());
+ return TrySplitOn(TBase::find(delim), l, r, delim.size());
}
/**
@@ -229,7 +229,7 @@ public:
* @returns Whether the split was actually performed.
*/
inline bool TryRSplit(TdSelf delim, TdSelf& l, TdSelf& r) const noexcept {
- return TrySplitOn(TBase::rfind(delim), l, r, delim.size());
+ return TrySplitOn(TBase::rfind(delim), l, r, delim.size());
}
inline void Split(TCharType delim, TdSelf& l, TdSelf& r) const noexcept {
diff --git a/util/generic/strbuf_ut.cpp b/util/generic/strbuf_ut.cpp
index 69cde785af..fe2f7f1913 100644
--- a/util/generic/strbuf_ut.cpp
+++ b/util/generic/strbuf_ut.cpp
@@ -8,14 +8,14 @@ Y_UNIT_TEST_SUITE(TStrBufTest) {
Y_UNIT_TEST(TestConstructorsAndOperators) {
TStringBuf str("qwerty");
- UNIT_ASSERT_EQUAL(*str.data(), 'q');
- UNIT_ASSERT_EQUAL(str.size(), 6);
+ UNIT_ASSERT_EQUAL(*str.data(), 'q');
+ UNIT_ASSERT_EQUAL(str.size(), 6);
TStringBuf str1("qwe\0rty"sv);
TStringBuf str2(str1.data());
UNIT_ASSERT_VALUES_UNEQUAL(str1, str2);
- UNIT_ASSERT_VALUES_EQUAL(str1.size(), 7);
- UNIT_ASSERT_VALUES_EQUAL(str2.size(), 3);
+ UNIT_ASSERT_VALUES_EQUAL(str1.size(), 7);
+ UNIT_ASSERT_VALUES_EQUAL(str2.size(), 3);
std::string_view helloWorld("Hello, World!");
TStringBuf fromStringView(helloWorld);
@@ -29,10 +29,10 @@ Y_UNIT_TEST_SUITE(TStrBufTest) {
Y_UNIT_TEST(TestConstExpr) {
static constexpr TStringBuf str1("qwe\0rty", 7);
- static constexpr TStringBuf str2(str1.data(), str1.size());
+ static constexpr TStringBuf str2(str1.data(), str1.size());
static constexpr TStringBuf str3 = "qwe\0rty"sv;
- UNIT_ASSERT_VALUES_EQUAL(str1.size(), 7);
+ UNIT_ASSERT_VALUES_EQUAL(str1.size(), 7);
UNIT_ASSERT_VALUES_EQUAL(str1, str2);
UNIT_ASSERT_VALUES_EQUAL(str2, str3);
@@ -136,7 +136,7 @@ Y_UNIT_TEST_SUITE(TStrBufTest) {
}
Y_UNIT_TEST(TestEmpty) {
- UNIT_ASSERT(TStringBuf().empty());
+ UNIT_ASSERT(TStringBuf().empty());
UNIT_ASSERT(!TStringBuf("q").empty());
}
@@ -146,7 +146,7 @@ Y_UNIT_TEST_SUITE(TStrBufTest) {
str = qw;
str.Chop(10);
- UNIT_ASSERT(str.empty());
+ UNIT_ASSERT(str.empty());
str = qw;
UNIT_ASSERT_EQUAL(str.SubStr(2), TStringBuf("erty"));
@@ -172,7 +172,7 @@ Y_UNIT_TEST_SUITE(TStrBufTest) {
rt = qw;
lt = rt.NextTok('r');
TStringBuf ty = rt.NextTok('r'); // no 'r' in "ty"
- UNIT_ASSERT_EQUAL(rt.size(), 0);
+ UNIT_ASSERT_EQUAL(rt.size(), 0);
UNIT_ASSERT_EQUAL(ty, TStringBuf("ty"));
}
diff --git a/util/generic/string.cpp b/util/generic/string.cpp
index 3c655f1f66..584f72675e 100644
--- a/util/generic/string.cpp
+++ b/util/generic/string.cpp
@@ -11,7 +11,7 @@
alignas(32) const char NULL_STRING_REPR[128] = {0};
std::ostream& operator<<(std::ostream& os, const TString& s) {
- return os.write(s.data(), s.size());
+ return os.write(s.data(), s.size());
}
std::istream& operator>>(std::istream& is, TString& s) {
diff --git a/util/generic/string_ut.cpp b/util/generic/string_ut.cpp
index ac82e9091d..cd45b1d42c 100644
--- a/util/generic/string_ut.cpp
+++ b/util/generic/string_ut.cpp
@@ -29,7 +29,7 @@ public:
void TestZero() {
const char data[] = "abc\0def\0";
TString s(data, sizeof(data));
- UNIT_ASSERT(s.size() == sizeof(data));
+ UNIT_ASSERT(s.size() == sizeof(data));
UNIT_ASSERT(s.StartsWith(s));
UNIT_ASSERT(s.EndsWith(s));
UNIT_ASSERT(s.Contains('\0'));
@@ -48,7 +48,7 @@ public:
UNIT_ASSERT_EQUAL(TString::npos, s.find(TString(nonSubstring, sizeof(nonSubstring))));
TString copy = s;
- copy.replace(copy.size() - 1, 1, "z");
+ copy.replace(copy.size() - 1, 1, "z");
UNIT_ASSERT(s != copy);
copy.replace(copy.size() - 1, 1, "\0", 0, 1);
UNIT_ASSERT(s == copy);
@@ -57,8 +57,8 @@ public:
UNIT_ASSERT(s.StartsWith(prefix));
UNIT_ASSERT(s != prefix);
UNIT_ASSERT(s > prefix);
- UNIT_ASSERT(s > s.data());
- UNIT_ASSERT(s == TString(s.data(), s.size()));
+ UNIT_ASSERT(s > s.data());
+ UNIT_ASSERT(s == TString(s.data(), s.size()));
UNIT_ASSERT(data < s);
s.remove(5);
@@ -552,13 +552,13 @@ protected:
str2 = Data_.abcdef();
UNIT_ASSERT(str1.compare(str2) == 0);
- UNIT_ASSERT(str1.compare(str2.data(), str2.size()) == 0);
+ UNIT_ASSERT(str1.compare(str2.data(), str2.size()) == 0);
str2 = Data_.abcde();
UNIT_ASSERT(str1.compare(str2) > 0);
- UNIT_ASSERT(str1.compare(str2.data(), str2.size()) > 0);
+ UNIT_ASSERT(str1.compare(str2.data(), str2.size()) > 0);
str2 = Data_.abcdefg();
UNIT_ASSERT(str1.compare(str2) < 0);
- UNIT_ASSERT(str1.compare(str2.data(), str2.size()) < 0);
+ UNIT_ASSERT(str1.compare(str2.data(), str2.size()) < 0);
UNIT_ASSERT(str1.compare(Data_.abcdef()) == 0);
UNIT_ASSERT(str1.compare(Data_.abcde()) > 0);
@@ -889,7 +889,7 @@ private:
UNIT_ASSERT(str == TUtf16String::FromAscii("X"));
const TUtf16String hello = TUtf16String::FromAscii("hello");
- str = hello.data();
+ str = hello.data();
UNIT_ASSERT(str == hello);
str = hello;
@@ -1087,7 +1087,7 @@ private:
UNIT_ASSERT(str == TUtf32String::FromAscii("X"));
const TUtf32String hello = TUtf32String::FromAscii("hello");
- str = hello.data();
+ str = hello.data();
UNIT_ASSERT(str == hello);
str = hello;
diff --git a/util/generic/string_ut.h b/util/generic/string_ut.h
index 44bb10bdeb..95bc855cb2 100644
--- a/util/generic/string_ut.h
+++ b/util/generic/string_ut.h
@@ -646,8 +646,8 @@ public:
s = Data._012345();
UNIT_ASSERT(s.at(1) == *Data._1());
UNIT_ASSERT(s[1] == *Data._1());
- UNIT_ASSERT(s.at(s.size()) == 0);
- UNIT_ASSERT(s[s.size()] == 0);
+ UNIT_ASSERT(s.at(s.size()) == 0);
+ UNIT_ASSERT(s[s.size()] == 0);
}
#ifndef TSTRING_IS_STD_STRING
@@ -690,7 +690,7 @@ public:
UNIT_ASSERT(s.find_first_of(TStringType(Data._389())) == 3);
UNIT_ASSERT(s.find_first_of(Data._389()) == 3);
- UNIT_ASSERT(s.find_first_of(Data._389(), s.size()) == TStringType::npos);
+ UNIT_ASSERT(s.find_first_of(Data._389(), s.size()) == TStringType::npos);
UNIT_ASSERT(s.find_first_not_of(Data._123()) == 0);
UNIT_ASSERT(s.find_first_of('6') == 6);
UNIT_ASSERT(s.find_first_of('1', 2) == 8);
@@ -820,10 +820,10 @@ public:
void TestFuncs() {
TStringType s(Data._0123456());
- UNIT_ASSERT(s.c_str() == s.data());
+ UNIT_ASSERT(s.c_str() == s.data());
// length()
- UNIT_ASSERT(s.length() == s.size());
+ UNIT_ASSERT(s.length() == s.size());
UNIT_ASSERT(s.length() == traits_type::length(s.data()));
// is_null()
@@ -868,10 +868,10 @@ public:
s2 = s3;
// resize family
- s2.resize(s2.size()); // without length change
+ s2.resize(s2.size()); // without length change
UNIT_ASSERT(s2 == Data.Asdf1234qwer());
- s2.resize(s2.size() + 4, *Data.W());
+ s2.resize(s2.size() + 4, *Data.W());
UNIT_ASSERT(s2 == Data.Asdf1234qwerWWWW());
s2.resize(4);
diff --git a/util/generic/vector_ut.cpp b/util/generic/vector_ut.cpp
index 0f6b4037a0..865a00cd3a 100644
--- a/util/generic/vector_ut.cpp
+++ b/util/generic/vector_ut.cpp
@@ -70,7 +70,7 @@ private:
inline void TestTildeEmptyToNull() {
TVector<int> v;
- UNIT_ASSERT_EQUAL(nullptr, v.data());
+ UNIT_ASSERT_EQUAL(nullptr, v.data());
}
inline void TestTilde() {
@@ -78,17 +78,17 @@ private:
v.push_back(10);
v.push_back(20);
- UNIT_ASSERT_EQUAL(10, (v.data())[0]);
- UNIT_ASSERT_EQUAL(20, (v.data())[1]);
+ UNIT_ASSERT_EQUAL(10, (v.data())[0]);
+ UNIT_ASSERT_EQUAL(20, (v.data())[1]);
for (int i = 0; i < 10000; ++i) {
v.push_back(99);
}
- UNIT_ASSERT_EQUAL(10, (v.data())[0]);
- UNIT_ASSERT_EQUAL(20, (v.data())[1]);
- UNIT_ASSERT_EQUAL(99, (v.data())[3]);
- UNIT_ASSERT_EQUAL(99, (v.data())[4]);
+ UNIT_ASSERT_EQUAL(10, (v.data())[0]);
+ UNIT_ASSERT_EQUAL(20, (v.data())[1]);
+ UNIT_ASSERT_EQUAL(99, (v.data())[3]);
+ UNIT_ASSERT_EQUAL(99, (v.data())[4]);
}
// Copy-paste of STLPort tests
diff --git a/util/memory/blob.cpp b/util/memory/blob.cpp
index 91da5cadca..d7de94fe86 100644
--- a/util/memory/blob.cpp
+++ b/util/memory/blob.cpp
@@ -395,7 +395,7 @@ TBlob ConstructFromString(S&& s) {
using TBase = TStringBlobBase<TCounter>;
auto base = MakeHolder<TBase>(std::forward<S>(s));
- TBlob ret(base->String().data(), base->String().size(), base.Get());
+ TBlob ret(base->String().data(), base->String().size(), base.Get());
Y_UNUSED(base.Release());
return ret;
diff --git a/util/memory/pool.h b/util/memory/pool.h
index 13c8b6b9ed..c906f6d208 100644
--- a/util/memory/pool.h
+++ b/util/memory/pool.h
@@ -225,10 +225,10 @@ public:
template <typename TChar>
inline TBasicStringBuf<TChar> AppendCString(const TBasicStringBuf<TChar>& buf) {
- TChar* ret = static_cast<TChar*>(Allocate((buf.size() + 1) * sizeof(TChar)));
+ TChar* ret = static_cast<TChar*>(Allocate((buf.size() + 1) * sizeof(TChar)));
std::char_traits<TChar>::copy(ret, buf.data(), buf.size());
- *(ret + buf.size()) = 0;
+ *(ret + buf.size()) = 0;
return TBasicStringBuf<TChar>(ret, buf.size());
}
diff --git a/util/memory/segmented_string_pool.h b/util/memory/segmented_string_pool.h
index a40aa408f5..4da0763afc 100644
--- a/util/memory/segmented_string_pool.h
+++ b/util/memory/segmented_string_pool.h
@@ -3,7 +3,7 @@
#include <util/system/align.h>
#include <util/system/yassert.h>
#include <util/system/defaults.h>
-#include <util/generic/noncopyable.h>
+#include <util/generic/noncopyable.h>
#include <util/generic/vector.h>
#include <util/generic/strbuf.h>
@@ -172,7 +172,7 @@ public:
return rv;
}
char* Append(const TStringBuf s) {
- return append(s.data(), s.size());
+ return append(s.data(), s.size());
}
void align_4() {
size_t t = (curseg->freepos + 3) & ~3;
diff --git a/util/network/ip.h b/util/network/ip.h
index dc7c2d24a0..fbabb76cbf 100644
--- a/util/network/ip.h
+++ b/util/network/ip.h
@@ -46,7 +46,7 @@ static inline TIpHost ResolveHost(const char* data, size_t len) {
TIpHost ret;
const TString s(data, len);
- if (NResolver::GetHostIP(s.data(), &ret) != 0) {
+ if (NResolver::GetHostIP(s.data(), &ret) != 0) {
ythrow TSystemError(NResolver::GetDnsError()) << "can not resolve(" << s << ")";
}
@@ -70,7 +70,7 @@ struct TIpAddress: public sockaddr_in {
}
inline TIpAddress(TStringBuf ip, TIpPort port) {
- Set(ResolveHost(ip.data(), ip.size()), port);
+ Set(ResolveHost(ip.data(), ip.size()), port);
}
inline TIpAddress(const char* ip, TIpPort port) {
diff --git a/util/network/socket.cpp b/util/network/socket.cpp
index 4f6e804346..1440dd5363 100644
--- a/util/network/socket.cpp
+++ b/util/network/socket.cpp
@@ -1070,12 +1070,12 @@ TNetworkAddress::TNetworkAddress(const TUnixSocketPath& unixSocketPath, int flag
}
TNetworkAddress::TNetworkAddress(const TString& host, ui16 port, int flags)
- : Impl_(new TImpl(host.data(), port, flags))
+ : Impl_(new TImpl(host.data(), port, flags))
{
}
TNetworkAddress::TNetworkAddress(const TString& host, ui16 port)
- : Impl_(new TImpl(host.data(), port, 0))
+ : Impl_(new TImpl(host.data(), port, 0))
{
}
diff --git a/util/network/socket_ut.cpp b/util/network/socket_ut.cpp
index 6b20e11f70..7a03df97ea 100644
--- a/util/network/socket_ut.cpp
+++ b/util/network/socket_ut.cpp
@@ -48,7 +48,7 @@ void TSockTest::TestSock() {
TSocketInput si(s);
const TStringBuf req = "GET / HTTP/1.1\r\nHost: yandex.ru\r\n\r\n";
- so.Write(req.data(), req.size());
+ so.Write(req.data(), req.size());
UNIT_ASSERT(!si.ReadLine().empty());
}
diff --git a/util/random/entropy.cpp b/util/random/entropy.cpp
index 3617edb83d..c3ae7a1718 100644
--- a/util/random/entropy.cpp
+++ b/util/random/entropy.cpp
@@ -160,7 +160,7 @@ namespace {
#define DO_STEP(type) \
while (len >= sizeof(type)) { \
- WriteUnaligned<type>(buf, RandomNumber<type>()); \
+ WriteUnaligned<type>(buf, RandomNumber<type>()); \
buf += sizeof(type); \
len -= sizeof(type); \
}
diff --git a/util/random/normal_ut.cpp b/util/random/normal_ut.cpp
index 42b6cc4ba2..8968f9e571 100644
--- a/util/random/normal_ut.cpp
+++ b/util/random/normal_ut.cpp
@@ -31,13 +31,13 @@ Y_UNIT_TEST_SUITE(TestNormalDistribution) {
mm += x;
}
- mm /= v.size();
+ mm /= v.size();
for (auto x : v) {
vv += (mm - x) * (mm - x);
}
- vv /= v.size();
+ vv /= v.size();
long double dd = std::sqrt(vv);
diff --git a/util/str_stl.h b/util/str_stl.h
index f1e137181d..a8fe450e62 100644
--- a/util/str_stl.h
+++ b/util/str_stl.h
@@ -222,14 +222,14 @@ struct TCIEqualTo<const char*> {
template <>
struct TCIEqualTo<TStringBuf> {
inline bool operator()(const TStringBuf a, const TStringBuf b) const {
- return a.size() == b.size() && strnicmp(a.data(), b.data(), a.size()) == 0;
+ return a.size() == b.size() && strnicmp(a.data(), b.data(), a.size()) == 0;
}
};
template <>
struct TCIEqualTo<TString> {
inline bool operator()(const TString& a, const TString& b) const {
- return a.size() == b.size() && strnicmp(a.data(), b.data(), a.size()) == 0;
+ return a.size() == b.size() && strnicmp(a.data(), b.data(), a.size()) == 0;
}
};
diff --git a/util/stream/buffer.cpp b/util/stream/buffer.cpp
index 2facece4ea..d42b193a5f 100644
--- a/util/stream/buffer.cpp
+++ b/util/stream/buffer.cpp
@@ -109,7 +109,7 @@ void TBufferInput::Rewind() noexcept {
size_t TBufferInput::DoNext(const void** ptr, size_t len) {
len = Min(Buf_.Size() - Readed_, len);
- *ptr = Buf_.data() + Readed_;
+ *ptr = Buf_.data() + Readed_;
Readed_ += len;
return len;
}
diff --git a/util/stream/buffer_ut.cpp b/util/stream/buffer_ut.cpp
index 3494696190..28fe961809 100644
--- a/util/stream/buffer_ut.cpp
+++ b/util/stream/buffer_ut.cpp
@@ -67,12 +67,12 @@ Y_UNIT_TEST_SUITE(TBufferTest) {
<< "4444"
<< "55555";
- UNIT_ASSERT(0 == memcmp(buffer.data(), "1"
+ UNIT_ASSERT(0 == memcmp(buffer.data(), "1"
"22"
"333"
"4444"
"55555",
- buffer.size()));
+ buffer.size()));
}
Y_UNIT_TEST(WriteChars) {
@@ -80,6 +80,6 @@ Y_UNIT_TEST_SUITE(TBufferTest) {
TBufferOutput output(buffer);
output << '1' << '2' << '3' << '4' << '5' << '6' << '7' << '8' << '9' << '0';
- UNIT_ASSERT(0 == memcmp(buffer.data(), "1234567890", buffer.size()));
+ UNIT_ASSERT(0 == memcmp(buffer.data(), "1234567890", buffer.size()));
}
}
diff --git a/util/stream/buffered_ut.cpp b/util/stream/buffered_ut.cpp
index 41d2fc3030..ebcd31ae3f 100644
--- a/util/stream/buffered_ut.cpp
+++ b/util/stream/buffered_ut.cpp
@@ -18,7 +18,7 @@ Y_UNIT_TEST_SUITE(TestBufferedIO) {
s.append('A' + (r.GenRand() % 10));
}
- out.Write(s.data(), s.size());
+ out.Write(s.data(), s.size());
}
}
diff --git a/util/stream/format.h b/util/stream/format.h
index b033208a1b..c88ea3a1e0 100644
--- a/util/stream/format.h
+++ b/util/stream/format.h
@@ -144,7 +144,7 @@ namespace NFormatPrivate {
template <typename Char, size_t Base>
IOutputStream& operator<<(IOutputStream& os, const TBaseText<Char, Base>& text) {
- for (size_t i = 0; i < text.Text.size(); ++i) {
+ for (size_t i = 0; i < text.Text.size(); ++i) {
if (i != 0) {
os << ' ';
}
diff --git a/util/stream/hex_ut.cpp b/util/stream/hex_ut.cpp
index 5074a0b616..f788d38233 100644
--- a/util/stream/hex_ut.cpp
+++ b/util/stream/hex_ut.cpp
@@ -7,13 +7,13 @@ Y_UNIT_TEST_SUITE(THexCodingTest) {
void TestImpl(const TString& data) {
TString encoded;
TStringOutput encodedOut(encoded);
- HexEncode(data.data(), data.size(), encodedOut);
+ HexEncode(data.data(), data.size(), encodedOut);
- UNIT_ASSERT_EQUAL(encoded.size(), data.size() * 2);
+ UNIT_ASSERT_EQUAL(encoded.size(), data.size() * 2);
TString decoded;
TStringOutput decodedOut(decoded);
- HexDecode(encoded.data(), encoded.size(), decodedOut);
+ HexDecode(encoded.data(), encoded.size(), decodedOut);
UNIT_ASSERT_EQUAL(decoded, data);
}
diff --git a/util/stream/input_ut.cpp b/util/stream/input_ut.cpp
index 4a93f5458e..8d3b1bad0d 100644
--- a/util/stream/input_ut.cpp
+++ b/util/stream/input_ut.cpp
@@ -23,7 +23,7 @@ public:
template <typename FuncType>
void ForInput(const TStringBuf text, const FuncType& func) {
TFile tempFile(TFile::Temporary("input_ut"));
- tempFile.Write(text.data(), text.size());
+ tempFile.Write(text.data(), text.size());
tempFile.FlushData();
tempFile.Seek(0, sSet);
diff --git a/util/stream/ios_ut.cpp b/util/stream/ios_ut.cpp
index 139f4296e5..2f08fc57ba 100644
--- a/util/stream/ios_ut.cpp
+++ b/util/stream/ios_ut.cpp
@@ -191,7 +191,7 @@ public:
s.append((const char*)p[i].buf, p[i].len);
}
- DoWrite(s.data(), s.size());
+ DoWrite(s.data(), s.size());
}
private:
@@ -210,13 +210,13 @@ void TStreamsTest::TestBufferedIO() {
TString str(" ");
str += ToString(i % 10);
- bo.Write(str.data(), str.size());
+ bo.Write(str.data(), str.size());
}
bo.Finish();
}
- UNIT_ASSERT_EQUAL(s.size(), 2000);
+ UNIT_ASSERT_EQUAL(s.size(), 2000);
{
const size_t buflen = 11;
@@ -248,7 +248,7 @@ void TStreamsTest::TestBufferedIO() {
}
for (size_t i = 0; i < 1000; ++i) {
- bo.Write(f.data(), i);
+ bo.Write(f.data(), i);
}
bo.Finish();
@@ -259,13 +259,13 @@ void TStreamsTest::TestBufferStream() {
TBufferStream stream;
TString s = "test";
- stream.Write(s.data(), s.size());
+ stream.Write(s.data(), s.size());
char buf[5];
size_t bytesRead = stream.Read(buf, 4);
UNIT_ASSERT_EQUAL(4, bytesRead);
- UNIT_ASSERT_EQUAL(0, strncmp(s.data(), buf, 4));
+ UNIT_ASSERT_EQUAL(0, strncmp(s.data(), buf, 4));
- stream.Write(s.data(), s.size());
+ stream.Write(s.data(), s.size());
bytesRead = stream.Read(buf, 2);
UNIT_ASSERT_EQUAL(2, bytesRead);
UNIT_ASSERT_EQUAL(0, strncmp("te", buf, 2));
@@ -382,9 +382,9 @@ namespace {
void TestStreamReadTo(const TString& text, T test) {
TStringInput is(text);
test(is, "TStringInput");
- TMemoryInput mi(text.data(), text.size());
+ TMemoryInput mi(text.data(), text.size());
test(mi, "TMemoryInput");
- TBuffer b(text.data(), text.size());
+ TBuffer b(text.data(), text.size());
TBufferInput bi(b);
test(bi, "TBufferInput");
TStringInput slave(text);
@@ -409,7 +409,7 @@ void TStreamsTest::TestStrokaInput() {
TString s;
for (ui32 i = 0; i < 100000; ++i) {
TVector<char> d(i % 1000, 'a');
- s.append(d.data(), d.size());
+ s.append(d.data(), d.size());
s.append('\n');
}
TestStreamReadTo(s, ::TestStrokaInput);
diff --git a/util/stream/length_ut.cpp b/util/stream/length_ut.cpp
index 8968448954..11ff8e8c8a 100644
--- a/util/stream/length_ut.cpp
+++ b/util/stream/length_ut.cpp
@@ -45,7 +45,7 @@ Y_UNIT_TEST_SUITE(TestLengthIO) {
UNIT_ASSERT_VALUES_EQUAL(l1.Counter(), 5);
TString buf("aaa");
- IOutputStream::TPart parts[] = {{buf.data(), buf.size()}, {buf.data(), buf.size()}, {buf.data(), buf.size()}};
+ IOutputStream::TPart parts[] = {{buf.data(), buf.size()}, {buf.data(), buf.size()}, {buf.data(), buf.size()}};
l1.Write(parts, 3);
UNIT_ASSERT_VALUES_EQUAL(l1.Counter(), 14);
}
diff --git a/util/stream/mem.cpp b/util/stream/mem.cpp
index 22a3339e27..279a276ee8 100644
--- a/util/stream/mem.cpp
+++ b/util/stream/mem.cpp
@@ -15,8 +15,8 @@ TMemoryInput::TMemoryInput(const void* buf, size_t len) noexcept
}
TMemoryInput::TMemoryInput(const TStringBuf buf) noexcept
- : Buf_(buf.data())
- , Len_(buf.size())
+ : Buf_(buf.data())
+ , Len_(buf.size())
{
}
diff --git a/util/stream/output.cpp b/util/stream/output.cpp
index db81b81b70..2ca09137f8 100644
--- a/util/stream/output.cpp
+++ b/util/stream/output.cpp
@@ -91,7 +91,7 @@ static void WriteString(IOutputStream& o, const wchar32* w, size_t n) {
template <>
void Out<TString>(IOutputStream& o, const TString& p) {
- o.Write(p.data(), p.size());
+ o.Write(p.data(), p.size());
}
template <>
diff --git a/util/stream/output.h b/util/stream/output.h
index 00eef50b95..cf45957b99 100644
--- a/util/stream/output.h
+++ b/util/stream/output.h
@@ -31,8 +31,8 @@ public:
}
inline TPart(const TStringBuf s) noexcept
- : buf(s.data())
- , len(s.size())
+ : buf(s.data())
+ , len(s.size())
{
}
@@ -80,7 +80,7 @@ public:
* @param st String to write.
*/
inline void Write(const TStringBuf st) {
- Write(st.data(), st.size());
+ Write(st.data(), st.size());
}
/**
diff --git a/util/stream/pipe.cpp b/util/stream/pipe.cpp
index 51be1934a7..ecbb9b96d3 100644
--- a/util/stream/pipe.cpp
+++ b/util/stream/pipe.cpp
@@ -15,7 +15,7 @@ public:
ythrow TSystemError(EINVAL) << "pipe \"r+\" mode is implemented only on FreeBSD";
}
#endif
- Pipe_ = ::popen(command.data(), mode);
+ 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..847c45cfb3 100644
--- a/util/stream/printf_ut.cpp
+++ b/util/stream/printf_ut.cpp
@@ -26,7 +26,7 @@ Y_UNIT_TEST_SUITE(TStreamPrintfTest) {
TString s = NUnitTest::RandomString(1000000);
TStringStream ss;
- Printf(ss, "%s", s.data());
+ Printf(ss, "%s", s.data());
UNIT_ASSERT_EQUAL(ss.Str(), s);
}
diff --git a/util/stream/str.h b/util/stream/str.h
index 028bd572c0..a956d1597d 100644
--- a/util/stream/str.h
+++ b/util/stream/str.h
@@ -169,7 +169,7 @@ public:
* to be null-terminated.
*/
inline const char* Data() const noexcept {
- return Ptr()->data();
+ return Ptr()->data();
}
/**
@@ -179,7 +179,7 @@ public:
* available for reading.
*/
inline size_t Size() const noexcept {
- return Ptr()->size();
+ return Ptr()->size();
}
/**
diff --git a/util/stream/tokenizer_ut.cpp b/util/stream/tokenizer_ut.cpp
index afc566da86..f149209fb0 100644
--- a/util/stream/tokenizer_ut.cpp
+++ b/util/stream/tokenizer_ut.cpp
@@ -8,7 +8,7 @@
#include "tokenizer.h"
static inline void CheckIfNullTerminated(const TStringBuf str) {
- UNIT_ASSERT_VALUES_EQUAL('\0', *(str.data() + str.size()));
+ UNIT_ASSERT_VALUES_EQUAL('\0', *(str.data() + str.size()));
}
Y_UNIT_TEST_SUITE(TStreamTokenizerTests) {
diff --git a/util/stream/zlib.cpp b/util/stream/zlib.cpp
index 60f4e9439f..c672177880 100644
--- a/util/stream/zlib.cpp
+++ b/util/stream/zlib.cpp
@@ -215,8 +215,8 @@ public:
deflateSetHeader(Z(), GZHeader_.Get());
}
- if (p.Dict.size()) {
- if (deflateSetDictionary(Z(), (const Bytef*)p.Dict.data(), p.Dict.size())) {
+ if (p.Dict.size()) {
+ if (deflateSetDictionary(Z(), (const Bytef*)p.Dict.data(), p.Dict.size())) {
ythrow TZLibCompressorError() << "can not set deflate dictionary";
}
}
diff --git a/util/string/ascii_ut.cpp b/util/string/ascii_ut.cpp
index 89069fee50..5c35f3bda5 100644
--- a/util/string/ascii_ut.cpp
+++ b/util/string/ascii_ut.cpp
@@ -74,9 +74,9 @@ Y_UNIT_TEST_SUITE(TAsciiTest) {
TString z = "qQnB";
TString zz = "qQqq";
TString zzz = "qQqqq";
- TStringBuf xs = TStringBuf(x.data(), 3);
- TStringBuf ys = TStringBuf(y.data(), 3);
- TStringBuf zs = TStringBuf(z.data(), 3);
+ TStringBuf xs = TStringBuf(x.data(), 3);
+ TStringBuf ys = TStringBuf(y.data(), 3);
+ TStringBuf zs = TStringBuf(z.data(), 3);
UNIT_ASSERT(AsciiCompareIgnoreCase(xs, ys) == 0);
UNIT_ASSERT(AsciiCompareIgnoreCase(xs, zs) > 0);
UNIT_ASSERT(AsciiCompareIgnoreCase(xs, zz) < 0);
diff --git a/util/string/cast.h b/util/string/cast.h
index 90e925c194..a27f5838bd 100644
--- a/util/string/cast.h
+++ b/util/string/cast.h
@@ -152,12 +152,12 @@ inline T FromString(const TChar* data) {
template <class T>
inline T FromString(const TStringBuf& s) {
- return ::FromString<T>(s.data(), s.size());
+ return ::FromString<T>(s.data(), s.size());
}
template <class T>
inline T FromString(const TString& s) {
- return ::FromString<T>(s.data(), s.size());
+ return ::FromString<T>(s.data(), s.size());
}
template <class T>
@@ -172,7 +172,7 @@ inline TString FromString<TString>(const TString& s) {
template <class T>
inline T FromString(const TWtringBuf& s) {
- return ::FromString<T, typename TWtringBuf::char_type>(s.data(), s.size());
+ return ::FromString<T, typename TWtringBuf::char_type>(s.data(), s.size());
}
template <class T>
@@ -212,7 +212,7 @@ inline ::NPrivate::TFromString<TChar> FromString(const TChar* data) {
template <typename T>
inline ::NPrivate::TFromString<typename T::TChar> FromString(const T& s) {
- return ::NPrivate::TFromString<typename T::TChar>(s.data(), s.size());
+ return ::NPrivate::TFromString<typename T::TChar>(s.data(), s.size());
}
// Conversion exception free versions
@@ -247,12 +247,12 @@ inline bool TryFromString(const TChar* data, const size_t len, T& result, const
template <class T>
inline bool TryFromString(const TStringBuf& s, T& result) {
- return TryFromString<T>(s.data(), s.size(), result);
+ return TryFromString<T>(s.data(), s.size(), result);
}
template <class T>
inline bool TryFromString(const TString& s, T& result) {
- return TryFromString<T>(s.data(), s.size(), result);
+ return TryFromString<T>(s.data(), s.size(), result);
}
template <class T>
@@ -262,17 +262,17 @@ inline bool TryFromString(const std::string& s, T& result) {
template <class T>
inline bool TryFromString(const TWtringBuf& s, T& result) {
- return TryFromString<T>(s.data(), s.size(), result);
+ return TryFromString<T>(s.data(), s.size(), result);
}
template <class T>
inline bool TryFromString(const TUtf16String& s, T& result) {
- return TryFromString<T>(s.data(), s.size(), result);
+ return TryFromString<T>(s.data(), s.size(), result);
}
template <class T, class TStringType>
inline bool TryFromStringWithDefault(const TStringType& s, T& result, const T& def) {
- return TryFromString<T>(s.data(), s.size(), result, def);
+ return TryFromString<T>(s.data(), s.size(), result, def);
}
template <class T>
@@ -295,7 +295,7 @@ inline T FromString(const TChar* data, const size_t len, const T& def) {
template <class T, class TStringType>
inline T FromStringWithDefault(const TStringType& s, const T& def) {
- return FromString<T>(s.data(), s.size(), def);
+ return FromString<T>(s.data(), s.size(), def);
}
template <class T>
@@ -328,7 +328,7 @@ bool TryIntFromString(const TChar* data, size_t len, TInt& result);
template <int base, class TInt, class TStringType>
inline bool TryIntFromString(const TStringType& s, TInt& result) {
- return TryIntFromString<base>(s.data(), s.size(), result);
+ return TryIntFromString<base>(s.data(), s.size(), result);
}
template <class TInt, int base, class TChar>
@@ -341,7 +341,7 @@ inline TInt IntFromString(const TChar* str) {
template <class TInt, int base, class TStringType>
inline TInt IntFromString(const TStringType& str) {
- return IntFromString<TInt, base>(str.data(), str.size());
+ return IntFromString<TInt, base>(str.data(), str.size());
}
static inline TString ToString(const TStringBuf str) {
diff --git a/util/string/cast_ut.cpp b/util/string/cast_ut.cpp
index 033450c38c..0b2ca39dc7 100644
--- a/util/string/cast_ut.cpp
+++ b/util/string/cast_ut.cpp
@@ -324,7 +324,7 @@ Y_UNIT_TEST_SUITE(TCastTest) {
TString a = "xyz";
TStringBuf b = FromString<TStringBuf>(a);
UNIT_ASSERT_VALUES_EQUAL(a, b);
- UNIT_ASSERT_VALUES_EQUAL((void*)a.data(), (void*)b.data());
+ UNIT_ASSERT_VALUES_EQUAL((void*)a.data(), (void*)b.data());
}
#if 0
@@ -360,14 +360,14 @@ Y_UNIT_TEST_SUITE(TCastTest) {
UNIT_ASSERT_VALUES_EQUAL(TryFromString(uw, uv), true);
UNIT_ASSERT_VALUES_EQUAL(uv, 21474836470ull);
- TWtringBuf bw(uw.data(), uw.size());
+ TWtringBuf bw(uw.data(), uw.size());
uv = 0;
UNIT_ASSERT_VALUES_EQUAL(TryFromString(uw, uv), true);
UNIT_ASSERT_VALUES_EQUAL(uv, 21474836470ull);
- const wchar16* beg = uw.data();
+ const wchar16* beg = uw.data();
uv = 0;
- UNIT_ASSERT_VALUES_EQUAL(TryFromString(beg, uw.size(), uv), true);
+ UNIT_ASSERT_VALUES_EQUAL(TryFromString(beg, uw.size(), uv), true);
UNIT_ASSERT_VALUES_EQUAL(uv, 21474836470ull);
}
diff --git a/util/string/escape.cpp b/util/string/escape.cpp
index cd09a7dbd0..2e8428308e 100644
--- a/util/string/escape.cpp
+++ b/util/string/escape.cpp
@@ -401,33 +401,33 @@ template size_t UnescapeCCharLen<char>(const char* begin, const char* end);
template size_t UnescapeCCharLen<TUtf16String::TChar>(const TUtf16String::TChar* begin, const TUtf16String::TChar* end);
TString& EscapeC(const TStringBuf str, TString& s) {
- return EscapeC(str.data(), str.size(), s);
+ return EscapeC(str.data(), str.size(), s);
}
TUtf16String& EscapeC(const TWtringBuf str, TUtf16String& w) {
- return EscapeC(str.data(), str.size(), w);
+ return EscapeC(str.data(), str.size(), w);
}
TString EscapeC(const TString& str) {
- return EscapeC(str.data(), str.size());
+ return EscapeC(str.data(), str.size());
}
TUtf16String EscapeC(const TUtf16String& str) {
- return EscapeC(str.data(), str.size());
+ return EscapeC(str.data(), str.size());
}
TString& UnescapeC(const TStringBuf str, TString& s) {
- return UnescapeC(str.data(), str.size(), s);
+ return UnescapeC(str.data(), str.size(), s);
}
TUtf16String& UnescapeC(const TWtringBuf str, TUtf16String& w) {
- return UnescapeC(str.data(), str.size(), w);
+ return UnescapeC(str.data(), str.size(), w);
}
TString UnescapeC(const TStringBuf str) {
- return UnescapeC(str.data(), str.size());
+ return UnescapeC(str.data(), str.size());
}
TUtf16String UnescapeC(const TWtringBuf str) {
- return UnescapeC(str.data(), str.size());
+ return UnescapeC(str.data(), str.size());
}
diff --git a/util/string/escape.h b/util/string/escape.h
index b01be65b0e..b45a4494b6 100644
--- a/util/string/escape.h
+++ b/util/string/escape.h
@@ -25,7 +25,7 @@ static inline TBasicString<TChar> EscapeC(const TChar* str, size_t len) {
template <typename TChar>
static inline TBasicString<TChar> EscapeC(const TBasicStringBuf<TChar>& str) {
- return EscapeC(str.data(), str.size());
+ return EscapeC(str.data(), str.size());
}
template <typename TChar>
diff --git a/util/string/escape_ut.cpp b/util/string/escape_ut.cpp
index cd38ecffd3..9d557621c5 100644
--- a/util/string/escape_ut.cpp
+++ b/util/string/escape_ut.cpp
@@ -135,7 +135,7 @@ Y_UNIT_TEST_SUITE(TEscapeCTest) {
char buf[100000];
for (const auto& x : CommonTestData) {
- char* end = UnescapeC(x.Expected.data(), x.Expected.size(), buf);
+ char* end = UnescapeC(x.Expected.data(), x.Expected.size(), buf);
UNIT_ASSERT_VALUES_EQUAL(x.Source, TStringBuf(buf, end));
}
diff --git a/util/string/hex.h b/util/string/hex.h
index af3d2d528f..212d22dcc5 100644
--- a/util/string/hex.h
+++ b/util/string/hex.h
@@ -31,7 +31,7 @@ char* HexEncode(const void* in, size_t len, char* out);
TString HexEncode(const void* in, size_t len);
inline TString HexEncode(const TStringBuf h) {
- return HexEncode(h.data(), h.size());
+ return HexEncode(h.data(), h.size());
}
//! Convert a hex string @c in of @c len chars (case-insensitive) to array of ints stored at @c ptr and return this array.
@@ -55,5 +55,5 @@ TString HexDecode(const void* in, size_t len);
//! Convert an ASCII hex-string (case-insensitive) to the binary form. Note that h.Size() must be even (+h % 2 == 0).
inline TString HexDecode(const TStringBuf h) {
- return HexDecode(h.data(), h.size());
+ return HexDecode(h.data(), h.size());
}
diff --git a/util/string/split.cpp b/util/string/split.cpp
index 7d26857cc7..9b193e9459 100644
--- a/util/string/split.cpp
+++ b/util/string/split.cpp
@@ -20,5 +20,5 @@ size_t Split(const char* ptr, const char* delim, TVector<TString>& values) {
}
size_t Split(const TString& in, const TString& delim, TVector<TString>& res) {
- return Split(in.data(), delim.data(), res);
+ return Split(in.data(), delim.data(), res);
}
diff --git a/util/string/split.h b/util/string/split.h
index bc46d9e64c..5e03d89344 100644
--- a/util/string/split.h
+++ b/util/string/split.h
@@ -3,24 +3,24 @@
#include "strspn.h"
#include "cast.h"
-#include <util/generic/algorithm.h>
+#include <util/generic/algorithm.h>
#include <util/generic/fwd.h>
-#include <util/generic/iterator.h>
-#include <util/generic/iterator_range.h>
-#include <util/generic/store_policy.h>
-#include <util/generic/strbuf.h>
+#include <util/generic/iterator.h>
+#include <util/generic/iterator_range.h>
+#include <util/generic/store_policy.h>
+#include <util/generic/strbuf.h>
#include <util/generic/string.h>
#include <util/generic/typetraits.h>
-#include <util/generic/vector.h>
+#include <util/generic/vector.h>
#include <util/generic/ylimits.h>
-#include <util/system/compat.h>
-#include <util/system/defaults.h>
+#include <util/system/compat.h>
+#include <util/system/defaults.h>
-#include <utility>
-#include <stlfwd>
-
-// NOTE: Check StringSplitter below to get more convenient split string interface.
+#include <utility>
+#include <stlfwd>
+// NOTE: Check StringSplitter below to get more convenient split string interface.
+
namespace NStringSplitPrivate {
template <class T, class I, class = void>
@@ -420,7 +420,7 @@ inline size_t Split(const TStringBuf s, const TSetDelimiter<const char>& delim,
res.clear();
TContainerConsumer<TVector<TStringBuf>> res1(&res);
TSkipEmptyTokens<TContainerConsumer<TVector<TStringBuf>>> consumer(&res1);
- SplitString(s.data(), s.data() + s.size(), delim, consumer);
+ SplitString(s.data(), s.data() + s.size(), delim, consumer);
return res.size();
}
@@ -455,218 +455,218 @@ void Split(TStringBuf s, D delim, P1& p1, P2& p2, Other&... other) {
GetNext(s, delim, p1);
Split(s, delim, p2, other...);
}
-
-/**
- * \fn auto StringSplitter(...)
- *
- * Creates a string splitter object. The only use for it is to call one of its
- * `Split*` methods, and then do something with the resulting proxy range.
- *
- * Some examples:
- * \code
- * TVector<TStringBuf> values = StringSplitter("1\t2\t3").Split('\t');
- *
- * for(TStringBuf part: StringSplitter("1::2::::3").SplitByString("::").SkipEmpty()) {
- * Cerr << part;
- * }
- *
- * TVector<TString> firstTwoValues = StringSplitter("1\t2\t3").Split('\t').Take(2);
- * \endcode
- *
- * Use `Collect` or `AddTo` to store split results into an existing container:
- * \code
- * TVector<TStringBuf> values = {"0"};
- * StringSplitter("1\t2\t3").Split('\t').AddTo(&values);
- * \endcode
- * Note that `Collect` clears target container, while `AddTo` just inserts values.
- * You can use these methods with any container that has `emplace` / `emplace_back`.
- *
- * Use `ParseInto` to also perform string conversions before inserting values
- * into target container:
- * \code
- * TSet<int> values;
- * StringSplitter("1\t2\t3").Split('\t').ParseInto(&values);
- * \endcode
- */
-
+
+/**
+ * \fn auto StringSplitter(...)
+ *
+ * Creates a string splitter object. The only use for it is to call one of its
+ * `Split*` methods, and then do something with the resulting proxy range.
+ *
+ * Some examples:
+ * \code
+ * TVector<TStringBuf> values = StringSplitter("1\t2\t3").Split('\t');
+ *
+ * for(TStringBuf part: StringSplitter("1::2::::3").SplitByString("::").SkipEmpty()) {
+ * Cerr << part;
+ * }
+ *
+ * TVector<TString> firstTwoValues = StringSplitter("1\t2\t3").Split('\t').Take(2);
+ * \endcode
+ *
+ * Use `Collect` or `AddTo` to store split results into an existing container:
+ * \code
+ * TVector<TStringBuf> values = {"0"};
+ * StringSplitter("1\t2\t3").Split('\t').AddTo(&values);
+ * \endcode
+ * Note that `Collect` clears target container, while `AddTo` just inserts values.
+ * You can use these methods with any container that has `emplace` / `emplace_back`.
+ *
+ * Use `ParseInto` to also perform string conversions before inserting values
+ * into target container:
+ * \code
+ * TSet<int> values;
+ * StringSplitter("1\t2\t3").Split('\t').ParseInto(&values);
+ * \endcode
+ */
+
namespace NStringSplitPrivate {
- Y_HAS_MEMBER(push_back, PushBack);
- Y_HAS_MEMBER(insert, Insert);
- Y_HAS_MEMBER(data, Data);
-
- /**
- * This one is needed here so that `std::string_view -> std::string_view`
- * conversion works.
- */
+ Y_HAS_MEMBER(push_back, PushBack);
+ Y_HAS_MEMBER(insert, Insert);
+ Y_HAS_MEMBER(data, Data);
+
+ /**
+ * This one is needed here so that `std::string_view -> std::string_view`
+ * conversion works.
+ */
template <class Src, class Dst>
- inline void DoFromString(const Src& src, Dst* dst) {
- *dst = ::FromString<Dst>(src);
- }
-
+ inline void DoFromString(const Src& src, Dst* dst) {
+ *dst = ::FromString<Dst>(src);
+ }
+
template <class T>
- inline void DoFromString(const T& src, T* dst) noexcept {
- *dst = src;
- }
-
+ inline void DoFromString(const T& src, T* dst) noexcept {
+ *dst = src;
+ }
+
template <class T>
inline void DoFromString(const T& src, decltype(std::ignore)* dst) noexcept {
*dst = src;
}
template <class Src, class Dst>
- inline Y_WARN_UNUSED_RESULT bool TryDoFromString(const Src& src, Dst* dst) noexcept {
- return ::TryFromString(src, *dst);
- }
-
+ inline Y_WARN_UNUSED_RESULT bool TryDoFromString(const Src& src, Dst* dst) noexcept {
+ return ::TryFromString(src, *dst);
+ }
+
template <class T>
- inline Y_WARN_UNUSED_RESULT bool TryDoFromString(const T& src, T* dst) noexcept {
- *dst = src;
- return true;
- }
-
+ inline Y_WARN_UNUSED_RESULT bool TryDoFromString(const T& src, T* dst) noexcept {
+ *dst = src;
+ return true;
+ }
+
template <class T>
inline Y_WARN_UNUSED_RESULT bool TryDoFromString(const T& src, decltype(std::ignore)* dst) noexcept {
*dst = src;
return true;
}
- /**
- * Consumer that places provided elements into a container. Not using
- * `emplace(iterator)` for efficiency.
- */
- template <class Container>
- struct TContainerConsumer {
- using value_type = typename Container::value_type;
-
- TContainerConsumer(Container* c)
- : C_(c)
- {
- }
-
- // TODO: return bool (continue)
+ /**
+ * Consumer that places provided elements into a container. Not using
+ * `emplace(iterator)` for efficiency.
+ */
+ template <class Container>
+ struct TContainerConsumer {
+ using value_type = typename Container::value_type;
+
+ TContainerConsumer(Container* c)
+ : C_(c)
+ {
+ }
+
+ // TODO: return bool (continue)
template <class StringBuf>
- void operator()(StringBuf e) const {
- this->operator()(C_, e);
- }
-
- private:
+ void operator()(StringBuf e) const {
+ this->operator()(C_, e);
+ }
+
+ private:
template <class OtherContainer, class StringBuf>
- auto operator()(OtherContainer* c, StringBuf e) const -> decltype(c->emplace_back()) {
- return c->emplace_back(value_type(e));
- }
-
+ auto operator()(OtherContainer* c, StringBuf e) const -> decltype(c->emplace_back()) {
+ return c->emplace_back(value_type(e));
+ }
+
template <class OtherContainer, class StringBuf>
- auto operator()(OtherContainer* c, StringBuf e) const -> decltype(c->emplace()) {
- return c->emplace(value_type(e));
- }
-
- Container* C_;
- };
-
- /**
- * Consumer that converts provided elements via `FromString` and places them
- * into a container.
- */
- template <class Container>
- struct TContainerConvertingConsumer {
- using value_type = typename Container::value_type;
-
- TContainerConvertingConsumer(Container* c)
- : C_(c)
- {
- }
-
- template <class StringBuf>
- void operator()(StringBuf e) const {
- this->operator()(C_, e);
- }
-
- private:
+ auto operator()(OtherContainer* c, StringBuf e) const -> decltype(c->emplace()) {
+ return c->emplace(value_type(e));
+ }
+
+ Container* C_;
+ };
+
+ /**
+ * Consumer that converts provided elements via `FromString` and places them
+ * into a container.
+ */
+ template <class Container>
+ struct TContainerConvertingConsumer {
+ using value_type = typename Container::value_type;
+
+ TContainerConvertingConsumer(Container* c)
+ : C_(c)
+ {
+ }
+
+ template <class StringBuf>
+ void operator()(StringBuf e) const {
+ this->operator()(C_, e);
+ }
+
+ private:
template <class OtherContainer, class StringBuf>
- auto operator()(OtherContainer* c, StringBuf e) const -> decltype(c->emplace_back()) {
- value_type v;
- DoFromString(e, &v);
- return c->emplace_back(std::move(v));
- }
-
+ auto operator()(OtherContainer* c, StringBuf e) const -> decltype(c->emplace_back()) {
+ value_type v;
+ DoFromString(e, &v);
+ return c->emplace_back(std::move(v));
+ }
+
template <class OtherContainer, class StringBuf>
- auto operator()(OtherContainer* c, StringBuf e) const -> decltype(c->emplace()) {
- value_type v;
- DoFromString(e, &v);
- return c->emplace(std::move(v));
- }
-
- Container* C_;
- };
-
- template <class String>
- struct TStringBufOfImpl {
- using type = std::conditional_t<
- THasData<String>::value,
- TBasicStringBuf<typename String::value_type>,
+ auto operator()(OtherContainer* c, StringBuf e) const -> decltype(c->emplace()) {
+ value_type v;
+ DoFromString(e, &v);
+ return c->emplace(std::move(v));
+ }
+
+ Container* C_;
+ };
+
+ template <class String>
+ struct TStringBufOfImpl {
+ using type = std::conditional_t<
+ THasData<String>::value,
+ TBasicStringBuf<typename String::value_type>,
TIteratorRange<typename String::const_iterator>>;
- };
-
- template <class Char, class Traits, class Allocator>
- struct TStringBufOfImpl<std::basic_string<Char, Traits, Allocator>> {
- using type = std::basic_string_view<Char, Traits>;
- };
-
- template <class Char, class Traits>
- struct TStringBufOfImpl<std::basic_string_view<Char, Traits>> {
- using type = std::basic_string_view<Char, Traits>;
- };
-
- /**
- * Metafunction that returns a string buffer for the given type. This is to
- * make sure that splitting `std::string` returns `std::string_view`.
- */
+ };
+
+ template <class Char, class Traits, class Allocator>
+ struct TStringBufOfImpl<std::basic_string<Char, Traits, Allocator>> {
+ using type = std::basic_string_view<Char, Traits>;
+ };
+
+ template <class Char, class Traits>
+ struct TStringBufOfImpl<std::basic_string_view<Char, Traits>> {
+ using type = std::basic_string_view<Char, Traits>;
+ };
+
+ /**
+ * Metafunction that returns a string buffer for the given type. This is to
+ * make sure that splitting `std::string` returns `std::string_view`.
+ */
template <class String>
- using TStringBufOf = typename TStringBufOfImpl<String>::type;
-
+ using TStringBufOf = typename TStringBufOfImpl<String>::type;
+
template <class StringBuf, class Iterator>
- StringBuf DoMakeStringBuf(Iterator b, Iterator e, StringBuf*) {
- return StringBuf(b, e);
- }
-
+ StringBuf DoMakeStringBuf(Iterator b, Iterator e, StringBuf*) {
+ return StringBuf(b, e);
+ }
+
template <class Char, class Traits, class Iterator>
- std::basic_string_view<Char, Traits> DoMakeStringBuf(Iterator b, Iterator e, std::basic_string_view<Char, Traits>*) {
- return std::basic_string_view<Char, Traits>(b, e - b);
- }
-
+ std::basic_string_view<Char, Traits> DoMakeStringBuf(Iterator b, Iterator e, std::basic_string_view<Char, Traits>*) {
+ return std::basic_string_view<Char, Traits>(b, e - b);
+ }
+
template <class StringBuf, class Iterator>
- StringBuf MakeStringBuf(Iterator b, Iterator e) {
- return DoMakeStringBuf(b, e, static_cast<StringBuf*>(nullptr));
- }
-
+ StringBuf MakeStringBuf(Iterator b, Iterator e) {
+ return DoMakeStringBuf(b, e, static_cast<StringBuf*>(nullptr));
+ }
+
template <class String>
- struct TIteratorOfImpl {
- using type = std::conditional_t<
- THasData<String>::value,
- const typename String::value_type*,
+ struct TIteratorOfImpl {
+ using type = std::conditional_t<
+ THasData<String>::value,
+ const typename String::value_type*,
typename String::const_iterator>;
- };
-
+ };
+
template <class String>
- using TIteratorOf = typename TIteratorOfImpl<String>::type;
-
+ using TIteratorOf = typename TIteratorOfImpl<String>::type;
+
template <class String>
class TStringSplitter;
template <class String>
struct TIterState: public TStringBufOf<String> {
public:
- using TStringBufType = TStringBufOf<String>;
- using TIterator = TIteratorOf<String>;
+ using TStringBufType = TStringBufOf<String>;
+ using TIterator = TIteratorOf<String>;
friend class TStringSplitter<String>;
-
- TIterState(const String& string) noexcept
+
+ TIterState(const String& string) noexcept
: TStringBufType()
, DelimiterEnd_(std::begin(string))
, OriginEnd_(std::end(string))
- {
- }
-
+ {
+ }
+
template <
typename Other,
typename = std::enable_if_t<
@@ -675,397 +675,397 @@ namespace NStringSplitPrivate {
return TStringBufType(*this) == TStringBufType(toCompare);
}
- TIterator TokenStart() const noexcept {
+ TIterator TokenStart() const noexcept {
return this->begin();
- }
-
- TIterator TokenDelim() const noexcept {
+ }
+
+ TIterator TokenDelim() const noexcept {
return this->end();
- }
-
- TStringBufType Token() const noexcept {
+ }
+
+ TStringBufType Token() const noexcept {
return *this;
- }
-
- TStringBufType Delim() const noexcept {
+ }
+
+ TStringBufType Delim() const noexcept {
return MakeStringBuf<TStringBufType>(TokenDelim(), DelimiterEnd_);
- }
-
- private:
+ }
+
+ private:
void UpdateParentBuf(TIterator tokenStart, TIterator tokenDelim) noexcept {
*static_cast<TStringBufType*>(this) = MakeStringBuf<TStringBufType>(tokenStart, tokenDelim);
- }
-
+ }
+
bool DelimiterIsEmpty() const noexcept {
return TokenDelim() == DelimiterEnd_;
- }
+ }
private:
TIterator DelimiterEnd_;
const TIterator OriginEnd_;
- };
-
- template <class Base>
+ };
+
+ template <class Base>
class TSplitRange: public Base, public TInputRangeAdaptor<TSplitRange<Base>> {
- using TStringBufType = decltype(std::declval<Base>().Next()->Token());
-
- public:
- template <typename... Args>
- inline TSplitRange(Args&&... args)
- : Base(std::forward<Args>(args)...)
- {
- }
-
- template <class Consumer, std::enable_if_t<std::is_same<decltype(std::declval<Consumer>()(std::declval<TStringBufType>())), void>::value, int>* = nullptr>
- inline void Consume(Consumer&& f) {
- for (auto&& it : *this) {
- f(it.Token());
- }
- }
-
- template <class Consumer, std::enable_if_t<std::is_same<decltype(std::declval<Consumer>()(std::declval<TStringBufType>())), bool>::value, int>* = nullptr>
- inline bool Consume(Consumer&& f) {
- for (auto&& it : *this) {
- if (!f(it.Token())) {
- return false;
- }
- }
- return true;
- }
-
+ using TStringBufType = decltype(std::declval<Base>().Next()->Token());
+
+ public:
+ template <typename... Args>
+ inline TSplitRange(Args&&... args)
+ : Base(std::forward<Args>(args)...)
+ {
+ }
+
+ template <class Consumer, std::enable_if_t<std::is_same<decltype(std::declval<Consumer>()(std::declval<TStringBufType>())), void>::value, int>* = nullptr>
+ inline void Consume(Consumer&& f) {
+ for (auto&& it : *this) {
+ f(it.Token());
+ }
+ }
+
+ template <class Consumer, std::enable_if_t<std::is_same<decltype(std::declval<Consumer>()(std::declval<TStringBufType>())), bool>::value, int>* = nullptr>
+ inline bool Consume(Consumer&& f) {
+ for (auto&& it : *this) {
+ if (!f(it.Token())) {
+ return false;
+ }
+ }
+ return true;
+ }
+
template <class Container, class = std::enable_if_t<THasInsert<Container>::value || THasPushBack<Container>::value>>
- operator Container() {
- Container result;
- AddTo(&result);
- return result;
- }
-
- template <class S>
- inline TVector<S> ToList() {
- TVector<S> result;
- for (auto&& it : *this) {
- result.push_back(S(it.Token()));
- }
- return result;
- }
-
- template <class Container>
- inline void Collect(Container* c) {
- Y_ASSERT(c);
- c->clear();
- AddTo(c);
- }
-
- template <class Container>
- inline void AddTo(Container* c) {
- Y_ASSERT(c);
- TContainerConsumer<Container> consumer(c);
- Consume(consumer);
- }
-
- template <class Container>
- inline void ParseInto(Container* c) {
- Y_ASSERT(c);
- TContainerConvertingConsumer<Container> consumer(c);
- Consume(consumer);
- }
-
- // TODO: this is actually TryParseInto
- /**
- * Same as `CollectInto`, just doesn't throw.
- *
- * \param[out] args Output arguments.
- * \returns Whether parsing was successful.
- */
- template <typename... Args>
- inline bool TryCollectInto(Args*... args) noexcept {
- size_t successfullyFilled = 0;
- auto it = this->begin();
-
- //FIXME: actually, some kind of TryApplyToMany is needed in order to stop iteration upon first failure
- ApplyToMany([&](auto&& arg) {
- if (it != this->end()) {
- if (TryDoFromString(it->Token(), arg)) {
- ++successfullyFilled;
- }
- ++it;
- }
+ operator Container() {
+ Container result;
+ AddTo(&result);
+ return result;
+ }
+
+ template <class S>
+ inline TVector<S> ToList() {
+ TVector<S> result;
+ for (auto&& it : *this) {
+ result.push_back(S(it.Token()));
+ }
+ return result;
+ }
+
+ template <class Container>
+ inline void Collect(Container* c) {
+ Y_ASSERT(c);
+ c->clear();
+ AddTo(c);
+ }
+
+ template <class Container>
+ inline void AddTo(Container* c) {
+ Y_ASSERT(c);
+ TContainerConsumer<Container> consumer(c);
+ Consume(consumer);
+ }
+
+ template <class Container>
+ inline void ParseInto(Container* c) {
+ Y_ASSERT(c);
+ TContainerConvertingConsumer<Container> consumer(c);
+ Consume(consumer);
+ }
+
+ // TODO: this is actually TryParseInto
+ /**
+ * Same as `CollectInto`, just doesn't throw.
+ *
+ * \param[out] args Output arguments.
+ * \returns Whether parsing was successful.
+ */
+ template <typename... Args>
+ inline bool TryCollectInto(Args*... args) noexcept {
+ size_t successfullyFilled = 0;
+ auto it = this->begin();
+
+ //FIXME: actually, some kind of TryApplyToMany is needed in order to stop iteration upon first failure
+ ApplyToMany([&](auto&& arg) {
+ if (it != this->end()) {
+ if (TryDoFromString(it->Token(), arg)) {
+ ++successfullyFilled;
+ }
+ ++it;
+ }
}, args...);
-
- return successfullyFilled == sizeof...(args) && it == this->end();
- }
-
- // TODO: this is actually ParseInto
- /**
- * Splits and parses everything that's in this splitter into `args`.
- *
- * Example usage:
- * \code
- * int l, r;
- * StringSplitter("100*200").Split('*').CollectInto(&l, &r);
- * \endcode
- *
- * \param[out] args Output arguments.
- * \throws If not all items were parsed, or
- * if there were too many items in the split.
- */
- template <typename... Args>
- inline void CollectInto(Args*... args) {
- Y_ENSURE(TryCollectInto<Args...>(args...));
- }
-
- inline size_t Count() const {
- size_t cnt = 0;
- for (auto&& it : *this) {
- Y_UNUSED(it);
- ++cnt;
- }
- return cnt;
- }
- };
-
- template <class String>
- class TStringSplitter {
- using TStringType = String;
- using TChar = typename TStringType::value_type;
- using TIteratorState = TIterState<TStringType>;
+
+ return successfullyFilled == sizeof...(args) && it == this->end();
+ }
+
+ // TODO: this is actually ParseInto
+ /**
+ * Splits and parses everything that's in this splitter into `args`.
+ *
+ * Example usage:
+ * \code
+ * int l, r;
+ * StringSplitter("100*200").Split('*').CollectInto(&l, &r);
+ * \endcode
+ *
+ * \param[out] args Output arguments.
+ * \throws If not all items were parsed, or
+ * if there were too many items in the split.
+ */
+ template <typename... Args>
+ inline void CollectInto(Args*... args) {
+ Y_ENSURE(TryCollectInto<Args...>(args...));
+ }
+
+ inline size_t Count() const {
+ size_t cnt = 0;
+ for (auto&& it : *this) {
+ Y_UNUSED(it);
+ ++cnt;
+ }
+ return cnt;
+ }
+ };
+
+ template <class String>
+ class TStringSplitter {
+ using TStringType = String;
+ using TChar = typename TStringType::value_type;
+ using TIteratorState = TIterState<TStringType>;
using TStringBufType = typename TIteratorState::TStringBufType;
using TIterator = typename TIteratorState::TIterator;
-
- /**
- * Base class for all split ranges that actually does the splitting.
- */
- template <class DelimStorage>
- struct TSplitRangeBase {
- template <class OtherString, class... Args>
- inline TSplitRangeBase(OtherString&& s, Args&&... args)
- : String_(std::forward<OtherString>(s))
- , State_(String_)
+
+ /**
+ * Base class for all split ranges that actually does the splitting.
+ */
+ template <class DelimStorage>
+ struct TSplitRangeBase {
+ template <class OtherString, class... Args>
+ inline TSplitRangeBase(OtherString&& s, Args&&... args)
+ : String_(std::forward<OtherString>(s))
+ , State_(String_)
, Delimiter_(std::forward<Args>(args)...)
- {
- }
-
- inline TIteratorState* Next() {
+ {
+ }
+
+ inline TIteratorState* Next() {
if (State_.DelimiterIsEmpty()) {
- return nullptr;
- }
-
+ return nullptr;
+ }
+
const auto tokenBegin = State_.DelimiterEnd_;
const auto tokenEnd = Delimiter_.Ptr()->Find(State_.DelimiterEnd_, State_.OriginEnd_);
State_.UpdateParentBuf(tokenBegin, tokenEnd);
-
- return &State_;
- }
-
- private:
- TStringType String_;
- TIteratorState State_;
+
+ return &State_;
+ }
+
+ private:
+ TStringType String_;
+ TIteratorState State_;
DelimStorage Delimiter_;
- };
-
- template <class Base, class Filter>
+ };
+
+ template <class Base, class Filter>
struct TFilterRange: public Base {
- template <class... Args>
- inline TFilterRange(const Base& base, Args&&... args)
- : Base(base)
- , Filter_(std::forward<Args>(args)...)
- {
- }
-
- inline TIteratorState* Next() {
- TIteratorState* ret;
-
- do {
- ret = Base::Next();
- } while (ret && !Filter_.Accept(ret));
-
- return ret;
- }
-
- Filter Filter_;
- };
-
- struct TNonEmptyFilter {
- template <class TToken>
- inline bool Accept(const TToken* token) noexcept {
+ template <class... Args>
+ inline TFilterRange(const Base& base, Args&&... args)
+ : Base(base)
+ , Filter_(std::forward<Args>(args)...)
+ {
+ }
+
+ inline TIteratorState* Next() {
+ TIteratorState* ret;
+
+ do {
+ ret = Base::Next();
+ } while (ret && !Filter_.Accept(ret));
+
+ return ret;
+ }
+
+ Filter Filter_;
+ };
+
+ struct TNonEmptyFilter {
+ template <class TToken>
+ inline bool Accept(const TToken* token) noexcept {
return !token->empty();
- }
- };
-
- template <class TIter>
- struct TStopIteration;
-
- template <class Base>
+ }
+ };
+
+ template <class TIter>
+ struct TStopIteration;
+
+ template <class Base>
struct TFilters: public Base {
- template <class TFilter>
- using TIt = TSplitRange<TStopIteration<TFilters<TFilterRange<Base, TFilter>>>>;
-
- template <typename... Args>
- inline TFilters(Args&&... args)
- : Base(std::forward<Args>(args)...)
- {
- }
-
- inline TIt<TNonEmptyFilter> SkipEmpty() const {
+ template <class TFilter>
+ using TIt = TSplitRange<TStopIteration<TFilters<TFilterRange<Base, TFilter>>>>;
+
+ template <typename... Args>
+ inline TFilters(Args&&... args)
+ : Base(std::forward<Args>(args)...)
+ {
+ }
+
+ inline TIt<TNonEmptyFilter> SkipEmpty() const {
return {*this};
- }
- };
-
- template <class Base, class Stopper>
+ }
+ };
+
+ template <class Base, class Stopper>
struct TStopRange: public Base {
- template <typename... Args>
- inline TStopRange(const Base& base, Args&&... args)
- : Base(base)
- , Stopper_(std::forward<Args>(args)...)
- {
- }
-
- inline TIteratorState* Next() {
- TIteratorState* ret = Base::Next();
- if (!ret || Stopper_.Stop(ret)) {
- return nullptr;
- }
- return ret;
- }
-
- Stopper Stopper_;
- };
-
- struct TTake {
- TTake() = default;
-
- TTake(size_t count)
- : Count(count)
- {
- }
-
- template <class TToken>
- inline bool Stop(TToken*) noexcept {
- if (Count > 0) {
- --Count;
- return false;
- } else {
- return true;
- }
- }
-
- size_t Count = 0;
- };
-
- struct TLimit {
- TLimit() = default;
-
- TLimit(size_t count)
- : Count(count)
- {
- Y_ASSERT(Count > 0);
- }
-
- template <class TToken>
- inline bool Stop(TToken* token) noexcept {
- if (Count > 1) {
- --Count;
- return false;
- } else if (Count == 1) {
+ template <typename... Args>
+ inline TStopRange(const Base& base, Args&&... args)
+ : Base(base)
+ , Stopper_(std::forward<Args>(args)...)
+ {
+ }
+
+ inline TIteratorState* Next() {
+ TIteratorState* ret = Base::Next();
+ if (!ret || Stopper_.Stop(ret)) {
+ return nullptr;
+ }
+ return ret;
+ }
+
+ Stopper Stopper_;
+ };
+
+ struct TTake {
+ TTake() = default;
+
+ TTake(size_t count)
+ : Count(count)
+ {
+ }
+
+ template <class TToken>
+ inline bool Stop(TToken*) noexcept {
+ if (Count > 0) {
+ --Count;
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ size_t Count = 0;
+ };
+
+ struct TLimit {
+ TLimit() = default;
+
+ TLimit(size_t count)
+ : Count(count)
+ {
+ Y_ASSERT(Count > 0);
+ }
+
+ template <class TToken>
+ inline bool Stop(TToken* token) noexcept {
+ if (Count > 1) {
+ --Count;
+ return false;
+ } else if (Count == 1) {
token->DelimiterEnd_ = token->OriginEnd_;
token->UpdateParentBuf(token->TokenStart(), token->DelimiterEnd_);
- return false;
- }
- return true;
- }
-
- size_t Count = 0;
- };
-
- template <class Base>
+ return false;
+ }
+ return true;
+ }
+
+ size_t Count = 0;
+ };
+
+ template <class Base>
struct TStopIteration: public Base {
- template <class TStopper>
- using TIt = TSplitRange<TStopIteration<TFilters<TStopRange<Base, TStopper>>>>;
-
- template <typename... Args>
- inline TStopIteration(Args&&... args)
- : Base(std::forward<Args>(args)...)
- {
- }
-
- inline TIt<TTake> Take(size_t count) {
+ template <class TStopper>
+ using TIt = TSplitRange<TStopIteration<TFilters<TStopRange<Base, TStopper>>>>;
+
+ template <typename... Args>
+ inline TStopIteration(Args&&... args)
+ : Base(std::forward<Args>(args)...)
+ {
+ }
+
+ inline TIt<TTake> Take(size_t count) {
return {*this, count};
- }
-
- inline TIt<TLimit> Limit(size_t count) {
+ }
+
+ inline TIt<TLimit> Limit(size_t count) {
return {*this, count};
- }
- };
-
- template <class TPolicy>
- using TIt = TSplitRange<TStopIteration<TFilters<TSplitRangeBase<TPolicy>>>>;
-
- public:
+ }
+ };
+
+ template <class TPolicy>
+ using TIt = TSplitRange<TStopIteration<TFilters<TSplitRangeBase<TPolicy>>>>;
+
+ public:
template <class OtherString>
- explicit TStringSplitter(OtherString&& s)
- : String_(std::forward<OtherString>(s))
- {
- }
-
- //does not own TDelim
- template <class TDelim>
- inline TIt<TPtrPolicy<const TDelim>> Split(const TDelim& d) const noexcept {
+ explicit TStringSplitter(OtherString&& s)
+ : String_(std::forward<OtherString>(s))
+ {
+ }
+
+ //does not own TDelim
+ template <class TDelim>
+ inline TIt<TPtrPolicy<const TDelim>> Split(const TDelim& d) const noexcept {
return {String_, &d};
- }
-
- inline TIt<TEmbedPolicy<TCharDelimiter<const TChar>>> Split(TChar ch) const noexcept {
+ }
+
+ inline TIt<TEmbedPolicy<TCharDelimiter<const TChar>>> Split(TChar ch) const noexcept {
return {String_, ch};
- }
-
- inline TIt<TSimpleRefPolicy<TSetDelimiter<const TChar>>> SplitBySet(const TChar* set) const noexcept {
+ }
+
+ inline TIt<TSimpleRefPolicy<TSetDelimiter<const TChar>>> SplitBySet(const TChar* set) const noexcept {
return {String_, set};
- }
-
- inline TIt<TEmbedPolicy<TStringDelimiter<const TChar>>> SplitByString(const TStringBufType& str) const noexcept {
+ }
+
+ inline TIt<TEmbedPolicy<TStringDelimiter<const TChar>>> SplitByString(const TStringBufType& str) const noexcept {
return {String_, str.data(), str.size()};
- }
-
- template <class TFunc>
- inline TIt<TEmbedPolicy<TFuncDelimiter<TIterator, TFunc>>> SplitByFunc(TFunc f) const noexcept {
+ }
+
+ template <class TFunc>
+ inline TIt<TEmbedPolicy<TFuncDelimiter<TIterator, TFunc>>> SplitByFunc(TFunc f) const noexcept {
return {String_, f};
- }
-
- private:
- TStringType String_;
- };
-
+ }
+
+ private:
+ TStringType String_;
+ };
+
template <class String>
- auto MakeStringSplitter(String&& s) {
- return TStringSplitter<std::remove_reference_t<String>>(std::forward<String>(s));
- }
-}
-
-template <class Iterator>
-auto StringSplitter(Iterator begin, Iterator end) {
+ auto MakeStringSplitter(String&& s) {
+ return TStringSplitter<std::remove_reference_t<String>>(std::forward<String>(s));
+ }
+}
+
+template <class Iterator>
+auto StringSplitter(Iterator begin, Iterator end) {
return ::NStringSplitPrivate::MakeStringSplitter(TIteratorRange<Iterator>(begin, end));
-}
-
-template <class Char>
-auto StringSplitter(const Char* begin, const Char* end) {
+}
+
+template <class Char>
+auto StringSplitter(const Char* begin, const Char* end) {
return ::NStringSplitPrivate::MakeStringSplitter(TBasicStringBuf<Char>(begin, end));
-}
-
-template <class Char>
-auto StringSplitter(const Char* begin, size_t len) {
+}
+
+template <class Char>
+auto StringSplitter(const Char* begin, size_t len) {
return ::NStringSplitPrivate::MakeStringSplitter(TBasicStringBuf<Char>(begin, len));
-}
-
-template <class Char>
-auto StringSplitter(const Char* str) {
+}
+
+template <class Char>
+auto StringSplitter(const Char* str) {
return ::NStringSplitPrivate::MakeStringSplitter(TBasicStringBuf<Char>(str));
-}
-
-template <class String, std::enable_if_t<!std::is_pointer<std::remove_reference_t<String>>::value, int> = 0>
-auto StringSplitter(String& s) {
+}
+
+template <class String, std::enable_if_t<!std::is_pointer<std::remove_reference_t<String>>::value, int> = 0>
+auto StringSplitter(String& s) {
return ::NStringSplitPrivate::MakeStringSplitter(::NStringSplitPrivate::TStringBufOf<String>(s.data(), s.size()));
-}
-
-template <class String, std::enable_if_t<!std::is_pointer<std::remove_reference_t<String>>::value, int> = 0>
-auto StringSplitter(String&& s) {
+}
+
+template <class String, std::enable_if_t<!std::is_pointer<std::remove_reference_t<String>>::value, int> = 0>
+auto StringSplitter(String&& s) {
return ::NStringSplitPrivate::MakeStringSplitter(std::move(s));
-}
+}
diff --git a/util/string/split_ut.cpp b/util/string/split_ut.cpp
index 43e59f2d75..f8cd78cb88 100644
--- a/util/string/split_ut.cpp
+++ b/util/string/split_ut.cpp
@@ -7,9 +7,9 @@
#include <util/datetime/cputimer.h>
#include <util/generic/maybe.h>
-#include <string>
-#include <string_view>
-
+#include <string>
+#include <string_view>
+
template <typename T>
static inline void OldSplit(char* pszBuf, T* pRes) {
pRes->resize(0);
@@ -126,8 +126,8 @@ Y_UNIT_TEST_SUITE(SplitStringTest) {
TVector<TString> good(canonic, canonic + 4);
TCharDelimiter<const char> delim(' ');
- TestDelimiterOnString<TContainerConsumer>(good, data.data(), delim);
- TestDelimiterOnRange<TContainerConsumer>(good, data.data(), data.end(), delim);
+ TestDelimiterOnString<TContainerConsumer>(good, data.data(), delim);
+ TestDelimiterOnRange<TContainerConsumer>(good, data.data(), data.end(), delim);
}
Y_UNIT_TEST(TestWideSingleDelimiter) {
@@ -136,8 +136,8 @@ Y_UNIT_TEST_SUITE(SplitStringTest) {
TVector<TUtf16String> good(canonic, canonic + 4);
TCharDelimiter<const wchar16> delim(' ');
- TestDelimiterOnString<TContainerConsumer>(good, data.data(), delim);
- TestDelimiterOnRange<TContainerConsumer>(good, data.data(), data.end(), delim);
+ TestDelimiterOnString<TContainerConsumer>(good, data.data(), delim);
+ TestDelimiterOnRange<TContainerConsumer>(good, data.data(), data.end(), delim);
}
Y_UNIT_TEST(TestConvertToIntCharSingleDelimiter) {
@@ -146,8 +146,8 @@ Y_UNIT_TEST_SUITE(SplitStringTest) {
TVector<i32> good(canonic, canonic + 4);
TCharDelimiter<const char> delim(' ');
- TestDelimiterOnString<TContainerConvertingConsumer>(good, data.data(), delim);
- TestDelimiterOnRange<TContainerConvertingConsumer>(good, data.data(), data.end(), delim);
+ TestDelimiterOnString<TContainerConvertingConsumer>(good, data.data(), delim);
+ TestDelimiterOnRange<TContainerConvertingConsumer>(good, data.data(), data.end(), delim);
}
Y_UNIT_TEST(TestCharSkipEmpty) {
@@ -155,8 +155,8 @@ Y_UNIT_TEST_SUITE(SplitStringTest) {
TString canonic[] = {"qw", "ab", "qwabcab"};
TVector<TString> good(canonic, canonic + 3);
- TestConsumerOnString<TSkipEmptyTokens<TStrokaConsumer>>(good, data.data(), " ");
- TestConsumerOnRange<TSkipEmptyTokens<TStrokaConsumer>>(good, data.data(), data.end(), " ");
+ TestConsumerOnString<TSkipEmptyTokens<TStrokaConsumer>>(good, data.data(), " ");
+ TestConsumerOnRange<TSkipEmptyTokens<TStrokaConsumer>>(good, data.data(), data.end(), " ");
}
Y_UNIT_TEST(TestCharKeepDelimiters) {
@@ -164,8 +164,8 @@ Y_UNIT_TEST_SUITE(SplitStringTest) {
TString canonic[] = {"qw", " ", "ab", " ", "", " ", "qwabcab", " ", ""};
TVector<TString> good(canonic, canonic + 9);
- TestConsumerOnString<TKeepDelimiters<TStrokaConsumer>>(good, data.data(), " ");
- TestConsumerOnRange<TKeepDelimiters<TStrokaConsumer>>(good, data.data(), data.end(), " ");
+ TestConsumerOnString<TKeepDelimiters<TStrokaConsumer>>(good, data.data(), " ");
+ TestConsumerOnRange<TKeepDelimiters<TStrokaConsumer>>(good, data.data(), data.end(), " ");
}
Y_UNIT_TEST(TestCharLimit) {
@@ -173,8 +173,8 @@ Y_UNIT_TEST_SUITE(SplitStringTest) {
TString canonic[] = {"qw", "ab"};
TVector<TString> good(canonic, canonic + 2);
- TestLimitingConsumerOnString(good, data.data(), " ", 3, " qwabcab ");
- TestLimitingConsumerOnRange(good, data.data(), data.end(), " ", 3, " qwabcab ");
+ TestLimitingConsumerOnString(good, data.data(), " ", 3, " qwabcab ");
+ TestLimitingConsumerOnRange(good, data.data(), data.end(), " ", 3, " qwabcab ");
}
Y_UNIT_TEST(TestCharStringDelimiter) {
@@ -183,8 +183,8 @@ Y_UNIT_TEST_SUITE(SplitStringTest) {
TVector<TString> good(canonic, canonic + 5);
TStringDelimiter<const char> delim("ab");
- TestDelimiterOnString<TContainerConsumer>(good, data.data(), delim);
- TestDelimiterOnRange<TContainerConsumer>(good, data.data(), data.end(), delim);
+ TestDelimiterOnString<TContainerConsumer>(good, data.data(), delim);
+ TestDelimiterOnRange<TContainerConsumer>(good, data.data(), data.end(), delim);
}
Y_UNIT_TEST(TestWideStringDelimiter) {
@@ -194,8 +194,8 @@ Y_UNIT_TEST_SUITE(SplitStringTest) {
TUtf16String wideDelim(u"ab");
TStringDelimiter<const wchar16> delim(wideDelim.data());
- TestDelimiterOnString<TContainerConsumer>(good, data.data(), delim);
- TestDelimiterOnRange<TContainerConsumer>(good, data.data(), data.end(), delim);
+ TestDelimiterOnString<TContainerConsumer>(good, data.data(), delim);
+ TestDelimiterOnRange<TContainerConsumer>(good, data.data(), data.end(), delim);
}
Y_UNIT_TEST(TestCharSetDelimiter) {
@@ -204,8 +204,8 @@ Y_UNIT_TEST_SUITE(SplitStringTest) {
TVector<TString> good(canonic, canonic + 5);
TSetDelimiter<const char> delim("wc");
- TestDelimiterOnString<TContainerConsumer>(good, data.data(), delim);
- TestDelimiterOnRange<TContainerConsumer>(good, data.data(), data.end(), delim);
+ TestDelimiterOnString<TContainerConsumer>(good, data.data(), delim);
+ TestDelimiterOnRange<TContainerConsumer>(good, data.data(), data.end(), delim);
}
Y_UNIT_TEST(TestWideSetDelimiter) {
@@ -215,7 +215,7 @@ Y_UNIT_TEST_SUITE(SplitStringTest) {
TUtf16String wideDelim(u"wc");
TSetDelimiter<const wchar16> delim(wideDelim.data());
- TestDelimiterOnString<TContainerConsumer>(good, data.data(), delim);
+ TestDelimiterOnString<TContainerConsumer>(good, data.data(), delim);
}
Y_UNIT_TEST(TestWideSetDelimiterRange) {
@@ -227,18 +227,18 @@ Y_UNIT_TEST_SUITE(SplitStringTest) {
TVector<TUtf16String> test;
TContainerConsumer<TVector<TUtf16String>> consumer(&test);
- SplitString(data.data(), data.data(), delim, consumer); // Empty string is still inserted into consumer
+ SplitString(data.data(), data.data(), delim, consumer); // Empty string is still inserted into consumer
Cmp(good, test);
good.assign(canonic, canonic + 4);
good.push_back(TUtf16String());
test.clear();
- SplitString(data.data(), data.end() - 2, delim, consumer);
+ SplitString(data.data(), data.end() - 2, delim, consumer);
Cmp(good, test);
}
Y_UNIT_TEST(TestSplit) {
- TString data("qw ab qwababcba");
+ TString data("qw ab qwababcba");
TString canonic[] = {"qw ", " qw", "c"};
TVector<TString> good(canonic, canonic + 3);
TString delim = "ab";
@@ -247,7 +247,7 @@ Y_UNIT_TEST_SUITE(SplitStringTest) {
Cmp(good, test);
TVector<TStringBuf> test1;
- Split(data, delim.data(), test1);
+ Split(data, delim.data(), test1);
Cmp(good, test1);
}
@@ -302,263 +302,263 @@ Y_UNIT_TEST_SUITE(SplitStringTest) {
UNIT_ASSERT_EXCEPTION(Split(data, ' ', s1, s2, m1, m2, m1, m1, m1, m1, s1), yexception);
}
}
-
-template <typename I, typename C>
-void TestStringSplitterCount(I* str, C delim, size_t good) {
- size_t res = StringSplitter(str).Split(delim).Count();
- UNIT_ASSERT_VALUES_EQUAL(res, good);
-}
-
-Y_UNIT_TEST_SUITE(StringSplitter) {
- Y_UNIT_TEST(TestSplit) {
- int sum = 0;
-
- for (const auto& it : StringSplitter("1,2,3").Split(',')) {
- sum += FromString<int>(it.Token());
- }
-
- UNIT_ASSERT_VALUES_EQUAL(sum, 6);
- }
-
- Y_UNIT_TEST(TestSplit1) {
- int cnt = 0;
-
- for (const auto& it : StringSplitter(" ").Split(' ')) {
- (void)it;
-
- ++cnt;
- }
-
- UNIT_ASSERT_VALUES_EQUAL(cnt, 2);
- }
-
- Y_UNIT_TEST(TestSplitLimited) {
- TVector<TString> expected = {"1", "2", "3,4,5"};
- TVector<TString> actual = StringSplitter("1,2,3,4,5").Split(',').Limit(3).ToList<TString>();
- UNIT_ASSERT_VALUES_EQUAL(expected, actual);
- }
-
- Y_UNIT_TEST(TestSplitLimitedWithEmptySkip) {
- TVector<TString> expected = {"1", "2", "3,4,5"};
- TVector<TString> actual = StringSplitter("1,,,2,,,,3,4,5").Split(',').SkipEmpty().Limit(3).ToList<TString>();
- UNIT_ASSERT_VALUES_EQUAL(expected, actual);
-
- expected = {"1", "2", ",,,3,4,5"};
- actual = StringSplitter("1,2,,,,3,4,5").Split(',').Limit(3).SkipEmpty().ToList<TString>();
- UNIT_ASSERT_VALUES_EQUAL(expected, actual);
- }
-
- Y_UNIT_TEST(TestSplitBySet) {
- int sum = 0;
-
- for (const auto& it : StringSplitter("1,2:3").SplitBySet(",:")) {
- sum += FromString<int>(it.Token());
- }
-
- UNIT_ASSERT_VALUES_EQUAL(sum, 6);
- }
-
- Y_UNIT_TEST(TestSplitBySetLimited) {
- TVector<TString> expected = {"1", "2", "3,4:5"};
- TVector<TString> actual = StringSplitter("1,2:3,4:5").SplitBySet(",:").Limit(3).ToList<TString>();
- UNIT_ASSERT_VALUES_EQUAL(expected, actual);
- }
-
- Y_UNIT_TEST(TestSplitBySetLimitedWithEmptySkip) {
- TVector<TString> expected = {"1", "2", "3,4:5"};
- TVector<TString> actual = StringSplitter("1,:,2::::,3,4:5").SplitBySet(",:").SkipEmpty().Limit(3).ToList<TString>();
- UNIT_ASSERT_VALUES_EQUAL(expected, actual);
-
- expected = {"1", ",2::::,3,4:5"};
- actual = StringSplitter("1,:,2::::,3,4:5").SplitBySet(",:").Limit(3).SkipEmpty().ToList<TString>();
- UNIT_ASSERT_VALUES_EQUAL(expected, actual);
- }
-
- Y_UNIT_TEST(TestSplitByString) {
- int sum = 0;
-
- for (const auto& it : StringSplitter("1ab2ab3").SplitByString("ab")) {
- sum += FromString<int>(it.Token());
- }
-
- UNIT_ASSERT_VALUES_EQUAL(sum, 6);
- }
-
- Y_UNIT_TEST(TestSplitByStringLimited) {
- TVector<TString> expected = {"1", "2", "3ab4ab5"};
- TVector<TString> actual = StringSplitter("1ab2ab3ab4ab5").SplitByString("ab").Limit(3).ToList<TString>();
- UNIT_ASSERT_VALUES_EQUAL(expected, actual);
- }
-
- Y_UNIT_TEST(TestSplitByStringLimitedWithEmptySkip) {
- TVector<TString> expected = {"1", "2", "3ab4ab5"};
- TVector<TString> actual = StringSplitter("1abab2ababababab3ab4ab5").SplitByString("ab").SkipEmpty().Limit(3).ToList<TString>();
- UNIT_ASSERT_VALUES_EQUAL(expected, actual);
- }
-
- Y_UNIT_TEST(TestSplitByFunc) {
- TString s = "123 456 \t\n789\n10\t 20";
- TVector<TString> pattern = {"123", "456", "789", "10", "20"};
-
- TVector<TString> tokens;
- auto f = [](char a) { return a == ' ' || a == '\t' || a == '\n'; };
- for (auto v : StringSplitter(s).SplitByFunc(f)) {
+
+template <typename I, typename C>
+void TestStringSplitterCount(I* str, C delim, size_t good) {
+ size_t res = StringSplitter(str).Split(delim).Count();
+ UNIT_ASSERT_VALUES_EQUAL(res, good);
+}
+
+Y_UNIT_TEST_SUITE(StringSplitter) {
+ Y_UNIT_TEST(TestSplit) {
+ int sum = 0;
+
+ for (const auto& it : StringSplitter("1,2,3").Split(',')) {
+ sum += FromString<int>(it.Token());
+ }
+
+ UNIT_ASSERT_VALUES_EQUAL(sum, 6);
+ }
+
+ Y_UNIT_TEST(TestSplit1) {
+ int cnt = 0;
+
+ for (const auto& it : StringSplitter(" ").Split(' ')) {
+ (void)it;
+
+ ++cnt;
+ }
+
+ UNIT_ASSERT_VALUES_EQUAL(cnt, 2);
+ }
+
+ Y_UNIT_TEST(TestSplitLimited) {
+ TVector<TString> expected = {"1", "2", "3,4,5"};
+ TVector<TString> actual = StringSplitter("1,2,3,4,5").Split(',').Limit(3).ToList<TString>();
+ UNIT_ASSERT_VALUES_EQUAL(expected, actual);
+ }
+
+ Y_UNIT_TEST(TestSplitLimitedWithEmptySkip) {
+ TVector<TString> expected = {"1", "2", "3,4,5"};
+ TVector<TString> actual = StringSplitter("1,,,2,,,,3,4,5").Split(',').SkipEmpty().Limit(3).ToList<TString>();
+ UNIT_ASSERT_VALUES_EQUAL(expected, actual);
+
+ expected = {"1", "2", ",,,3,4,5"};
+ actual = StringSplitter("1,2,,,,3,4,5").Split(',').Limit(3).SkipEmpty().ToList<TString>();
+ UNIT_ASSERT_VALUES_EQUAL(expected, actual);
+ }
+
+ Y_UNIT_TEST(TestSplitBySet) {
+ int sum = 0;
+
+ for (const auto& it : StringSplitter("1,2:3").SplitBySet(",:")) {
+ sum += FromString<int>(it.Token());
+ }
+
+ UNIT_ASSERT_VALUES_EQUAL(sum, 6);
+ }
+
+ Y_UNIT_TEST(TestSplitBySetLimited) {
+ TVector<TString> expected = {"1", "2", "3,4:5"};
+ TVector<TString> actual = StringSplitter("1,2:3,4:5").SplitBySet(",:").Limit(3).ToList<TString>();
+ UNIT_ASSERT_VALUES_EQUAL(expected, actual);
+ }
+
+ Y_UNIT_TEST(TestSplitBySetLimitedWithEmptySkip) {
+ TVector<TString> expected = {"1", "2", "3,4:5"};
+ TVector<TString> actual = StringSplitter("1,:,2::::,3,4:5").SplitBySet(",:").SkipEmpty().Limit(3).ToList<TString>();
+ UNIT_ASSERT_VALUES_EQUAL(expected, actual);
+
+ expected = {"1", ",2::::,3,4:5"};
+ actual = StringSplitter("1,:,2::::,3,4:5").SplitBySet(",:").Limit(3).SkipEmpty().ToList<TString>();
+ UNIT_ASSERT_VALUES_EQUAL(expected, actual);
+ }
+
+ Y_UNIT_TEST(TestSplitByString) {
+ int sum = 0;
+
+ for (const auto& it : StringSplitter("1ab2ab3").SplitByString("ab")) {
+ sum += FromString<int>(it.Token());
+ }
+
+ UNIT_ASSERT_VALUES_EQUAL(sum, 6);
+ }
+
+ Y_UNIT_TEST(TestSplitByStringLimited) {
+ TVector<TString> expected = {"1", "2", "3ab4ab5"};
+ TVector<TString> actual = StringSplitter("1ab2ab3ab4ab5").SplitByString("ab").Limit(3).ToList<TString>();
+ UNIT_ASSERT_VALUES_EQUAL(expected, actual);
+ }
+
+ Y_UNIT_TEST(TestSplitByStringLimitedWithEmptySkip) {
+ TVector<TString> expected = {"1", "2", "3ab4ab5"};
+ TVector<TString> actual = StringSplitter("1abab2ababababab3ab4ab5").SplitByString("ab").SkipEmpty().Limit(3).ToList<TString>();
+ UNIT_ASSERT_VALUES_EQUAL(expected, actual);
+ }
+
+ Y_UNIT_TEST(TestSplitByFunc) {
+ TString s = "123 456 \t\n789\n10\t 20";
+ TVector<TString> pattern = {"123", "456", "789", "10", "20"};
+
+ TVector<TString> tokens;
+ auto f = [](char a) { return a == ' ' || a == '\t' || a == '\n'; };
+ for (auto v : StringSplitter(s).SplitByFunc(f)) {
if (v) {
- tokens.emplace_back(v);
+ tokens.emplace_back(v);
}
- }
-
- UNIT_ASSERT(tokens == pattern);
- }
-
- Y_UNIT_TEST(TestSplitByFuncLimited) {
- TVector<TString> expected = {"1", "2", "3a4b5"};
- auto f = [](char a) { return a == 'a' || a == 'b'; };
- TVector<TString> actual = StringSplitter("1a2b3a4b5").SplitByFunc(f).Limit(3).ToList<TString>();
- UNIT_ASSERT_VALUES_EQUAL(expected, actual);
- }
-
- Y_UNIT_TEST(TestSplitByFuncLimitedWithEmptySkip) {
- TVector<TString> expected = {"1", "2", "3a4b5"};
- auto f = [](char a) { return a == 'a' || a == 'b'; };
- TVector<TString> actual = StringSplitter("1aaba2bbababa3a4b5").SplitByFunc(f).SkipEmpty().Limit(3).Take(3).ToList<TString>();
- UNIT_ASSERT_VALUES_EQUAL(expected, actual);
- }
-
- Y_UNIT_TEST(TestSkipEmpty) {
- int sum = 0;
-
- for (const auto& it : StringSplitter(" 1 2 3 ").Split(' ').SkipEmpty()) {
- sum += FromString<int>(it.Token());
- }
-
- UNIT_ASSERT_VALUES_EQUAL(sum, 6);
-
- // double
- sum = 0;
- for (const auto& it : StringSplitter(" 1 2 3 ").Split(' ').SkipEmpty().SkipEmpty()) {
- sum += FromString<int>(it.Token());
- }
- UNIT_ASSERT_VALUES_EQUAL(sum, 6);
- }
-
- Y_UNIT_TEST(TestTake) {
- TVector<TString> expected = {"1", "2", "3"};
- UNIT_ASSERT_VALUES_EQUAL(expected, StringSplitter("1 2 3 4 5 6 7 8 9 10").Split(' ').Take(3).ToList<TString>());
-
- expected = {"1", "2"};
- UNIT_ASSERT_VALUES_EQUAL(expected, StringSplitter(" 1 2 3 ").Split(' ').SkipEmpty().Take(2).ToList<TString>());
-
- expected = {"1", "2", "3"};
- UNIT_ASSERT_VALUES_EQUAL(expected, StringSplitter("1 2 3 4 5 6 7 8 9 10").Split(' ').Take(5).Take(3).ToList<TString>());
- UNIT_ASSERT_VALUES_EQUAL(expected, StringSplitter("1 2 3 4 5 6 7 8 9 10").Split(' ').Take(3).Take(5).ToList<TString>());
-
- expected = {"1", "2"};
- UNIT_ASSERT_VALUES_EQUAL(expected, StringSplitter(" 1 2 3 ").Split(' ').Take(4).SkipEmpty().ToList<TString>());
-
- expected = {"1"};
- UNIT_ASSERT_VALUES_EQUAL(expected, StringSplitter(" 1 2 3 ").Split(' ').Take(4).SkipEmpty().Take(1).ToList<TString>());
- }
-
- Y_UNIT_TEST(TestCompile) {
+ }
+
+ UNIT_ASSERT(tokens == pattern);
+ }
+
+ Y_UNIT_TEST(TestSplitByFuncLimited) {
+ TVector<TString> expected = {"1", "2", "3a4b5"};
+ auto f = [](char a) { return a == 'a' || a == 'b'; };
+ TVector<TString> actual = StringSplitter("1a2b3a4b5").SplitByFunc(f).Limit(3).ToList<TString>();
+ UNIT_ASSERT_VALUES_EQUAL(expected, actual);
+ }
+
+ Y_UNIT_TEST(TestSplitByFuncLimitedWithEmptySkip) {
+ TVector<TString> expected = {"1", "2", "3a4b5"};
+ auto f = [](char a) { return a == 'a' || a == 'b'; };
+ TVector<TString> actual = StringSplitter("1aaba2bbababa3a4b5").SplitByFunc(f).SkipEmpty().Limit(3).Take(3).ToList<TString>();
+ UNIT_ASSERT_VALUES_EQUAL(expected, actual);
+ }
+
+ Y_UNIT_TEST(TestSkipEmpty) {
+ int sum = 0;
+
+ for (const auto& it : StringSplitter(" 1 2 3 ").Split(' ').SkipEmpty()) {
+ sum += FromString<int>(it.Token());
+ }
+
+ UNIT_ASSERT_VALUES_EQUAL(sum, 6);
+
+ // double
+ sum = 0;
+ for (const auto& it : StringSplitter(" 1 2 3 ").Split(' ').SkipEmpty().SkipEmpty()) {
+ sum += FromString<int>(it.Token());
+ }
+ UNIT_ASSERT_VALUES_EQUAL(sum, 6);
+ }
+
+ Y_UNIT_TEST(TestTake) {
+ TVector<TString> expected = {"1", "2", "3"};
+ UNIT_ASSERT_VALUES_EQUAL(expected, StringSplitter("1 2 3 4 5 6 7 8 9 10").Split(' ').Take(3).ToList<TString>());
+
+ expected = {"1", "2"};
+ UNIT_ASSERT_VALUES_EQUAL(expected, StringSplitter(" 1 2 3 ").Split(' ').SkipEmpty().Take(2).ToList<TString>());
+
+ expected = {"1", "2", "3"};
+ UNIT_ASSERT_VALUES_EQUAL(expected, StringSplitter("1 2 3 4 5 6 7 8 9 10").Split(' ').Take(5).Take(3).ToList<TString>());
+ UNIT_ASSERT_VALUES_EQUAL(expected, StringSplitter("1 2 3 4 5 6 7 8 9 10").Split(' ').Take(3).Take(5).ToList<TString>());
+
+ expected = {"1", "2"};
+ UNIT_ASSERT_VALUES_EQUAL(expected, StringSplitter(" 1 2 3 ").Split(' ').Take(4).SkipEmpty().ToList<TString>());
+
+ expected = {"1"};
+ UNIT_ASSERT_VALUES_EQUAL(expected, StringSplitter(" 1 2 3 ").Split(' ').Take(4).SkipEmpty().Take(1).ToList<TString>());
+ }
+
+ Y_UNIT_TEST(TestCompile) {
(void)StringSplitter(TString());
(void)StringSplitter(TStringBuf());
(void)StringSplitter("", 0);
- }
-
- Y_UNIT_TEST(TestStringSplitterCountEmpty) {
- TCharDelimiter<const char> delim(' ');
- TestStringSplitterCount("", delim, 1);
- }
-
- Y_UNIT_TEST(TestStringSplitterCountOne) {
- TCharDelimiter<const char> delim(' ');
- TestStringSplitterCount("one", delim, 1);
- }
-
- Y_UNIT_TEST(TestStringSplitterCountWithOneDelimiter) {
- TCharDelimiter<const char> delim(' ');
- TestStringSplitterCount("one two", delim, 2);
- }
-
- Y_UNIT_TEST(TestStringSplitterCountWithTrailing) {
- TCharDelimiter<const char> delim(' ');
- TestStringSplitterCount(" one ", delim, 3);
- }
-
- Y_UNIT_TEST(TestStringSplitterConsume) {
- TVector<TString> expected = {"1", "2", "3"};
- TVector<TString> actual;
- auto func = [&actual](const TBasicStringBuf<char>& token) {
- actual.push_back(TString(token));
- };
- StringSplitter("1 2 3").Split(' ').Consume(func);
- UNIT_ASSERT_VALUES_EQUAL(expected, actual);
- }
-
- Y_UNIT_TEST(TestStringSplitterConsumeConditional) {
+ }
+
+ Y_UNIT_TEST(TestStringSplitterCountEmpty) {
+ TCharDelimiter<const char> delim(' ');
+ TestStringSplitterCount("", delim, 1);
+ }
+
+ Y_UNIT_TEST(TestStringSplitterCountOne) {
+ TCharDelimiter<const char> delim(' ');
+ TestStringSplitterCount("one", delim, 1);
+ }
+
+ Y_UNIT_TEST(TestStringSplitterCountWithOneDelimiter) {
+ TCharDelimiter<const char> delim(' ');
+ TestStringSplitterCount("one two", delim, 2);
+ }
+
+ Y_UNIT_TEST(TestStringSplitterCountWithTrailing) {
+ TCharDelimiter<const char> delim(' ');
+ TestStringSplitterCount(" one ", delim, 3);
+ }
+
+ Y_UNIT_TEST(TestStringSplitterConsume) {
+ TVector<TString> expected = {"1", "2", "3"};
+ TVector<TString> actual;
+ auto func = [&actual](const TBasicStringBuf<char>& token) {
+ actual.push_back(TString(token));
+ };
+ StringSplitter("1 2 3").Split(' ').Consume(func);
+ UNIT_ASSERT_VALUES_EQUAL(expected, actual);
+ }
+
+ Y_UNIT_TEST(TestStringSplitterConsumeConditional) {
TVector<TString> expected = {"1", "2"};
- TVector<TString> actual;
- auto func = [&actual](const TBasicStringBuf<char>& token) {
+ TVector<TString> actual;
+ auto func = [&actual](const TBasicStringBuf<char>& token) {
if (token == "3") {
- return false;
+ return false;
}
- actual.push_back(TString(token));
- return true;
- };
- bool completed = StringSplitter("1 2 3 4 5").Split(' ').Consume(func);
- UNIT_ASSERT(!completed);
- UNIT_ASSERT_VALUES_EQUAL(expected, actual);
- }
-
- Y_UNIT_TEST(TestStringSplitterToList) {
- TVector<TString> expected = {"1", "2", "3"};
- TVector<TString> actual = StringSplitter("1 2 3").Split(' ').ToList<TString>();
- UNIT_ASSERT_VALUES_EQUAL(expected, actual);
- }
-
- Y_UNIT_TEST(TestStringSplitterCollectPushBack) {
- TVector<TString> expected = {"1", "2", "3"};
- TVector<TString> actual;
- StringSplitter("1 2 3").Split(' ').Collect(&actual);
- UNIT_ASSERT_VALUES_EQUAL(expected, actual);
- }
-
- Y_UNIT_TEST(TestStringSplitterCollectInsert) {
- TSet<TString> expected = {"1", "2", "3"};
- TSet<TString> actual;
- StringSplitter("1 2 3 1 2 3").Split(' ').Collect(&actual);
- UNIT_ASSERT_VALUES_EQUAL(expected, actual);
- }
-
- Y_UNIT_TEST(TestStringSplitterCollectClears) {
- TVector<TString> v;
- StringSplitter("1 2 3").Split(' ').Collect(&v);
- UNIT_ASSERT_VALUES_EQUAL(v.size(), 3);
- StringSplitter("4 5").Split(' ').Collect(&v);
- UNIT_ASSERT_VALUES_EQUAL(v.size(), 2);
- }
-
- Y_UNIT_TEST(TestStringSplitterAddToDoesntClear) {
- TVector<TString> v;
- StringSplitter("1 2 3").Split(' ').AddTo(&v);
- UNIT_ASSERT_VALUES_EQUAL(v.size(), 3);
- StringSplitter("4 5").Split(' ').AddTo(&v);
- UNIT_ASSERT_VALUES_EQUAL(v.size(), 5);
- }
-
- Y_UNIT_TEST(TestSplitStringInto) {
- int a = -1;
- TStringBuf s;
- double d = -1;
- StringSplitter("2 substr 1.02").Split(' ').CollectInto(&a, &s, &d);
- UNIT_ASSERT_VALUES_EQUAL(a, 2);
- UNIT_ASSERT_VALUES_EQUAL(s, "substr");
- UNIT_ASSERT_DOUBLES_EQUAL(d, 1.02, 0.0001);
- UNIT_ASSERT_EXCEPTION(StringSplitter("1").Split(' ').CollectInto(&a, &a), yexception);
- UNIT_ASSERT_EXCEPTION(StringSplitter("1 2 3").Split(' ').CollectInto(&a, &a), yexception);
- }
-
+ actual.push_back(TString(token));
+ return true;
+ };
+ bool completed = StringSplitter("1 2 3 4 5").Split(' ').Consume(func);
+ UNIT_ASSERT(!completed);
+ UNIT_ASSERT_VALUES_EQUAL(expected, actual);
+ }
+
+ Y_UNIT_TEST(TestStringSplitterToList) {
+ TVector<TString> expected = {"1", "2", "3"};
+ TVector<TString> actual = StringSplitter("1 2 3").Split(' ').ToList<TString>();
+ UNIT_ASSERT_VALUES_EQUAL(expected, actual);
+ }
+
+ Y_UNIT_TEST(TestStringSplitterCollectPushBack) {
+ TVector<TString> expected = {"1", "2", "3"};
+ TVector<TString> actual;
+ StringSplitter("1 2 3").Split(' ').Collect(&actual);
+ UNIT_ASSERT_VALUES_EQUAL(expected, actual);
+ }
+
+ Y_UNIT_TEST(TestStringSplitterCollectInsert) {
+ TSet<TString> expected = {"1", "2", "3"};
+ TSet<TString> actual;
+ StringSplitter("1 2 3 1 2 3").Split(' ').Collect(&actual);
+ UNIT_ASSERT_VALUES_EQUAL(expected, actual);
+ }
+
+ Y_UNIT_TEST(TestStringSplitterCollectClears) {
+ TVector<TString> v;
+ StringSplitter("1 2 3").Split(' ').Collect(&v);
+ UNIT_ASSERT_VALUES_EQUAL(v.size(), 3);
+ StringSplitter("4 5").Split(' ').Collect(&v);
+ UNIT_ASSERT_VALUES_EQUAL(v.size(), 2);
+ }
+
+ Y_UNIT_TEST(TestStringSplitterAddToDoesntClear) {
+ TVector<TString> v;
+ StringSplitter("1 2 3").Split(' ').AddTo(&v);
+ UNIT_ASSERT_VALUES_EQUAL(v.size(), 3);
+ StringSplitter("4 5").Split(' ').AddTo(&v);
+ UNIT_ASSERT_VALUES_EQUAL(v.size(), 5);
+ }
+
+ Y_UNIT_TEST(TestSplitStringInto) {
+ int a = -1;
+ TStringBuf s;
+ double d = -1;
+ StringSplitter("2 substr 1.02").Split(' ').CollectInto(&a, &s, &d);
+ UNIT_ASSERT_VALUES_EQUAL(a, 2);
+ UNIT_ASSERT_VALUES_EQUAL(s, "substr");
+ UNIT_ASSERT_DOUBLES_EQUAL(d, 1.02, 0.0001);
+ UNIT_ASSERT_EXCEPTION(StringSplitter("1").Split(' ').CollectInto(&a, &a), yexception);
+ UNIT_ASSERT_EXCEPTION(StringSplitter("1 2 3").Split(' ').CollectInto(&a, &a), yexception);
+ }
+
Y_UNIT_TEST(TestSplitStringWithIgnore) {
TStringBuf s;
StringSplitter("x y z").Split(' ').CollectInto(&std::ignore, &s, &std::ignore);
@@ -567,265 +567,265 @@ Y_UNIT_TEST_SUITE(StringSplitter) {
UNIT_ASSERT_EXCEPTION(StringSplitter("ignored != non-requred").Split(':').CollectInto(&s, &std::ignore), yexception);
}
- Y_UNIT_TEST(TestTryCollectInto) {
- int a, b, c;
- bool parsingSucceeded;
- parsingSucceeded = StringSplitter("100,500,3").Split(',').TryCollectInto(&a, &b, &c);
- UNIT_ASSERT(parsingSucceeded);
- UNIT_ASSERT_VALUES_EQUAL(a, 100);
- UNIT_ASSERT_VALUES_EQUAL(b, 500);
- UNIT_ASSERT_VALUES_EQUAL(c, 3);
-
- //not enough tokens
- parsingSucceeded = StringSplitter("3,14").Split(',').TryCollectInto(&a, &b, &c);
- UNIT_ASSERT(!parsingSucceeded);
-
- //too many tokens
- parsingSucceeded = StringSplitter("3,14,15,92,6").Split(',').TryCollectInto(&a, &b, &c);
- UNIT_ASSERT(!parsingSucceeded);
-
- //where single TryFromString fails
- parsingSucceeded = StringSplitter("ot topota kopyt pyl po polu letit").Split(' ').TryCollectInto(&a, &b, &c);
- UNIT_ASSERT(!parsingSucceeded);
- }
-
- Y_UNIT_TEST(TestOwningSplit1) {
- int sum = 0;
-
- for (const auto& it : StringSplitter(TString("1,2,3")).Split(',')) {
- sum += FromString<int>(it.Token());
- }
-
- UNIT_ASSERT_VALUES_EQUAL(sum, 6);
- }
-
- Y_UNIT_TEST(TestOwningSplit2) {
- int sum = 0;
-
- TString str("1,2,3");
- for (const auto& it : StringSplitter(str).Split(',')) {
- sum += FromString<int>(it.Token());
- }
-
- UNIT_ASSERT_VALUES_EQUAL(sum, 6);
- }
-
- Y_UNIT_TEST(TestOwningSplit3) {
- int sum = 0;
-
- const TString str("1,2,3");
- for (const auto& it : StringSplitter(str).Split(',')) {
- sum += FromString<int>(it.Token());
- }
-
- UNIT_ASSERT_VALUES_EQUAL(sum, 6);
- }
-
- Y_UNIT_TEST(TestAssigment) {
+ Y_UNIT_TEST(TestTryCollectInto) {
+ int a, b, c;
+ bool parsingSucceeded;
+ parsingSucceeded = StringSplitter("100,500,3").Split(',').TryCollectInto(&a, &b, &c);
+ UNIT_ASSERT(parsingSucceeded);
+ UNIT_ASSERT_VALUES_EQUAL(a, 100);
+ UNIT_ASSERT_VALUES_EQUAL(b, 500);
+ UNIT_ASSERT_VALUES_EQUAL(c, 3);
+
+ //not enough tokens
+ parsingSucceeded = StringSplitter("3,14").Split(',').TryCollectInto(&a, &b, &c);
+ UNIT_ASSERT(!parsingSucceeded);
+
+ //too many tokens
+ parsingSucceeded = StringSplitter("3,14,15,92,6").Split(',').TryCollectInto(&a, &b, &c);
+ UNIT_ASSERT(!parsingSucceeded);
+
+ //where single TryFromString fails
+ parsingSucceeded = StringSplitter("ot topota kopyt pyl po polu letit").Split(' ').TryCollectInto(&a, &b, &c);
+ UNIT_ASSERT(!parsingSucceeded);
+ }
+
+ Y_UNIT_TEST(TestOwningSplit1) {
+ int sum = 0;
+
+ for (const auto& it : StringSplitter(TString("1,2,3")).Split(',')) {
+ sum += FromString<int>(it.Token());
+ }
+
+ UNIT_ASSERT_VALUES_EQUAL(sum, 6);
+ }
+
+ Y_UNIT_TEST(TestOwningSplit2) {
+ int sum = 0;
+
+ TString str("1,2,3");
+ for (const auto& it : StringSplitter(str).Split(',')) {
+ sum += FromString<int>(it.Token());
+ }
+
+ UNIT_ASSERT_VALUES_EQUAL(sum, 6);
+ }
+
+ Y_UNIT_TEST(TestOwningSplit3) {
+ int sum = 0;
+
+ const TString str("1,2,3");
+ for (const auto& it : StringSplitter(str).Split(',')) {
+ sum += FromString<int>(it.Token());
+ }
+
+ UNIT_ASSERT_VALUES_EQUAL(sum, 6);
+ }
+
+ Y_UNIT_TEST(TestAssigment) {
TVector<TString> expected0 = {"1", "2", "3", "4"};
- TVector<TString> actual0 = StringSplitter("1 2 3 4").Split(' ');
- UNIT_ASSERT_VALUES_EQUAL(expected0, actual0);
-
+ TVector<TString> actual0 = StringSplitter("1 2 3 4").Split(' ');
+ UNIT_ASSERT_VALUES_EQUAL(expected0, actual0);
+
TSet<TString> expected1 = {"11", "22", "33", "44"};
- TSet<TString> actual1 = StringSplitter("11 22 33 44").Split(' ');
- UNIT_ASSERT_VALUES_EQUAL(expected1, actual1);
-
+ TSet<TString> actual1 = StringSplitter("11 22 33 44").Split(' ');
+ UNIT_ASSERT_VALUES_EQUAL(expected1, actual1);
+
TSet<TString> expected2 = {"11", "aa"};
- auto actual2 = static_cast<TSet<TString>>(StringSplitter("11 aa 11 11 aa").Split(' '));
- UNIT_ASSERT_VALUES_EQUAL(expected2, actual2);
-
+ auto actual2 = static_cast<TSet<TString>>(StringSplitter("11 aa 11 11 aa").Split(' '));
+ UNIT_ASSERT_VALUES_EQUAL(expected2, actual2);
+
TVector<TString> expected3 = {"dd", "bb"};
- auto actual3 = TVector<TString>(StringSplitter("dd\tbb").Split('\t'));
- UNIT_ASSERT_VALUES_EQUAL(expected3, actual3);
- }
-
- Y_UNIT_TEST(TestRangeBasedFor) {
+ auto actual3 = TVector<TString>(StringSplitter("dd\tbb").Split('\t'));
+ UNIT_ASSERT_VALUES_EQUAL(expected3, actual3);
+ }
+
+ Y_UNIT_TEST(TestRangeBasedFor) {
TVector<TString> actual0 = {"11", "22", "33", "44"};
- size_t num = 0;
- for (TStringBuf elem : StringSplitter("11 22 33 44").Split(' ')) {
- UNIT_ASSERT_VALUES_EQUAL(elem, actual0[num++]);
- }
-
+ size_t num = 0;
+ for (TStringBuf elem : StringSplitter("11 22 33 44").Split(' ')) {
+ UNIT_ASSERT_VALUES_EQUAL(elem, actual0[num++]);
+ }
+
TVector<TString> actual1 = {"another", "one,", "and", "another", "one"};
- num = 0;
+ num = 0;
for (TStringBuf elem : StringSplitter(TStringBuf("another one, and \n\n another one")).SplitBySet(" \n").SkipEmpty()) {
- UNIT_ASSERT_VALUES_EQUAL(elem, actual1[num++]);
- }
-
+ UNIT_ASSERT_VALUES_EQUAL(elem, actual1[num++]);
+ }
+
TVector<TUtf16String> actual2 = {u"привет,", u"как", u"дела"};
- num = 0;
+ num = 0;
for (TWtringBuf elem : StringSplitter(u"привет, как дела").Split(wchar16(' '))) {
- UNIT_ASSERT_VALUES_EQUAL(elem, actual2[num++]);
- }
-
- TVector<TString> copy(4);
- auto v = StringSplitter("11 22 33 44").Split(' ');
- Copy(v.begin(), v.end(), copy.begin());
- UNIT_ASSERT_VALUES_EQUAL(actual0, copy);
- }
-
- Y_UNIT_TEST(TestParseInto) {
+ UNIT_ASSERT_VALUES_EQUAL(elem, actual2[num++]);
+ }
+
+ TVector<TString> copy(4);
+ auto v = StringSplitter("11 22 33 44").Split(' ');
+ Copy(v.begin(), v.end(), copy.begin());
+ UNIT_ASSERT_VALUES_EQUAL(actual0, copy);
+ }
+
+ Y_UNIT_TEST(TestParseInto) {
TVector<int> actual0 = {1, 2, 3, 4};
- TVector<int> answer0;
-
- StringSplitter("1 2 3 4").Split(' ').ParseInto(&answer0);
- UNIT_ASSERT_VALUES_EQUAL(actual0, answer0);
-
+ TVector<int> answer0;
+
+ StringSplitter("1 2 3 4").Split(' ').ParseInto(&answer0);
+ UNIT_ASSERT_VALUES_EQUAL(actual0, answer0);
+
TVector<int> actual1 = {42, 1, 2, 3, 4};
TVector<int> answer1 = {42};
- StringSplitter("1 2 3 4").Split(' ').ParseInto(&answer1);
- UNIT_ASSERT_VALUES_EQUAL(actual1, answer1);
-
- answer1.clear();
- UNIT_ASSERT_EXCEPTION(StringSplitter("1 2 3 4").Split(' ').ParseInto(&answer1), yexception);
-
+ StringSplitter("1 2 3 4").Split(' ').ParseInto(&answer1);
+ UNIT_ASSERT_VALUES_EQUAL(actual1, answer1);
+
+ answer1.clear();
+ UNIT_ASSERT_EXCEPTION(StringSplitter("1 2 3 4").Split(' ').ParseInto(&answer1), yexception);
+
answer1 = {42};
- StringSplitter(" 1 2 3 4").Split(' ').SkipEmpty().ParseInto(&answer1);
- UNIT_ASSERT_VALUES_EQUAL(actual1, answer1);
-
- answer1.clear();
- StringSplitter(" \n 1 2 \n\n\n 3 4\n ").SplitBySet(" \n").SkipEmpty().ParseInto(&answer1);
- UNIT_ASSERT_VALUES_EQUAL(actual0, answer1);
- }
-
- Y_UNIT_TEST(TestStdString) {
- std::vector<std::string_view> r0, r1, answer = {"lol", "zomg"};
- std::string s = "lol zomg";
- for (std::string_view ss : StringSplitter(s).Split(' ')) {
- r0.push_back(ss);
- }
- StringSplitter(s).Split(' ').Collect(&r1);
-
- UNIT_ASSERT_VALUES_EQUAL(r0, answer);
- UNIT_ASSERT_VALUES_EQUAL(r1, answer);
- }
-
- Y_UNIT_TEST(TestStdStringView) {
- std::string_view s = "aaacccbbb";
- std::vector<std::string_view> expected = {"aaa", "bbb"};
- std::vector<std::string_view> actual = StringSplitter(s).SplitByString("ccc");
- UNIT_ASSERT_VALUES_EQUAL(expected, actual);
- }
-
- Y_UNIT_TEST(TestStdSplitAfterSplit) {
- std::string_view input = "a*b+a*b";
+ StringSplitter(" 1 2 3 4").Split(' ').SkipEmpty().ParseInto(&answer1);
+ UNIT_ASSERT_VALUES_EQUAL(actual1, answer1);
+
+ answer1.clear();
+ StringSplitter(" \n 1 2 \n\n\n 3 4\n ").SplitBySet(" \n").SkipEmpty().ParseInto(&answer1);
+ UNIT_ASSERT_VALUES_EQUAL(actual0, answer1);
+ }
+
+ Y_UNIT_TEST(TestStdString) {
+ std::vector<std::string_view> r0, r1, answer = {"lol", "zomg"};
+ std::string s = "lol zomg";
+ for (std::string_view ss : StringSplitter(s).Split(' ')) {
+ r0.push_back(ss);
+ }
+ StringSplitter(s).Split(' ').Collect(&r1);
+
+ UNIT_ASSERT_VALUES_EQUAL(r0, answer);
+ UNIT_ASSERT_VALUES_EQUAL(r1, answer);
+ }
+
+ Y_UNIT_TEST(TestStdStringView) {
+ std::string_view s = "aaacccbbb";
+ std::vector<std::string_view> expected = {"aaa", "bbb"};
+ std::vector<std::string_view> actual = StringSplitter(s).SplitByString("ccc");
+ UNIT_ASSERT_VALUES_EQUAL(expected, actual);
+ }
+
+ Y_UNIT_TEST(TestStdSplitAfterSplit) {
+ std::string_view input = "a*b+a*b";
for (std::string_view summand : StringSplitter(input).Split('+')) {
- //FIXME: std::string is used to workaround MSVC ICE
- UNIT_ASSERT_VALUES_EQUAL(std::string(summand), "a*b");
- std::string_view multiplier1, multiplier2;
- bool splitResult = StringSplitter(summand).Split('*').TryCollectInto(&multiplier1, &multiplier2);
- UNIT_ASSERT(splitResult);
- UNIT_ASSERT_VALUES_EQUAL(std::string(multiplier1), "a");
- UNIT_ASSERT_VALUES_EQUAL(std::string(multiplier2), "b");
- }
- }
-
- Y_UNIT_TEST(TestStdSplitWithParsing) {
- std::string_view input = "1,2,3,4";
- TVector<ui64> numbers;
- const TVector<ui64> expected{1, 2, 3, 4};
- StringSplitter(input).Split(',').ParseInto(&numbers);
- UNIT_ASSERT_VALUES_EQUAL(numbers, expected);
- }
-
- Y_UNIT_TEST(TestArcadiaStdInterop) {
+ //FIXME: std::string is used to workaround MSVC ICE
+ UNIT_ASSERT_VALUES_EQUAL(std::string(summand), "a*b");
+ std::string_view multiplier1, multiplier2;
+ bool splitResult = StringSplitter(summand).Split('*').TryCollectInto(&multiplier1, &multiplier2);
+ UNIT_ASSERT(splitResult);
+ UNIT_ASSERT_VALUES_EQUAL(std::string(multiplier1), "a");
+ UNIT_ASSERT_VALUES_EQUAL(std::string(multiplier2), "b");
+ }
+ }
+
+ Y_UNIT_TEST(TestStdSplitWithParsing) {
+ std::string_view input = "1,2,3,4";
+ TVector<ui64> numbers;
+ const TVector<ui64> expected{1, 2, 3, 4};
+ StringSplitter(input).Split(',').ParseInto(&numbers);
+ UNIT_ASSERT_VALUES_EQUAL(numbers, expected);
+ }
+
+ Y_UNIT_TEST(TestArcadiaStdInterop) {
TVector<TString> expected0 = {"a", "b"};
TVector<TStringBuf> expected1 = {"a", "b"};
- std::string src1("a b");
- std::string_view src2("a b");
- TVector<TString> actual0 = StringSplitter(src1).Split(' ').SkipEmpty();
- TVector<TString> actual1 = StringSplitter(src2).Split(' ').SkipEmpty();
- TVector<TStringBuf> actual2 = StringSplitter(src1).Split(' ').SkipEmpty();
- TVector<TStringBuf> actual3 = StringSplitter(src2).Split(' ').SkipEmpty();
- UNIT_ASSERT_VALUES_EQUAL(expected0, actual0);
- UNIT_ASSERT_VALUES_EQUAL(expected0, actual1);
- UNIT_ASSERT_VALUES_EQUAL(expected1, actual2);
- UNIT_ASSERT_VALUES_EQUAL(expected1, actual3);
- }
-
- Y_UNIT_TEST(TestConstCString) {
- const char* b = "a;b";
- const char* e = b + 3;
-
- std::vector<TStringBuf> v;
- StringSplitter(b, e).Split(';').AddTo(&v);
-
+ std::string src1("a b");
+ std::string_view src2("a b");
+ TVector<TString> actual0 = StringSplitter(src1).Split(' ').SkipEmpty();
+ TVector<TString> actual1 = StringSplitter(src2).Split(' ').SkipEmpty();
+ TVector<TStringBuf> actual2 = StringSplitter(src1).Split(' ').SkipEmpty();
+ TVector<TStringBuf> actual3 = StringSplitter(src2).Split(' ').SkipEmpty();
+ UNIT_ASSERT_VALUES_EQUAL(expected0, actual0);
+ UNIT_ASSERT_VALUES_EQUAL(expected0, actual1);
+ UNIT_ASSERT_VALUES_EQUAL(expected1, actual2);
+ UNIT_ASSERT_VALUES_EQUAL(expected1, actual3);
+ }
+
+ Y_UNIT_TEST(TestConstCString) {
+ const char* b = "a;b";
+ const char* e = b + 3;
+
+ std::vector<TStringBuf> v;
+ StringSplitter(b, e).Split(';').AddTo(&v);
+
std::vector<TStringBuf> expected = {"a", "b"};
- UNIT_ASSERT_VALUES_EQUAL(v, expected);
- }
-
- Y_UNIT_TEST(TestCStringRef) {
- TString s = "lol";
- char* str = s.Detach();
-
- std::vector<TStringBuf> v = StringSplitter(str).Split('o');
+ UNIT_ASSERT_VALUES_EQUAL(v, expected);
+ }
+
+ Y_UNIT_TEST(TestCStringRef) {
+ TString s = "lol";
+ char* str = s.Detach();
+
+ std::vector<TStringBuf> v = StringSplitter(str).Split('o');
std::vector<TStringBuf> expected = {"l", "l"};
- UNIT_ASSERT_VALUES_EQUAL(v, expected);
- }
-
- Y_UNIT_TEST(TestSplitVector) {
+ UNIT_ASSERT_VALUES_EQUAL(v, expected);
+ }
+
+ Y_UNIT_TEST(TestSplitVector) {
std::vector<char> buffer = {'a', ';', 'b'};
-
- std::vector<TStringBuf> v = StringSplitter(buffer).Split(';');
-
+
+ std::vector<TStringBuf> v = StringSplitter(buffer).Split(';');
+
std::vector<TStringBuf> expected = {"a", "b"};
- UNIT_ASSERT_VALUES_EQUAL(v, expected);
- }
-
- class TDoubleIterator {
- public:
- using iterator_category = std::input_iterator_tag;
- using value_type = int;
- using pointer = void;
- using reference = int;
- using const_reference = int;
- using difference_type = ptrdiff_t;
-
- TDoubleIterator() = default;
-
+ UNIT_ASSERT_VALUES_EQUAL(v, expected);
+ }
+
+ class TDoubleIterator {
+ public:
+ using iterator_category = std::input_iterator_tag;
+ using value_type = int;
+ using pointer = void;
+ using reference = int;
+ using const_reference = int;
+ using difference_type = ptrdiff_t;
+
+ TDoubleIterator() = default;
+
TDoubleIterator(const char* ptr)
: Ptr_(ptr)
{
}
-
- TDoubleIterator operator++() {
- Ptr_ += 2;
- return *this;
- }
-
- TDoubleIterator operator++(int) {
- TDoubleIterator tmp = *this;
- ++*this;
- return tmp;
- }
-
- friend bool operator==(TDoubleIterator l, TDoubleIterator r) {
- return l.Ptr_ == r.Ptr_;
- }
-
- friend bool operator!=(TDoubleIterator l, TDoubleIterator r) {
- return l.Ptr_ != r.Ptr_;
- }
-
- int operator*() const {
- return (*Ptr_ - '0') * 10 + *(Ptr_ + 1) - '0';
- }
-
- private:
- const char* Ptr_ = nullptr;
- };
-
- Y_UNIT_TEST(TestInputIterator) {
- const char* beg = "1213002233000011";
- const char* end = beg + strlen(beg);
-
+
+ TDoubleIterator operator++() {
+ Ptr_ += 2;
+ return *this;
+ }
+
+ TDoubleIterator operator++(int) {
+ TDoubleIterator tmp = *this;
+ ++*this;
+ return tmp;
+ }
+
+ friend bool operator==(TDoubleIterator l, TDoubleIterator r) {
+ return l.Ptr_ == r.Ptr_;
+ }
+
+ friend bool operator!=(TDoubleIterator l, TDoubleIterator r) {
+ return l.Ptr_ != r.Ptr_;
+ }
+
+ int operator*() const {
+ return (*Ptr_ - '0') * 10 + *(Ptr_ + 1) - '0';
+ }
+
+ private:
+ const char* Ptr_ = nullptr;
+ };
+
+ Y_UNIT_TEST(TestInputIterator) {
+ const char* beg = "1213002233000011";
+ const char* end = beg + strlen(beg);
+
std::vector<std::vector<int>> expected = {{12, 13}, {22, 33}, {}, {11}};
- int i = 0;
-
- for (TIteratorRange<TDoubleIterator> part : StringSplitter(TDoubleIterator(beg), TDoubleIterator(end)).SplitByFunc([](int value) { return value == 0; })) {
- UNIT_ASSERT(std::equal(part.begin(), part.end(), expected[i].begin(), expected[i].end()));
- i++;
- }
- UNIT_ASSERT_VALUES_EQUAL(i, expected.size());
- }
-}
+ int i = 0;
+
+ for (TIteratorRange<TDoubleIterator> part : StringSplitter(TDoubleIterator(beg), TDoubleIterator(end)).SplitByFunc([](int value) { return value == 0; })) {
+ UNIT_ASSERT(std::equal(part.begin(), part.end(), expected[i].begin(), expected[i].end()));
+ i++;
+ }
+ UNIT_ASSERT_VALUES_EQUAL(i, expected.size());
+ }
+}
diff --git a/util/string/strip.cpp b/util/string/strip.cpp
index c921571cf0..f53b9ee896 100644
--- a/util/string/strip.cpp
+++ b/util/string/strip.cpp
@@ -10,7 +10,7 @@ bool Collapse(const TString& from, TString& to, size_t maxLen) {
void CollapseText(const TString& from, TString& to, size_t maxLen) {
Collapse(from, to, maxLen);
StripInPlace(to);
- if (to.size() >= maxLen) {
+ if (to.size() >= maxLen) {
to.remove(maxLen - 5); // " ..."
ReverseInPlace(to);
size_t pos = to.find_first_of(" .,;");
diff --git a/util/string/strip.h b/util/string/strip.h
index d5ef6da96d..0769ed5afe 100644
--- a/util/string/strip.h
+++ b/util/string/strip.h
@@ -218,7 +218,7 @@ size_t CollapseImpl(TChar* s, size_t n, const TWhitespaceFunc& isWhitespace) {
template <class TStringType, class TWhitespaceFunc>
bool CollapseImpl(const TStringType& from, TStringType& to, size_t maxLen, const TWhitespaceFunc& isWhitespace) {
to = from;
- maxLen = maxLen ? Min(maxLen, to.size()) : to.size();
+ maxLen = maxLen ? Min(maxLen, to.size()) : to.size();
for (size_t i = 0; i < maxLen; ++i) {
if (isWhitespace(to[i]) && (to[i] != ' ' || isWhitespace(to[i + 1]))) {
size_t tailSize = maxLen - i;
diff --git a/util/string/subst.cpp b/util/string/subst.cpp
index b2df328dc1..d86f939e25 100644
--- a/util/string/subst.cpp
+++ b/util/string/subst.cpp
@@ -67,7 +67,7 @@ static inline size_t SubstGlobalImpl(TStringType& s, const TStringViewType from,
result.reserve(s.size() + s.size() / 3);
}
result.append(s.begin() + srcPos, s.begin() + off);
- result.append(to.data(), to.size());
+ result.append(to.data(), to.size());
srcPos = off + fromSize;
++replacementsCount;
}
diff --git a/util/string/subst_ut.cpp b/util/string/subst_ut.cpp
index 21eccef779..a4db704938 100644
--- a/util/string/subst_ut.cpp
+++ b/util/string/subst_ut.cpp
@@ -26,7 +26,7 @@ Y_UNIT_TEST_SUITE(TStringSubst) {
Y_UNIT_TEST(TestSubstGlobalNoSubstA) {
for (const auto& from : ALL_FROM) {
- const size_t fromSz = from.size();
+ const size_t fromSz = from.size();
const size_t minSz = fromSz;
const size_t maxSz = fromSz + MIN_FROM_CTX;
for (size_t sz = minSz; sz <= maxSz; ++sz) {
@@ -42,7 +42,7 @@ Y_UNIT_TEST_SUITE(TStringSubst) {
Y_UNIT_TEST(TestSubstGlobalNoSubstB) {
for (const auto& from : ALL_FROM) {
- const size_t fromSz = from.size();
+ const size_t fromSz = from.size();
const size_t minSz = fromSz;
const size_t maxSz = fromSz + MIN_FROM_CTX;
for (size_t sz = minSz; sz <= maxSz; ++sz) {
@@ -64,7 +64,7 @@ Y_UNIT_TEST_SUITE(TStringSubst) {
static void DoTestSubstGlobal(TVector<TString>& parts, const size_t minBeg, const size_t sz,
const TString& from, const size_t fromPos, const size_t numSubst) {
const size_t numLeft = numSubst - parts.size();
- for (size_t fromBeg = minBeg; fromBeg <= sz - numLeft * from.size(); ++fromBeg) {
+ for (size_t fromBeg = minBeg; fromBeg <= sz - numLeft * from.size(); ++fromBeg) {
if (parts.empty()) {
parts.emplace_back(fromBeg, '.');
} else {
@@ -72,16 +72,16 @@ Y_UNIT_TEST_SUITE(TStringSubst) {
}
if (numLeft == 1) {
- parts.emplace_back(sz - fromBeg - from.size(), '.');
+ parts.emplace_back(sz - fromBeg - from.size(), '.');
TString sFrom = JoinSeq(from, parts);
- UNIT_ASSERT_VALUES_EQUAL_C(sFrom.size(), sz, sFrom);
+ UNIT_ASSERT_VALUES_EQUAL_C(sFrom.size(), sz, sFrom);
for (const auto& to : ALL_TO) {
TString sTo = JoinSeq(to, parts);
AssertSubstGlobal(sFrom, sTo, from, to, fromPos, numSubst);
}
parts.pop_back();
} else {
- DoTestSubstGlobal(parts, fromBeg + from.size(), sz, from, fromPos, numSubst);
+ DoTestSubstGlobal(parts, fromBeg + from.size(), sz, from, fromPos, numSubst);
}
parts.pop_back();
@@ -91,7 +91,7 @@ Y_UNIT_TEST_SUITE(TStringSubst) {
static void DoTestSubstGlobal(size_t numSubst) {
TVector<TString> parts;
for (const auto& from : ALL_FROM) {
- const size_t fromSz = from.size();
+ const size_t fromSz = from.size();
const size_t minSz = numSubst * fromSz;
const size_t maxSz = numSubst * (fromSz + MIN_FROM_CTX);
for (size_t sz = minSz; sz <= maxSz; ++sz) {
diff --git a/util/string/type.h b/util/string/type.h
index d6cb29ea58..ff6767415f 100644
--- a/util/string/type.h
+++ b/util/string/type.h
@@ -6,7 +6,7 @@ Y_PURE_FUNCTION bool IsSpace(const char* s, size_t len) noexcept;
/// Checks if a string is a set of only space symbols.
Y_PURE_FUNCTION static inline bool IsSpace(const TStringBuf s) noexcept {
- return IsSpace(s.data(), s.size());
+ return IsSpace(s.data(), s.size());
}
/// Returns "true" if the given string is an arabic number ([0-9]+)
diff --git a/util/string/vector.cpp b/util/string/vector.cpp
index 9ba401f0a2..3e78fce9c4 100644
--- a/util/string/vector.cpp
+++ b/util/string/vector.cpp
@@ -11,12 +11,12 @@ static inline void DoSplit2(TConsumer& c, TDelim& d, const TBasicStringBuf<TChr>
template <class TConsumer, class TDelim, typename TChr>
static inline void DoSplit1(TConsumer& cc, TDelim& d, const TBasicStringBuf<TChr> str, int opts) {
- if (opts & KEEP_EMPTY_TOKENS) {
+ if (opts & KEEP_EMPTY_TOKENS) {
DoSplit2(cc, d, str, opts);
} else {
TSkipEmptyTokens<TConsumer> sc(&cc);
- DoSplit2(sc, d, str, opts);
+ DoSplit2(sc, d, str, opts);
}
}
@@ -84,8 +84,8 @@ TUtf16String JoinStrings(const TVector<TUtf16String>& v, const TWtringBuf delim)
}
TUtf16String JoinStrings(const TVector<TUtf16String>& v, size_t index, size_t count, const TWtringBuf delim) {
- const size_t f = Min(index, v.size());
- const size_t l = f + Min(count, v.size() - f);
+ const size_t f = Min(index, v.size());
+ 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..78e01efa08 100644
--- a/util/string/vector.h
+++ b/util/string/vector.h
@@ -1,7 +1,7 @@
#pragma once
#include "cast.h"
-#include "split.h"
+#include "split.h"
#include <util/generic/map.h>
#include <util/generic/strbuf.h>
@@ -13,7 +13,7 @@
#define KEEP_EMPTY_TOKENS 0x01
//
-// NOTE: Check StringSplitter below to get more convenient split string interface.
+// NOTE: Check StringSplitter below to get more convenient split string interface.
namespace NPrivate {
@@ -46,7 +46,7 @@ TVector<typename ::NPrivate::TStringDeducer<C>::type>
SplitString(const C* ptr, const C* delimiter,
size_t maxFields = 0, int options = 0) {
TVector<typename ::NPrivate::TStringDeducer<C>::type> res;
- ::NPrivate::SplitStringImpl(&res, ptr, delimiter, maxFields, options);
+ ::NPrivate::SplitStringImpl(&res, ptr, delimiter, maxFields, options);
return res;
}
@@ -55,7 +55,7 @@ TVector<typename ::NPrivate::TStringDeducer<C>::type>
SplitString(const C* ptr, size_t len, const C* delimiter,
size_t maxFields = 0, int options = 0) {
TVector<typename ::NPrivate::TStringDeducer<C>::type> res;
- ::NPrivate::SplitStringImpl(&res, ptr, len, delimiter, maxFields, options);
+ ::NPrivate::SplitStringImpl(&res, ptr, len, delimiter, maxFields, options);
return res;
}
@@ -63,7 +63,7 @@ template <typename C>
TVector<typename ::NPrivate::TStringDeducer<C>::type>
SplitString(const typename ::NPrivate::TStringDeducer<C>::type& str, const C* delimiter,
size_t maxFields = 0, int options = 0) {
- return SplitString(str.data(), str.size(), delimiter, maxFields, options);
+ return SplitString(str.data(), str.size(), delimiter, maxFields, options);
}
template <class TIter>
diff --git a/util/system/atexit.cpp b/util/system/atexit.cpp
index 74fb10b6b1..1714784f29 100644
--- a/util/system/atexit.cpp
+++ b/util/system/atexit.cpp
@@ -60,7 +60,7 @@ namespace {
inline void Register(TAtExitFunc func, void* ctx, size_t priority) {
with_lock (Lock_) {
- Store_.push_back({func, ctx, priority, Store_.size()});
+ Store_.push_back({func, ctx, priority, Store_.size()});
Items_.push(&Store_.back());
}
}
diff --git a/util/system/compat.cpp b/util/system/compat.cpp
index 18fbfa296a..00eac400d7 100644
--- a/util/system/compat.cpp
+++ b/util/system/compat.cpp
@@ -18,7 +18,7 @@
#ifndef HAVE_NATIVE_GETPROGNAME
const char* getprogname() {
- return GetProgramName().data();
+ return GetProgramName().data();
}
#endif
diff --git a/util/system/dynlib.cpp b/util/system/dynlib.cpp
index 9d2541c25f..f5084f2f68 100644
--- a/util/system/dynlib.cpp
+++ b/util/system/dynlib.cpp
@@ -53,7 +53,7 @@ private:
(void)flags;
if (!Module) {
- ythrow yexception() << DLLERR().data();
+ ythrow yexception() << DLLERR().data();
}
}
@@ -81,7 +81,7 @@ public:
void* symbol = SymOptional(name);
if (symbol == nullptr) {
- ythrow yexception() << DLLERR().data();
+ ythrow yexception() << DLLERR().data();
}
return symbol;
@@ -100,7 +100,7 @@ TDynamicLibrary::TDynamicLibrary() noexcept {
}
TDynamicLibrary::TDynamicLibrary(const TString& path, int flags) {
- Open(path.data(), flags);
+ Open(path.data(), flags);
}
TDynamicLibrary::~TDynamicLibrary() = default;
diff --git a/util/system/dynlib.h b/util/system/dynlib.h
index 66eaf4a5c1..6515df903a 100644
--- a/util/system/dynlib.h
+++ b/util/system/dynlib.h
@@ -56,7 +56,7 @@ public:
PLib = nullptr;
DLib = nullptr;
if (es.IsDynamic())
- Open(es.LibName().data(), es.VtblName().data());
+ Open(es.LibName().data(), es.VtblName().data());
else if (es.IsStatic())
SetSym(es.Symbol());
}
@@ -64,7 +64,7 @@ public:
if (this != &es) {
Close();
if (es.IsDynamic())
- Open(es.LibName().data(), es.VtblName().data());
+ Open(es.LibName().data(), es.VtblName().data());
else if (es.IsStatic())
SetSym(es.Symbol());
}
diff --git a/util/system/env.cpp b/util/system/env.cpp
index ead9b566a5..483b000d34 100644
--- a/util/system/env.cpp
+++ b/util/system/env.cpp
@@ -23,7 +23,7 @@
TString GetEnv(const TString& key, const TString& def) {
#ifdef _win_
- size_t len = GetEnvironmentVariableA(key.data(), nullptr, 0);
+ size_t len = GetEnvironmentVariableA(key.data(), nullptr, 0);
if (len == 0) {
if (GetLastError() == ERROR_ENVVAR_NOT_FOUND) {
@@ -36,7 +36,7 @@ TString GetEnv(const TString& key, const TString& def) {
size_t bufferSize;
do {
bufferSize = buffer.size();
- len = GetEnvironmentVariableA(key.data(), buffer.data(), static_cast<DWORD>(bufferSize));
+ len = GetEnvironmentVariableA(key.data(), buffer.data(), static_cast<DWORD>(bufferSize));
if (len > bufferSize) {
buffer.resize(len);
}
@@ -44,7 +44,7 @@ TString GetEnv(const TString& key, const TString& def) {
return TString(buffer.data(), len);
#else
- const char* env = getenv(key.data());
+ const char* env = getenv(key.data());
return env ? TString(env) : def;
#endif
}
@@ -53,12 +53,12 @@ void SetEnv(const TString& key, const TString& value) {
bool isOk = false;
int errorCode = 0;
#ifdef _win_
- isOk = SetEnvironmentVariable(key.data(), value.data());
+ isOk = SetEnvironmentVariable(key.data(), value.data());
if (!isOk) {
errorCode = GetLastError();
}
#else
- isOk = (0 == setenv(key.data(), value.data(), true /*replace*/));
+ isOk = (0 == setenv(key.data(), value.data(), true /*replace*/));
if (!isOk) {
errorCode = errno;
}
diff --git a/util/system/file.cpp b/util/system/file.cpp
index 4a261d020c..743e8f67f2 100644
--- a/util/system/file.cpp
+++ b/util/system/file.cpp
@@ -260,7 +260,7 @@ TFileHandle::TFileHandle(const TString& fName, EOpenMode oMode) noexcept {
//temp file
if (Fd_ >= 0 && (oMode & Transient)) {
- unlink(fName.data());
+ unlink(fName.data());
}
#else
#error unsupported platform
diff --git a/util/system/filemap.h b/util/system/filemap.h
index 11be64bff4..b084c060a3 100644
--- a/util/system/filemap.h
+++ b/util/system/filemap.h
@@ -4,7 +4,7 @@
#include "align.h"
#include "yassert.h"
-#include <util/generic/noncopyable.h>
+#include <util/generic/noncopyable.h>
#include <util/generic/ptr.h>
#include <util/generic/utility.h>
#include <util/generic/yexception.h>
diff --git a/util/system/fs.cpp b/util/system/fs.cpp
index d2611a8ccc..e2db6cd403 100644
--- a/util/system/fs.cpp
+++ b/util/system/fs.cpp
@@ -20,7 +20,7 @@ bool NFs::Remove(const TString& path) {
#if defined(_win_)
return NFsPrivate::WinRemove(path);
#else
- return ::remove(path.data()) == 0;
+ return ::remove(path.data()) == 0;
#endif
}
@@ -58,7 +58,7 @@ bool NFs::MakeDirectory(const TString& path, EFilePermissions mode) {
Y_UNUSED(mode);
return NFsPrivate::WinMakeDirectory(path);
#else
- return mkdir(path.data(), mode) == 0;
+ return mkdir(path.data(), mode) == 0;
#endif
}
@@ -88,7 +88,7 @@ bool NFs::Rename(const TString& oldPath, const TString& newPath) {
#if defined(_win_)
return NFsPrivate::WinRename(oldPath, newPath);
#else
- return ::rename(oldPath.data(), newPath.data()) == 0;
+ return ::rename(oldPath.data(), newPath.data()) == 0;
#endif
}
@@ -102,7 +102,7 @@ bool NFs::HardLink(const TString& existingPath, const TString& newPath) {
#if defined(_win_)
return NFsPrivate::WinHardLink(existingPath, newPath);
#elif defined(_unix_)
- return (0 == link(existingPath.data(), newPath.data()));
+ return (0 == link(existingPath.data(), newPath.data()));
#endif
}
@@ -110,7 +110,7 @@ bool NFs::SymLink(const TString& targetPath, const TString& linkPath) {
#if defined(_win_)
return NFsPrivate::WinSymLink(targetPath, linkPath);
#elif defined(_unix_)
- return 0 == symlink(targetPath.data(), linkPath.data());
+ return 0 == symlink(targetPath.data(), linkPath.data());
#endif
}
@@ -120,7 +120,7 @@ TString NFs::ReadLink(const TString& path) {
#elif defined(_unix_)
TTempBuf buf;
while (true) {
- ssize_t r = readlink(path.data(), buf.Data(), buf.Size());
+ ssize_t r = readlink(path.data(), buf.Data(), buf.Size());
if (r < 0) {
ythrow yexception() << "can't read link " << path << ", errno = " << errno;
}
@@ -150,7 +150,7 @@ bool NFs::Exists(const TString& path) {
#if defined(_win_)
return NFsPrivate::WinExists(path);
#elif defined(_unix_)
- return access(path.data(), F_OK) == 0;
+ return access(path.data(), F_OK) == 0;
#endif
}
@@ -171,7 +171,7 @@ void NFs::SetCurrentWorkingDirectory(TString path) {
#ifdef _win_
bool ok = NFsPrivate::WinSetCurrentWorkingDirectory(path);
#else
- bool ok = !chdir(path.data());
+ bool ok = !chdir(path.data());
#endif
if (!ok) {
ythrow TSystemError() << "failed to change directory to " << path.Quote();
diff --git a/util/system/fs_ut.cpp b/util/system/fs_ut.cpp
index de071ebf55..7ed677bce0 100644
--- a/util/system/fs_ut.cpp
+++ b/util/system/fs_ut.cpp
@@ -71,10 +71,10 @@ void TFsTest::TestCreateRemove() {
UNIT_ASSERT(!NFs::MakeDirectoryRecursive(file1, NFs::FP_COMMON_FILE, false));
TString longUtf8Name = "";
- while (longUtf8Name.size() < 255) {
+ while (longUtf8Name.size() < 255) {
longUtf8Name = longUtf8Name + "fф";
}
- UNIT_ASSERT_EQUAL(longUtf8Name.size(), 255);
+ UNIT_ASSERT_EQUAL(longUtf8Name.size(), 255);
TFsPath longfile = dir1 / longUtf8Name;
Touch(longfile);
diff --git a/util/system/fs_win.cpp b/util/system/fs_win.cpp
index a410ccac06..9360677e82 100644
--- a/util/system/fs_win.cpp
+++ b/util/system/fs_win.cpp
@@ -10,13 +10,13 @@
namespace NFsPrivate {
static LPCWSTR UTF8ToWCHAR(const TStringBuf str, TUtf16String& wstr) {
- wstr.resize(str.size());
+ wstr.resize(str.size());
size_t written = 0;
- if (!UTF8ToWide(str.data(), str.size(), wstr.begin(), written))
+ if (!UTF8ToWide(str.data(), str.size(), wstr.begin(), written))
return nullptr;
wstr.erase(written);
static_assert(sizeof(WCHAR) == sizeof(wchar16), "expect sizeof(WCHAR) == sizeof(wchar16)");
- return (const WCHAR*)wstr.data();
+ return (const WCHAR*)wstr.data();
}
static TString WCHARToUTF8(const LPWSTR wstr, size_t len) {
diff --git a/util/system/fstat.cpp b/util/system/fstat.cpp
index 81e98cbc6b..c413e552c6 100644
--- a/util/system/fstat.cpp
+++ b/util/system/fstat.cpp
@@ -121,11 +121,11 @@ void TFileStat::MakeFromFileName(const char* fileName, bool nofollow) {
}
TFileStat::TFileStat(const TFsPath& fileName, bool nofollow) {
- MakeFromFileName(fileName.GetPath().data(), nofollow);
+ MakeFromFileName(fileName.GetPath().data(), nofollow);
}
TFileStat::TFileStat(const TString& fileName, bool nofollow) {
- MakeFromFileName(fileName.data(), nofollow);
+ MakeFromFileName(fileName.data(), nofollow);
}
TFileStat::TFileStat(const char* fileName, bool nofollow) {
@@ -211,5 +211,5 @@ i64 GetFileLength(const char* name) {
}
i64 GetFileLength(const TString& name) {
- return GetFileLength(name.data());
+ return GetFileLength(name.data());
}
diff --git a/util/system/fstat_ut.cpp b/util/system/fstat_ut.cpp
index 160ecd936e..81a0dbcb1d 100644
--- a/util/system/fstat_ut.cpp
+++ b/util/system/fstat_ut.cpp
@@ -13,7 +13,7 @@ Y_UNIT_TEST_SUITE(TestFileStat) {
TString fileName = "f1.txt";
TFileStat oFs;
{
- TFile file(fileName.data(), OpenAlways | WrOnly);
+ TFile file(fileName.data(), OpenAlways | WrOnly);
file.Write("1234567", 7);
{
@@ -43,7 +43,7 @@ Y_UNIT_TEST_SUITE(TestFileStat) {
UNIT_ASSERT_VALUES_EQUAL(cFs.Uid, oFs.Uid);
UNIT_ASSERT_VALUES_EQUAL(cFs.Gid, oFs.Gid);
UNIT_ASSERT_VALUES_EQUAL(cFs.INode, oFs.INode);
- UNIT_ASSERT(unlink(fileName.data()) == 0);
+ UNIT_ASSERT(unlink(fileName.data()) == 0);
}
Y_UNIT_TEST(DirTest) {
diff --git a/util/system/hi_lo.h b/util/system/hi_lo.h
index f86870534f..452b3c697a 100644
--- a/util/system/hi_lo.h
+++ b/util/system/hi_lo.h
@@ -41,7 +41,7 @@ namespace NHiLoPrivate {
}
TIntRef& operator=(TRepr value) {
- WriteUnaligned<TRepr>(GetPtr(), value);
+ WriteUnaligned<TRepr>(GetPtr(), value);
return *this;
}
diff --git a/util/system/hostname.cpp b/util/system/hostname.cpp
index 386f646d6b..9d6a1333fe 100644
--- a/util/system/hostname.cpp
+++ b/util/system/hostname.cpp
@@ -69,7 +69,7 @@ const TString& HostName() {
}
const char* GetHostName() {
- return HostName().data();
+ return HostName().data();
}
const TString& FQDNHostName() {
@@ -77,7 +77,7 @@ const TString& FQDNHostName() {
}
const char* GetFQDNHostName() {
- return FQDNHostName().data();
+ return FQDNHostName().data();
}
bool IsFQDN(const TString& name) {
diff --git a/util/system/progname.cpp b/util/system/progname.cpp
index 2c29119320..5a2b3e805b 100644
--- a/util/system/progname.cpp
+++ b/util/system/progname.cpp
@@ -9,7 +9,7 @@ static const char* Argv0;
namespace {
struct TProgramNameHolder {
inline TProgramNameHolder()
- : ProgName(GetFileNameComponent(Argv0 ? Argv0 : GetExecPath().data()))
+ : ProgName(GetFileNameComponent(Argv0 ? Argv0 : GetExecPath().data()))
{
}
diff --git a/util/system/protect.cpp b/util/system/protect.cpp
index bbb8d410df..20a4ba5a08 100644
--- a/util/system/protect.cpp
+++ b/util/system/protect.cpp
@@ -29,7 +29,7 @@ static TString ModeToString(const EProtectMemory mode) {
if (mode & PM_EXEC) {
strMode += "PM_EXEC|";
}
- return strMode.substr(0, strMode.size() - 1);
+ return strMode.substr(0, strMode.size() - 1);
}
void ProtectMemory(void* addr, const size_t length, const EProtectMemory mode) {
diff --git a/util/system/shellcommand.cpp b/util/system/shellcommand.cpp
index b1989b5c8c..aa84ea1661 100644
--- a/util/system/shellcommand.cpp
+++ b/util/system/shellcommand.cpp
@@ -563,13 +563,13 @@ void TShellCommand::TImpl::StartProcess(TShellCommand::TImpl::TPipes& pipes) {
Y_ENSURE_EX(cmd.size() < MAX_COMMAND_LINE, yexception() << "Command is too long (length=" << cmd.size() << ")");
TTempArray<wchar_t> cmdcopy(MAX_COMMAND_LINE);
- Copy(cmd.data(), cmd.data() + cmd.size(), cmdcopy.Data());
- *(cmdcopy.Data() + cmd.size()) = 0;
+ Copy(cmd.data(), cmd.data() + cmd.size(), cmdcopy.Data());
+ *(cmdcopy.Data() + cmd.size()) = 0;
const wchar_t* cwd = NULL;
std::wstring cwdBuff;
- if (WorkDir.size()) {
- cwdBuff = GetWString(WorkDir.data());
+ if (WorkDir.size()) {
+ cwdBuff = GetWString(WorkDir.data());
cwd = cwdBuff.c_str();
}
@@ -580,7 +580,7 @@ void TShellCommand::TImpl::StartProcess(TShellCommand::TImpl::TPipes& pipes) {
env += e->first + '=' + e->second + '\0';
}
env += '\0';
- lpEnvironment = const_cast<char*>(env.data());
+ lpEnvironment = const_cast<char*>(env.data());
}
// disable messagebox (may be in debug too)
@@ -602,9 +602,9 @@ void TShellCommand::TImpl::StartProcess(TShellCommand::TImpl::TPipes& pipes) {
&process_info);
} else {
res = CreateProcessWithLogonW(
- GetWString(User.Name.data()).c_str(),
+ GetWString(User.Name.data()).c_str(),
nullptr, // domain (if this parameter is NULL, the user name must be specified in UPN format)
- GetWString(User.Password.data()).c_str(),
+ GetWString(User.Password.data()).c_str(),
0, // logon flags
NULL, // image name
cmdcopy.Data(),
@@ -796,12 +796,12 @@ void TShellCommand::TImpl::Run() {
qargv.push_back(const_cast<char*>("-c"));
// two args for 'sh -c -- ',
// one for program name, and one for NULL at the end
- qargv.push_back(const_cast<char*>(shellArg.data()));
+ qargv.push_back(const_cast<char*>(shellArg.data()));
} else {
qargv.reserve(Arguments.size() + 2);
- qargv.push_back(const_cast<char*>(Command.data()));
+ qargv.push_back(const_cast<char*>(Command.data()));
for (auto& i : Arguments) {
- qargv.push_back(const_cast<char*>(i.data()));
+ qargv.push_back(const_cast<char*>(i.data()));
}
}
@@ -812,7 +812,7 @@ void TShellCommand::TImpl::Run() {
if (!Environment.empty()) {
for (auto& env : Environment) {
envHolder.emplace_back(env.first + '=' + env.second);
- envp.push_back(const_cast<char*>(envHolder.back().data()));
+ envp.push_back(const_cast<char*>(envHolder.back().data()));
}
envp.push_back(nullptr);
}
diff --git a/util/system/shellcommand_ut.cpp b/util/system/shellcommand_ut.cpp
index 9d849279d2..cea2777100 100644
--- a/util/system/shellcommand_ut.cpp
+++ b/util/system/shellcommand_ut.cpp
@@ -139,7 +139,7 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) {
<< "sort";
cmd.Run();
UNIT_ASSERT(TShellCommand::SHELL_FINISHED == cmd.GetStatus());
- UNIT_ASSERT_VALUES_EQUAL(cmd.GetError().size(), 0u);
+ UNIT_ASSERT_VALUES_EQUAL(cmd.GetError().size(), 0u);
UNIT_ASSERT(cmd.GetExitCode().Defined() && 0 == cmd.GetExitCode());
}
}
@@ -164,7 +164,7 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) {
UNIT_ASSERT_VALUES_EQUAL(cmd.GetError(), "");
#if !defined(_win_)
UNIT_ASSERT(TShellCommand::SHELL_FINISHED == cmd.GetStatus());
- UNIT_ASSERT_VALUES_EQUAL(cmd.GetOutput().size(), 0u);
+ UNIT_ASSERT_VALUES_EQUAL(cmd.GetOutput().size(), 0u);
UNIT_ASSERT(cmd.GetExitCode().Defined() && 0 == cmd.GetExitCode());
#endif
}
@@ -183,20 +183,20 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) {
#else
UNIT_ASSERT_VALUES_EQUAL(input, output);
#endif
- UNIT_ASSERT_VALUES_EQUAL(cmd.GetError().size(), 0u);
+ UNIT_ASSERT_VALUES_EQUAL(cmd.GetError().size(), 0u);
}
Y_UNIT_TEST(TestRunNonexistent) {
TShellCommand cmd("iwerognweiofnewio"); // some nonexistent command name
cmd.Run().Wait();
UNIT_ASSERT(TShellCommand::SHELL_ERROR == cmd.GetStatus());
- UNIT_ASSERT_VALUES_UNEQUAL(cmd.GetError().size(), 0u);
+ UNIT_ASSERT_VALUES_UNEQUAL(cmd.GetError().size(), 0u);
UNIT_ASSERT(cmd.GetExitCode().Defined() && 0 != cmd.GetExitCode());
}
Y_UNIT_TEST(TestExitCode) {
TShellCommand cmd("grep qwerty qwerty"); // some nonexistent file name
cmd.Run().Wait();
UNIT_ASSERT(TShellCommand::SHELL_ERROR == cmd.GetStatus());
- UNIT_ASSERT_VALUES_UNEQUAL(cmd.GetError().size(), 0u);
+ UNIT_ASSERT_VALUES_UNEQUAL(cmd.GetError().size(), 0u);
UNIT_ASSERT(cmd.GetExitCode().Defined() && 2 == cmd.GetExitCode());
}
// 'type con' and 'copy con con' want real console, not stdin, use sort
@@ -208,7 +208,7 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) {
TShellCommand cmd(catCommand, options);
cmd.Run().Wait();
UNIT_ASSERT_VALUES_EQUAL(input, cmd.GetOutput());
- UNIT_ASSERT_VALUES_EQUAL(cmd.GetError().size(), 0u);
+ UNIT_ASSERT_VALUES_EQUAL(cmd.GetError().size(), 0u);
}
Y_UNIT_TEST(TestOutput) {
TShellCommandOptions options;
@@ -221,7 +221,7 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) {
TShellCommand cmd(catCommand, options);
cmd.Run().Wait();
UNIT_ASSERT_VALUES_EQUAL(input, output);
- UNIT_ASSERT_VALUES_EQUAL(cmd.GetError().size(), 0u);
+ UNIT_ASSERT_VALUES_EQUAL(cmd.GetError().size(), 0u);
}
Y_UNIT_TEST(TestIO) {
// descriptive test: use all options
@@ -390,7 +390,7 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) {
TShellCommand cmd(catCommand, options);
cmd.Run().Wait();
UNIT_ASSERT(TShellCommand::SHELL_INTERNAL_ERROR == cmd.GetStatus());
- UNIT_ASSERT_VALUES_UNEQUAL(cmd.GetInternalError().size(), 0u);
+ UNIT_ASSERT_VALUES_UNEQUAL(cmd.GetInternalError().size(), 0u);
}
Y_UNIT_TEST(TestHugeOutput) {
TShellCommandOptions options;
diff --git a/util/system/shmat.cpp b/util/system/shmat.cpp
index 07ff0d6caa..6795f17164 100644
--- a/util/system/shmat.cpp
+++ b/util/system/shmat.cpp
@@ -170,7 +170,7 @@ static key_t GetKey(const TGUID& id) {
}
bool TSharedMemory::Open(const TGUID& id, int size) {
- Y_VERIFY(id, "invalid shared memory guid: %s", GetGuidAsString(id).data());
+ Y_VERIFY(id, "invalid shared memory guid: %s", GetGuidAsString(id).data());
//Y_ASSERT(Data == 0);
Size = size;
diff --git a/util/system/unaligned_mem.h b/util/system/unaligned_mem.h
index 4b84686f2f..61433ccfbe 100644
--- a/util/system/unaligned_mem.h
+++ b/util/system/unaligned_mem.h
@@ -16,11 +16,11 @@ inline T ReadUnaligned(const void* from) noexcept {
return ret;
}
-// std::remove_reference_t for non-deduced context to prevent such code to blow below:
-// ui8 first = f(); ui8 second = g();
-// WriteUnaligned(to, first - second) (int will be deduced)
+// std::remove_reference_t for non-deduced context to prevent such code to blow below:
+// ui8 first = f(); ui8 second = g();
+// WriteUnaligned(to, first - second) (int will be deduced)
template <class T>
-inline void WriteUnaligned(void* to, const std::remove_reference_t<T>& t) noexcept {
+inline void WriteUnaligned(void* to, const std::remove_reference_t<T>& t) noexcept {
memcpy(to, &t, sizeof(T));
}
diff --git a/util/system/unaligned_mem_ut.cpp b/util/system/unaligned_mem_ut.cpp
index 9de3f3e931..3b4ebd8887 100644
--- a/util/system/unaligned_mem_ut.cpp
+++ b/util/system/unaligned_mem_ut.cpp
@@ -33,9 +33,9 @@ Y_UNIT_TEST_SUITE(UnalignedMem) {
Y_UNIT_TEST(TestReadWrite) {
alignas(ui64) char buf[100];
- WriteUnaligned<ui16>(buf + 1, (ui16)1);
- WriteUnaligned<ui32>(buf + 1 + 2, (ui32)2);
- WriteUnaligned<ui64>(buf + 1 + 2 + 4, (ui64)3);
+ WriteUnaligned<ui16>(buf + 1, (ui16)1);
+ WriteUnaligned<ui32>(buf + 1 + 2, (ui32)2);
+ WriteUnaligned<ui64>(buf + 1 + 2 + 4, (ui64)3);
UNIT_ASSERT_VALUES_EQUAL(ReadUnaligned<ui16>(buf + 1), 1);
UNIT_ASSERT_VALUES_EQUAL(ReadUnaligned<ui32>(buf + 1 + 2), 2);
@@ -48,9 +48,9 @@ Y_UNIT_TEST_SUITE(UnalignedMem) {
alignas(ui64) static char buf[100] = {0}; // static is required for Clobber to work
- WriteUnaligned<ui16>(buf + 1, (ui16)1);
- WriteUnaligned<ui32>(buf + 1 + 2, (ui32)2);
- WriteUnaligned<ui64>(buf + 1 + 2 + 4, (ui64)3);
+ WriteUnaligned<ui16>(buf + 1, (ui16)1);
+ WriteUnaligned<ui32>(buf + 1 + 2, (ui32)2);
+ WriteUnaligned<ui64>(buf + 1 + 2 + 4, (ui64)3);
NBench::Clobber();
auto val1 = ReadUnaligned<ui16>(buf + 1);
@@ -72,7 +72,7 @@ Y_UNIT_TEST_SUITE(UnalignedMem) {
Y_UNIT_TEST(TestReadWrite128) {
alignas(TUInt128) char buf[100] = {0};
- WriteUnaligned<TUInt128>(buf + 1, TUInt128::Max());
+ WriteUnaligned<TUInt128>(buf + 1, TUInt128::Max());
auto val = ReadUnaligned<TUInt128>(buf + 1);
UNIT_ASSERT(val == TUInt128::Max());
}
@@ -82,7 +82,7 @@ Y_UNIT_TEST_SUITE(UnalignedMem) {
alignas(TUInt128) static char buf[100] = {0}; // static is required for Clobber to work
- WriteUnaligned<TUInt128>(buf + 1, TUInt128::Max());
+ WriteUnaligned<TUInt128>(buf + 1, TUInt128::Max());
NBench::Clobber();
auto val = ReadUnaligned<TUInt128>(buf + 1);
diff --git a/util/ysaveload_ut.cpp b/util/ysaveload_ut.cpp
index 723c68f391..4030241313 100644
--- a/util/ysaveload_ut.cpp
+++ b/util/ysaveload_ut.cpp
@@ -253,7 +253,7 @@ private:
TVector<ui16> vec;
Load(&S_, vec);
- UNIT_ASSERT_EQUAL(vec.size(), 3);
+ UNIT_ASSERT_EQUAL(vec.size(), 3);
UNIT_ASSERT_EQUAL(vec[0], 1);
UNIT_ASSERT_EQUAL(vec[1], 2);
UNIT_ASSERT_EQUAL(vec[2], 4);
@@ -306,8 +306,8 @@ private:
TBuffer buf;
Load(&S_, buf);
- UNIT_ASSERT_EQUAL(buf.size(), 4);
- UNIT_ASSERT_EQUAL(memcmp(buf.data(), "asdf", 4), 0);
+ UNIT_ASSERT_EQUAL(buf.size(), 4);
+ UNIT_ASSERT_EQUAL(memcmp(buf.data(), "asdf", 4), 0);
}
{
@@ -316,7 +316,7 @@ private:
Load(&S_, vec, pool);
- UNIT_ASSERT_EQUAL(vec.size(), 3);
+ UNIT_ASSERT_EQUAL(vec.size(), 3);
UNIT_ASSERT_EQUAL(vec[0], TString("1"));
UNIT_ASSERT_EQUAL(vec[1], TString("123"));
UNIT_ASSERT_EQUAL(vec[2], TString("4567"));
@@ -327,7 +327,7 @@ private:
Load(&S_, deq);
- UNIT_ASSERT_EQUAL(deq.size(), 4);
+ UNIT_ASSERT_EQUAL(deq.size(), 4);
UNIT_ASSERT_EQUAL(deq[0], 1);
UNIT_ASSERT_EQUAL(deq[1], 2);
UNIT_ASSERT_EQUAL(deq[2], 4);