aboutsummaryrefslogtreecommitdiffstats
path: root/library
diff options
context:
space:
mode:
authormelkov <melkov@yandex-team.ru>2022-02-10 16:48:13 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:48:13 +0300
commit438546c8737d5c1fdeb31157dcf999717d930eec (patch)
treed29d229abd2f9f889b9b7eb148d635059dc26acf /library
parent96647fad5355ff5ef45a00a6d85c097028584ab0 (diff)
downloadydb-438546c8737d5c1fdeb31157dcf999717d930eec.tar.gz
Restoring authorship annotation for <melkov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library')
-rw-r--r--library/cpp/cgiparam/cgiparam.cpp76
-rw-r--r--library/cpp/cgiparam/cgiparam.h38
-rw-r--r--library/cpp/cgiparam/cgiparam_ut.cpp42
-rw-r--r--library/cpp/charset/codepage.cpp22
-rw-r--r--library/cpp/charset/codepage.h8
-rw-r--r--library/cpp/deprecated/mapped_file/mapped_file.cpp4
-rw-r--r--library/cpp/deprecated/mapped_file/mapped_file.h10
-rw-r--r--library/cpp/digest/md5/md5.cpp10
-rw-r--r--library/cpp/getopt/small/opt.cpp2
-rw-r--r--library/cpp/getopt/small/opt2.cpp540
-rw-r--r--library/cpp/getopt/small/opt2.h144
-rw-r--r--library/cpp/getopt/ut/opt2_ut.cpp34
-rw-r--r--library/cpp/packedtypes/packedfloat.cpp24
-rw-r--r--library/cpp/string_utils/base64/base64.cpp14
-rw-r--r--library/cpp/string_utils/url/url.cpp58
-rw-r--r--library/cpp/string_utils/url/url.h4
-rw-r--r--library/cpp/string_utils/url/url_ut.cpp36
-rw-r--r--library/cpp/testing/unittest/utmain.cpp14
-rw-r--r--library/cpp/yson/node/node.h14
19 files changed, 547 insertions, 547 deletions
diff --git a/library/cpp/cgiparam/cgiparam.cpp b/library/cpp/cgiparam/cgiparam.cpp
index f3277b8e4b..3b1e3c7661 100644
--- a/library/cpp/cgiparam/cgiparam.cpp
+++ b/library/cpp/cgiparam/cgiparam.cpp
@@ -227,47 +227,47 @@ bool TCgiParameters::Has(const TStringBuf name, const TStringBuf value) const no
return false;
}
-
-TQuickCgiParam::TQuickCgiParam(const TStringBuf cgiParamStr) {
+
+TQuickCgiParam::TQuickCgiParam(const TStringBuf cgiParamStr) {
UnescapeBuf.reserve(CgiUnescapeBufLen(cgiParamStr.size()));
- char* buf = UnescapeBuf.begin();
-
- auto f = [this, &buf](const TStringBuf key, const TStringBuf val) {
- TStringBuf name = CgiUnescapeBuf(buf, key);
+ char* buf = UnescapeBuf.begin();
+
+ auto f = [this, &buf](const TStringBuf key, const TStringBuf val) {
+ TStringBuf name = CgiUnescapeBuf(buf, key);
buf += name.size() + 1;
- TStringBuf value = CgiUnescapeBuf(buf, val);
+ TStringBuf value = CgiUnescapeBuf(buf, val);
buf += value.size() + 1;
Y_ASSERT(buf <= UnescapeBuf.begin() + UnescapeBuf.capacity() + 1 /*trailing zero*/);
- emplace(name, value);
- };
-
- DoScan<false>(cgiParamStr, f);
-
- if (buf != UnescapeBuf.begin()) {
- UnescapeBuf.ReserveAndResize(buf - UnescapeBuf.begin() - 1 /*trailing zero*/);
- }
-}
-
+ emplace(name, value);
+ };
+
+ DoScan<false>(cgiParamStr, f);
+
+ if (buf != UnescapeBuf.begin()) {
+ UnescapeBuf.ReserveAndResize(buf - UnescapeBuf.begin() - 1 /*trailing zero*/);
+ }
+}
+
const TStringBuf& TQuickCgiParam::Get(const TStringBuf name, size_t pos) const noexcept {
- const auto pair = equal_range(name);
-
- for (auto it = pair.first; it != pair.second; ++it, --pos) {
- if (0 == pos) {
- return it->second;
- }
- }
-
- return Default<TStringBuf>();
-}
-
+ const auto pair = equal_range(name);
+
+ for (auto it = pair.first; it != pair.second; ++it, --pos) {
+ if (0 == pos) {
+ return it->second;
+ }
+ }
+
+ return Default<TStringBuf>();
+}
+
bool TQuickCgiParam::Has(const TStringBuf name, const TStringBuf value) const noexcept {
- const auto pair = equal_range(name);
-
- for (auto it = pair.first; it != pair.second; ++it) {
- if (value == it->second) {
- return true;
- }
- }
-
- return false;
-}
+ const auto pair = equal_range(name);
+
+ for (auto it = pair.first; it != pair.second; ++it) {
+ if (value == it->second) {
+ return true;
+ }
+ }
+
+ return false;
+}
diff --git a/library/cpp/cgiparam/cgiparam.h b/library/cpp/cgiparam/cgiparam.h
index 87d1ab0ad4..c7102bc40f 100644
--- a/library/cpp/cgiparam/cgiparam.h
+++ b/library/cpp/cgiparam/cgiparam.h
@@ -155,30 +155,30 @@ void TCgiParameters::ReplaceUnescaped(const TStringBuf key, TIter valuesBegin, c
}
}
}
-
-/** TQuickCgiParam is a faster non-editable version of TCgiParameters.
- * Care should be taken when replacing:
- * - note that the result of Get() is invalidated when TQuickCgiParam object is destroyed.
- */
-
-class TQuickCgiParam: public TMultiMap<TStringBuf, TStringBuf> {
-public:
+
+/** TQuickCgiParam is a faster non-editable version of TCgiParameters.
+ * Care should be taken when replacing:
+ * - note that the result of Get() is invalidated when TQuickCgiParam object is destroyed.
+ */
+
+class TQuickCgiParam: public TMultiMap<TStringBuf, TStringBuf> {
+public:
TQuickCgiParam() = default;
-
- explicit TQuickCgiParam(const TStringBuf cgiParamStr);
-
+
+ explicit TQuickCgiParam(const TStringBuf cgiParamStr);
+
Y_PURE_FUNCTION
bool Has(const TStringBuf name, const TStringBuf value) const noexcept;
Y_PURE_FUNCTION
bool Has(const TStringBuf name) const noexcept {
- const auto pair = equal_range(name);
- return pair.first != pair.second;
- }
-
+ const auto pair = equal_range(name);
+ return pair.first != pair.second;
+ }
+
Y_PURE_FUNCTION
const TStringBuf& Get(const TStringBuf name, size_t numOfValue = 0) const noexcept;
-
-private:
- TString UnescapeBuf;
-};
+
+private:
+ TString UnescapeBuf;
+};
diff --git a/library/cpp/cgiparam/cgiparam_ut.cpp b/library/cpp/cgiparam/cgiparam_ut.cpp
index a562342084..eb185b3370 100644
--- a/library/cpp/cgiparam/cgiparam_ut.cpp
+++ b/library/cpp/cgiparam/cgiparam_ut.cpp
@@ -17,27 +17,27 @@ Y_UNIT_TEST_SUITE(TCgiParametersTest) {
UNIT_ASSERT(!C.Has("zzzzzz"));
}
- Y_UNIT_TEST(TestQuick) {
- TQuickCgiParam C("aaa=b%62b&ccc=ddd&ag0=");
- UNIT_ASSERT_EQUAL(C.Get("aaa") == "bbb", true);
- UNIT_ASSERT(C.Has("ccc", "ddd"));
- UNIT_ASSERT(C.Has("ag0", ""));
- UNIT_ASSERT(!C.Has("a", "bbb"));
- UNIT_ASSERT(!C.Has("aaa", "bb"));
-
- UNIT_ASSERT(C.Has("ccc"));
- UNIT_ASSERT(!C.Has("zzzzzz"));
-
- TQuickCgiParam D = std::move(C);
- UNIT_ASSERT(D.Has("aaa"));
-
- TQuickCgiParam E("");
- UNIT_ASSERT(!E.Has("aaa"));
-
- C = std::move(E);
- UNIT_ASSERT(!C.Has("aaa"));
- }
-
+ Y_UNIT_TEST(TestQuick) {
+ TQuickCgiParam C("aaa=b%62b&ccc=ddd&ag0=");
+ UNIT_ASSERT_EQUAL(C.Get("aaa") == "bbb", true);
+ UNIT_ASSERT(C.Has("ccc", "ddd"));
+ UNIT_ASSERT(C.Has("ag0", ""));
+ UNIT_ASSERT(!C.Has("a", "bbb"));
+ UNIT_ASSERT(!C.Has("aaa", "bb"));
+
+ UNIT_ASSERT(C.Has("ccc"));
+ UNIT_ASSERT(!C.Has("zzzzzz"));
+
+ TQuickCgiParam D = std::move(C);
+ UNIT_ASSERT(D.Has("aaa"));
+
+ TQuickCgiParam E("");
+ UNIT_ASSERT(!E.Has("aaa"));
+
+ C = std::move(E);
+ UNIT_ASSERT(!C.Has("aaa"));
+ }
+
Y_UNIT_TEST(TestScan2) {
const TString parsee("=000&aaa=bbb&ag0=&ccc=ddd");
TCgiParameters c;
diff --git a/library/cpp/charset/codepage.cpp b/library/cpp/charset/codepage.cpp
index 0431bef31b..537a4f9f79 100644
--- a/library/cpp/charset/codepage.cpp
+++ b/library/cpp/charset/codepage.cpp
@@ -72,7 +72,7 @@ int CodePage::stricmp(const char* dst, const char* src) const {
return f - l;
}
-int CodePage::strnicmp(const char* dst, const char* src, size_t len) const {
+int CodePage::strnicmp(const char* dst, const char* src, size_t len) const {
unsigned char f, l;
if (len) {
do {
@@ -258,8 +258,8 @@ void DoDecodeUnknownPlane(TxChar* str, TxChar*& ee, const ECharset enc) {
for (TxChar* s = str; s < e; s++) {
if (Hi8(Lo16(*s)) == 0xF0)
*s = (TxChar)cp->unicode[Lo8(Lo16(*s))]; // NOT mb compliant
- }
- } else if (enc == CODES_UTF8) {
+ }
+ } else if (enc == CODES_UTF8) {
TxChar* s;
TxChar* d;
@@ -272,13 +272,13 @@ void DoDecodeUnknownPlane(TxChar* str, TxChar*& ee, const ECharset enc) {
*d++ = BROKEN_RUNE;
++s;
}
- }
- e = d;
+ }
+ e = d;
} else if (enc == CODES_UNKNOWN) {
for (TxChar* s = str; s < e; s++) {
if (Hi8(Lo16(*s)) == 0xF0)
*s = Lo8(Lo16(*s));
- }
+ }
} else {
Y_ASSERT(!SingleByteCodepage(enc));
@@ -307,13 +307,13 @@ void DoDecodeUnknownPlane(TxChar* str, TxChar*& ee, const ECharset enc) {
*d++ = *s;
}
}
- }
- ee = e;
-}
-
+ }
+ ee = e;
+}
+
void DecodeUnknownPlane(wchar16* str, wchar16*& ee, const ECharset enc) {
DoDecodeUnknownPlane(str, ee, enc);
-}
+}
void DecodeUnknownPlane(wchar32* str, wchar32*& ee, const ECharset enc) {
DoDecodeUnknownPlane(str, ee, enc);
}
diff --git a/library/cpp/charset/codepage.h b/library/cpp/charset/codepage.h
index 30a02a4610..7b7d4ee48c 100644
--- a/library/cpp/charset/codepage.h
+++ b/library/cpp/charset/codepage.h
@@ -215,8 +215,8 @@ struct Encoder {
void Tr(const wchar32* in, char* out, size_t len) const;
void Tr(const wchar32* in, char* out) const;
char* DefaultPlane;
-};
-
+};
+
/*****************************************************************\
* struct Recoder *
\*****************************************************************/
@@ -287,10 +287,10 @@ inline unsigned char CodePage::ToTitle(unsigned char ch) const {
extern const CodePage& csYandex;
/// these functions change (lowers) [end] position in case of utf-8
-/// null character is NOT assumed or written at [*end]
+/// null character is NOT assumed or written at [*end]
void DecodeUnknownPlane(wchar16* start, wchar16*& end, const ECharset enc4unk);
void DecodeUnknownPlane(wchar32* start, wchar32*& end, const ECharset enc4unk);
-
+
inline void ToLower(char* s, size_t n, const CodePage& cp = csYandex) {
char* const e = s + n;
for (; s != e; ++s)
diff --git a/library/cpp/deprecated/mapped_file/mapped_file.cpp b/library/cpp/deprecated/mapped_file/mapped_file.cpp
index b0e4511299..10032d8aab 100644
--- a/library/cpp/deprecated/mapped_file/mapped_file.cpp
+++ b/library/cpp/deprecated/mapped_file/mapped_file.cpp
@@ -25,8 +25,8 @@ void TMappedFile::precharge(size_t off, size_t size) const {
return;
Map_->Precharge(off, size);
-}
-
+}
+
void TMappedFile::init(const TString& name) {
THolder<TFileMap> map(new TFileMap(name));
TMappedFile newFile(map.Get(), name.data());
diff --git a/library/cpp/deprecated/mapped_file/mapped_file.h b/library/cpp/deprecated/mapped_file/mapped_file.h
index 45859ed65a..32bd169c57 100644
--- a/library/cpp/deprecated/mapped_file/mapped_file.h
+++ b/library/cpp/deprecated/mapped_file/mapped_file.h
@@ -25,11 +25,11 @@ public:
TMappedFile() {
Map_ = nullptr;
}
-
+
~TMappedFile() {
term();
}
-
+
explicit TMappedFile(const TString& name) {
Map_ = nullptr;
init(name, TFileMap::oRdOnly);
@@ -54,16 +54,16 @@ public:
Map_ = nullptr;
}
}
-
+
size_t getSize() const {
return (Map_ ? Map_->MappedSize() : 0);
}
-
+
void* getData(size_t pos = 0) const {
Y_ASSERT(!Map_ || (pos <= getSize()));
return (Map_ ? (void*)((unsigned char*)Map_->Ptr() + pos) : nullptr);
}
-
+
void precharge(size_t pos = 0, size_t size = (size_t)-1) const;
void swap(TMappedFile& file) noexcept {
diff --git a/library/cpp/digest/md5/md5.cpp b/library/cpp/digest/md5/md5.cpp
index 24a5b69eef..198afaabd9 100644
--- a/library/cpp/digest/md5/md5.cpp
+++ b/library/cpp/digest/md5/md5.cpp
@@ -192,15 +192,15 @@ char* MD5::End(char* buf) {
char* MD5::End_b64(char* buf) {
ui8 digest[16];
if (!buf)
- buf = (char*)malloc(25);
+ buf = (char*)malloc(25);
if (!buf)
return nullptr;
- Final(digest);
+ Final(digest);
Base64Encode(buf, digest, 16);
buf[24] = '\0';
- return buf;
-}
-
+ return buf;
+}
+
ui64 MD5::EndHalfMix() {
ui8 digest[16];
Final(digest);
diff --git a/library/cpp/getopt/small/opt.cpp b/library/cpp/getopt/small/opt.cpp
index 744501765c..a78f8adc9d 100644
--- a/library/cpp/getopt/small/opt.cpp
+++ b/library/cpp/getopt/small/opt.cpp
@@ -116,4 +116,4 @@ int opt_get_number(int& argc, char* argv[]) {
}
}
return num;
-}
+}
diff --git a/library/cpp/getopt/small/opt2.cpp b/library/cpp/getopt/small/opt2.cpp
index 0cdc774e78..eba042e3a6 100644
--- a/library/cpp/getopt/small/opt2.cpp
+++ b/library/cpp/getopt/small/opt2.cpp
@@ -4,63 +4,63 @@
#include <util/generic/utility.h>
#include <util/generic/yexception.h>
#include <util/str_stl.h>
-
+
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
-void Opt2::Clear() {
- Specs.clear();
- memset(SpecsMap, 0, sizeof(SpecsMap));
- Pos.clear();
-}
-
+void Opt2::Clear() {
+ Specs.clear();
+ memset(SpecsMap, 0, sizeof(SpecsMap));
+ Pos.clear();
+}
+
void Opt2::Init(int argc, char* const* argv, const char* optspec, IntRange free_args_num, const char* long_alias) {
- Clear();
+ Clear();
Argc = argc;
- Argv = argv;
- HasErrors = false, BadPosCount = false, UnknownOption = 0, OptionMissingArg = 0;
+ Argv = argv;
+ HasErrors = false, BadPosCount = false, UnknownOption = 0, OptionMissingArg = 0;
UnknownLongOption = nullptr;
- OptionWrongArg = 0, RequiredOptionMissing = 0;
- EatArgv(optspec, long_alias);
- MinArgs = Min<int>(free_args_num.Left, free_args_num.Right);
- MaxArgs = Max<int>(free_args_num.Left, free_args_num.Right);
- if (!HasErrors && MinArgs != -1 && ((int)Pos.size() < MinArgs || (int)Pos.size() > MaxArgs))
- BadPosCount = HasErrors = true;
-}
-
+ OptionWrongArg = 0, RequiredOptionMissing = 0;
+ EatArgv(optspec, long_alias);
+ MinArgs = Min<int>(free_args_num.Left, free_args_num.Right);
+ MaxArgs = Max<int>(free_args_num.Left, free_args_num.Right);
+ if (!HasErrors && MinArgs != -1 && ((int)Pos.size() < MinArgs || (int)Pos.size() > MaxArgs))
+ BadPosCount = HasErrors = true;
+}
+
void Opt2::EatArgv(const char* optspec, const char* long_alias) {
- // some flags
- bool require_order = false;
- if (*optspec == '+') {
- require_order = true;
- optspec++;
- }
- if (*optspec == '-')
+ // some flags
+ bool require_order = false;
+ if (*optspec == '+') {
+ require_order = true;
+ optspec++;
+ }
+ if (*optspec == '-')
ythrow yexception() << "Flag '-' can not be used in Opt2's optspec";
- // step 1 - parse optspec
+ // step 1 - parse optspec
for (const char* s = optspec; *s; s++) {
- if (SpecsMap[(ui8)*s])
+ if (SpecsMap[(ui8)*s])
ythrow yexception() << "Symbol '" << *s << "' is met twice in Opt2's optspec";
- if (*s == '?' || *s == '-')
+ if (*s == '?' || *s == '-')
ythrow yexception() << "Opt2: Symbol '" << *s << "' can not be used in optspec because it is reserved";
- Specs.push_back(Opt2Param());
+ Specs.push_back(Opt2Param());
SpecsMap[(ui8)*s] = (ui8)Specs.size(); // actual index + 1
- Specs.back().opt = *s;
- if (s[1] == ':') {
- Specs.back().HasArg = true;
- if (s[2] == ':')
+ Specs.back().opt = *s;
+ if (s[1] == ':') {
+ Specs.back().HasArg = true;
+ if (s[2] == ':')
ythrow yexception() << "Opt2 does not accept optional parameters (e.g. \"a::\") in optspec";
- s++;
- }
- }
- // long_alias has a form "long-name1=A,long-name2=B", etc.
- // This implementation is limited to aliasing a single long option
- // with single short option (extend it if you really need).
+ s++;
+ }
+ }
+ // long_alias has a form "long-name1=A,long-name2=B", etc.
+ // This implementation is limited to aliasing a single long option
+ // with single short option (extend it if you really need).
THashMap<const char*, char> long2short;
- long2short["help"] = '?';
+ long2short["help"] = '?';
long_alias = long_alias ? long_alias : "";
- alias_copy = long_alias;
+ alias_copy = long_alias;
for (char* s = alias_copy.begin(); s && *s;) {
char* eq = strchr(s, '=');
char* comma = strchr(s, ',');
@@ -68,180 +68,180 @@ void Opt2::EatArgv(const char* optspec, const char* long_alias) {
*comma = 0;
if (!eq || (comma && comma < eq))
ythrow yexception() << "Opt2, long_alias: '=' is expected after " << s;
- *eq++ = 0;
- if (!*eq || eq[1])
+ *eq++ = 0;
+ if (!*eq || eq[1])
ythrow yexception() << "Opt2, long_alias: single letter must be assigned to " << s;
- if (!SpecsMap[(ui8)*eq])
+ if (!SpecsMap[(ui8)*eq])
ythrow yexception() << "Opt2, long_alias: trying to assign unknown option '" << *eq << "' to " << s;
Opt2Param& p = Specs[SpecsMap[(ui8)*eq] - 1];
- // If several long options aliased to some letter, only last one is shown in usage
- p.LongOptName = s;
- if (long2short.find(s) != long2short.end())
+ // If several long options aliased to some letter, only last one is shown in usage
+ p.LongOptName = s;
+ if (long2short.find(s) != long2short.end())
ythrow yexception() << "Opt2, long_alias: " << s << " specified twice";
- long2short[s] = *eq;
+ long2short[s] = *eq;
s = comma ? comma + 1 : nullptr;
- }
-
- if (Argc < 1) {
- HasErrors = true;
- return;
- }
-
- // step 2 - parse argv
- int ind = 1;
- for (; ind != Argc; ind++) {
- if (*Argv[ind] != '-') {
- if (require_order) // everything now goes to Pos
- break;
- Pos.push_back(Argv[ind]);
- continue;
- }
+ }
+
+ if (Argc < 1) {
+ HasErrors = true;
+ return;
+ }
+
+ // step 2 - parse argv
+ int ind = 1;
+ for (; ind != Argc; ind++) {
+ if (*Argv[ind] != '-') {
+ if (require_order) // everything now goes to Pos
+ break;
+ Pos.push_back(Argv[ind]);
+ continue;
+ }
const char* s = Argv[ind] + 1;
-
- if (*s == '-') {
- if (!*++s) { // `--' terminates the list of options
- ind++;
- break;
- }
- // long option always spans one argv (--switch or --option-name=value)
+
+ if (*s == '-') {
+ if (!*++s) { // `--' terminates the list of options
+ ind++;
+ break;
+ }
+ // long option always spans one argv (--switch or --option-name=value)
const char* eq = strchr(s, '=');
TString lname(s, eq ? (size_t)(eq - s) : (size_t)strlen(s));
THashMap<const char*, char>::iterator i = long2short.find(lname.data());
- if (i == long2short.end()) {
+ if (i == long2short.end()) {
UnknownLongOption = strdup(lname.data()); // free'd in AutoUsage()
- HasErrors = true;
- return;
- }
- if (i->second == '?') {
- UnknownOption = '?';
- HasErrors = true;
- continue;
- }
+ HasErrors = true;
+ return;
+ }
+ if (i->second == '?') {
+ UnknownOption = '?';
+ HasErrors = true;
+ continue;
+ }
Opt2Param& p = Specs[SpecsMap[(ui8)i->second] - 1];
- p.IsFound = true;
- if (p.HasArg && !eq) {
- HasErrors = true;
- OptionMissingArg = p.opt; // short option, indeed
- return;
- }
- if (!p.HasArg && eq) {
- HasErrors = true;
- OptionWrongArg = p.opt; // short option, indeed
- return;
- }
- if (eq)
- p.ActualValue.push_back(eq + 1);
- continue;
- }
-
- for (; *s; s++) {
- if (!SpecsMap[(ui8)*s]) {
- UnknownOption = *s;
- HasErrors = true;
- if (*s == '?')
- continue;
- return;
- }
+ p.IsFound = true;
+ if (p.HasArg && !eq) {
+ HasErrors = true;
+ OptionMissingArg = p.opt; // short option, indeed
+ return;
+ }
+ if (!p.HasArg && eq) {
+ HasErrors = true;
+ OptionWrongArg = p.opt; // short option, indeed
+ return;
+ }
+ if (eq)
+ p.ActualValue.push_back(eq + 1);
+ continue;
+ }
+
+ for (; *s; s++) {
+ if (!SpecsMap[(ui8)*s]) {
+ UnknownOption = *s;
+ HasErrors = true;
+ if (*s == '?')
+ continue;
+ return;
+ }
Opt2Param& p = Specs[SpecsMap[(ui8)*s] - 1];
- p.IsFound = true;
- if (p.HasArg) {
+ p.IsFound = true;
+ if (p.HasArg) {
if (s[1])
p.ActualValue.push_back(s + 1);
- else {
- ind++;
- if (ind == Argc) {
- HasErrors = true;
- OptionMissingArg = *s;
- p.IsFound = false;
- return;
- }
- p.ActualValue.push_back(Argv[ind]);
- }
- break;
- }
- }
- }
- for (; ind != Argc; ind++)
- Pos.push_back(Argv[ind]);
-}
-
+ else {
+ ind++;
+ if (ind == Argc) {
+ HasErrors = true;
+ OptionMissingArg = *s;
+ p.IsFound = false;
+ return;
+ }
+ p.ActualValue.push_back(Argv[ind]);
+ }
+ break;
+ }
+ }
+ }
+ for (; ind != Argc; ind++)
+ Pos.push_back(Argv[ind]);
+}
+
Opt2Param& Opt2::GetInternal(char opt, const char* defValue, const char* helpUsage, bool requred) {
- if (!SpecsMap[(ui8)opt])
+ if (!SpecsMap[(ui8)opt])
ythrow yexception() << "Unspecified option character '" << opt << "' asked from Opt2::Get";
Opt2Param& p = Specs[SpecsMap[(ui8)opt] - 1];
- p.DefValue = defValue;
- p.HelpUsage = helpUsage;
- p.IsRequired = requred;
- if (!p.IsFound && requred && !HasErrors) {
- RequiredOptionMissing = opt;
- HasErrors = true;
- }
- return p;
-}
-
-// For options with parameters
+ p.DefValue = defValue;
+ p.HelpUsage = helpUsage;
+ p.IsRequired = requred;
+ if (!p.IsFound && requred && !HasErrors) {
+ RequiredOptionMissing = opt;
+ HasErrors = true;
+ }
+ return p;
+}
+
+// For options with parameters
const char* Opt2::Arg(char opt, const char* help, const char* def, bool required) {
Opt2Param& p = GetInternal(opt, def, help, required);
- if (!p.HasArg)
+ if (!p.HasArg)
ythrow yexception() << "Opt2::Arg called for '" << opt << "' which is an option without argument";
return p.IsFound ? p.ActualValue.empty() ? nullptr : p.ActualValue.back() : def;
-}
-
-// For options with parameters
+}
+
+// For options with parameters
const char* Opt2::Arg(char opt, const char* help, TString def, bool required) {
Opt2Param& p = GetInternal(opt, nullptr, help, required);
- if (!p.HasArg)
+ if (!p.HasArg)
ythrow yexception() << "Opt2::Arg called for '" << opt << "' which is an option without argument";
- p.DefValueStr = def;
- p.DefValue = p.DefValueStr.begin();
+ p.DefValueStr = def;
+ p.DefValue = p.DefValueStr.begin();
return p.IsFound ? p.ActualValue.empty() ? nullptr : p.ActualValue.back() : p.DefValue;
-}
-
-// Options with parameters that can be specified several times
+}
+
+// Options with parameters that can be specified several times
const TVector<const char*>& Opt2::MArg(char opt, const char* help) {
Opt2Param& p = GetInternal(opt, nullptr, help, false);
- p.MultipleUse = true;
- if (!p.HasArg)
+ p.MultipleUse = true;
+ if (!p.HasArg)
ythrow yexception() << "Opt2::Arg called for '" << opt << "' which is an option without argument";
- return p.ActualValue;
-}
-
-/// For options w/o parameters
+ return p.ActualValue;
+}
+
+/// For options w/o parameters
bool Opt2::Has(char opt, const char* help) {
Opt2Param& p = GetInternal(opt, nullptr, help, false);
- if (p.HasArg)
+ if (p.HasArg)
ythrow yexception() << "Opt2::Has called for '" << opt << "' which is an option with argument";
- return p.IsFound;
-}
-
-// Get() + strtol, may set up HasErrors
+ return p.IsFound;
+}
+
+// Get() + strtol, may set up HasErrors
long Opt2::Int(char opt, const char* help, long def, bool required) {
Opt2Param& p = GetInternal(opt, (char*)(uintptr_t)def, help, required);
- if (!p.HasArg)
+ if (!p.HasArg)
ythrow yexception() << "Opt2::Int called for '" << opt << "' which is an option without argument";
- p.IsNumeric = true;
- if (!p.IsFound || p.ActualValue.empty() || !p.ActualValue.back())
- return def;
+ p.IsNumeric = true;
+ if (!p.IsFound || p.ActualValue.empty() || !p.ActualValue.back())
+ return def;
char* e;
- long rv = strtol(p.ActualValue.back(), &e, 10);
- if (e == p.ActualValue.back() || *e) {
- OptionWrongArg = opt;
- HasErrors = true;
- }
- return rv;
-}
-
+ long rv = strtol(p.ActualValue.back(), &e, 10);
+ if (e == p.ActualValue.back() || *e) {
+ OptionWrongArg = opt;
+ HasErrors = true;
+ }
+ return rv;
+}
+
// Get() + strtoul, may set up HasErrors
unsigned long Opt2::UInt(char opt, const char* help, unsigned long def, bool required) {
Opt2Param& p = GetInternal(opt, (char*)(uintptr_t)def, help, required);
if (!p.HasArg)
ythrow yexception() << "Opt2::UInt called for '" << opt << "' which is an option without argument";
p.IsNumeric = true;
- if (!p.IsFound || p.ActualValue.empty() || !p.ActualValue.back())
+ if (!p.IsFound || p.ActualValue.empty() || !p.ActualValue.back())
return def;
char* e;
- unsigned long rv = strtoul(p.ActualValue.back(), &e, 10);
- if (e == p.ActualValue.back() || *e) {
+ unsigned long rv = strtoul(p.ActualValue.back(), &e, 10);
+ if (e == p.ActualValue.back() || *e) {
OptionWrongArg = opt;
HasErrors = true;
}
@@ -256,17 +256,17 @@ void Opt2::AddError(const char* message) {
}
int Opt2::AutoUsage(const char* free_arg_names) {
- if (!HasErrors)
- return 0;
+ if (!HasErrors)
+ return 0;
FILE* where = UnknownOption == '?' ? stdout : stderr;
- char req_str[256], nreq_str[256];
- int req = 0, nreq = 0;
- for (int n = 0; n < (int)Specs.size(); n++)
- if (Specs[n].IsRequired)
- req_str[req++] = Specs[n].opt;
- else
- nreq_str[nreq++] = Specs[n].opt;
- req_str[req] = 0, nreq_str[nreq] = 0;
+ char req_str[256], nreq_str[256];
+ int req = 0, nreq = 0;
+ for (int n = 0; n < (int)Specs.size(); n++)
+ if (Specs[n].IsRequired)
+ req_str[req++] = Specs[n].opt;
+ else
+ nreq_str[nreq++] = Specs[n].opt;
+ req_str[req] = 0, nreq_str[nreq] = 0;
const char* prog = strrchr(Argv[0], LOCSLASH_C);
prog = prog ? prog + 1 : Argv[0];
fprintf(where, "Usage: %s%s%s%s%s%s%s%s\n", prog, req ? " -" : "", req_str,
@@ -278,107 +278,107 @@ int Opt2::AutoUsage(const char* free_arg_names) {
fprintf(where, " -%c %s\n", spec.opt, hlp);
else if (!spec.IsNumeric)
fprintf(where, " -%c %s [Default: %s]\n", spec.opt, hlp, spec.DefValue);
- else
+ else
fprintf(where, " -%c %s [Def.val: %li]\n", spec.opt, hlp, (long)(uintptr_t)spec.DefValue);
if (spec.LongOptName)
fprintf(where, " --%s%s - same as -%c\n", spec.LongOptName, spec.HasArg ? "=<argument>" : "", spec.opt);
- }
- if (OptionMissingArg)
- fprintf(where, " *** Option '%c' is missing required argument\n", OptionMissingArg);
- if (OptionWrongArg)
- fprintf(where, " *** Incorrect argument for option '%c'\n", OptionWrongArg);
- if (UnknownOption && UnknownOption != '?')
- fprintf(where, " *** Unknown option '%c'\n", UnknownOption);
- if (UnknownLongOption) {
- fprintf(where, " *** Unknown long option '%s'\n", UnknownLongOption);
- free(UnknownLongOption);
+ }
+ if (OptionMissingArg)
+ fprintf(where, " *** Option '%c' is missing required argument\n", OptionMissingArg);
+ if (OptionWrongArg)
+ fprintf(where, " *** Incorrect argument for option '%c'\n", OptionWrongArg);
+ if (UnknownOption && UnknownOption != '?')
+ fprintf(where, " *** Unknown option '%c'\n", UnknownOption);
+ if (UnknownLongOption) {
+ fprintf(where, " *** Unknown long option '%s'\n", UnknownLongOption);
+ free(UnknownLongOption);
UnknownLongOption = nullptr;
- }
- if (RequiredOptionMissing)
- fprintf(where, " *** Required option '%c' missing\n", RequiredOptionMissing);
- if (BadPosCount && MinArgs != MaxArgs)
- fprintf(where, " *** %i free argument(s) supplied, expected %i to %i\n", (int)Pos.size(), MinArgs, MaxArgs);
- if (BadPosCount && MinArgs == MaxArgs)
- fprintf(where, " *** %i free argument(s) supplied, expected %i\n", (int)Pos.size(), MinArgs);
+ }
+ if (RequiredOptionMissing)
+ fprintf(where, " *** Required option '%c' missing\n", RequiredOptionMissing);
+ if (BadPosCount && MinArgs != MaxArgs)
+ fprintf(where, " *** %i free argument(s) supplied, expected %i to %i\n", (int)Pos.size(), MinArgs, MaxArgs);
+ if (BadPosCount && MinArgs == MaxArgs)
+ fprintf(where, " *** %i free argument(s) supplied, expected %i\n", (int)Pos.size(), MinArgs);
for (const auto& userErrorMessage : UserErrorMessages)
fprintf(where, " *** %s\n", userErrorMessage.data());
- return UnknownOption == '?' ? 1 : 2;
-}
-
+ return UnknownOption == '?' ? 1 : 2;
+}
+
void Opt2::AutoUsageErr(const char* free_arg_names) {
- if (AutoUsage(free_arg_names))
- exit(1);
-}
-
-#ifdef OPT2_TEST
-// TODO: convert it to unittest
-
-bool opt2_ut_fail = false, opt_ut_verbose = false;
+ if (AutoUsage(free_arg_names))
+ exit(1);
+}
+
+#ifdef OPT2_TEST
+// TODO: convert it to unittest
+
+bool opt2_ut_fail = false, opt_ut_verbose = false;
const char* ut_optspec;
int ut_real(TString args, bool err_exp, const char* A_exp, int b_exp, bool a_exp, const char* p1_exp, const char* p2_exp) {
char* argv[32];
- int argc = sf(' ', argv, args.begin());
- Opt2 opt(argc, argv, ut_optspec, 2, "option-1=A,option-2=a,");
+ int argc = sf(' ', argv, args.begin());
+ Opt2 opt(argc, argv, ut_optspec, 2, "option-1=A,option-2=a,");
const char* A = opt.Arg('A', "<qqq> - blah");
int b = opt.Int('b', "<rrr> - blah", 2);
bool a = opt.Has('a', "- blah");
/*const char *C = */ opt.Arg('C', "<ccc> - blah", 0);
-
- if (opt_ut_verbose)
- opt.AutoUsage("");
- if (opt.HasErrors != err_exp)
- return 1;
- if (err_exp)
- return false;
- if (!A && A_exp || A && !A_exp || A && A_exp && strcmp(A, A_exp))
- return 2;
- if (b != b_exp)
- return 3;
- if (a != a_exp)
- return 4;
- if (strcmp(opt.Pos[0], p1_exp))
- return 5;
- if (strcmp(opt.Pos[1], p2_exp))
- return 6;
- return false;
-}
-
+
+ if (opt_ut_verbose)
+ opt.AutoUsage("");
+ if (opt.HasErrors != err_exp)
+ return 1;
+ if (err_exp)
+ return false;
+ if (!A && A_exp || A && !A_exp || A && A_exp && strcmp(A, A_exp))
+ return 2;
+ if (b != b_exp)
+ return 3;
+ if (a != a_exp)
+ return 4;
+ if (strcmp(opt.Pos[0], p1_exp))
+ return 5;
+ if (strcmp(opt.Pos[1], p2_exp))
+ return 6;
+ return false;
+}
+
void ut(const char* args, bool err_exp, const char* A_exp, int b_exp, bool a_exp, const char* p1_exp, const char* p2_exp) {
- if (opt_ut_verbose)
- fprintf(stderr, "Testing: %s\n", args);
- if (int rv = ut_real(args, err_exp, A_exp, b_exp, a_exp, p1_exp, p2_exp)) {
- opt2_ut_fail = true;
- fprintf(stderr, "Test %i failed for: %s\n", rv, args);
- } else {
- if (opt_ut_verbose)
- fprintf(stderr, "OK\n");
- }
-}
-
+ if (opt_ut_verbose)
+ fprintf(stderr, "Testing: %s\n", args);
+ if (int rv = ut_real(args, err_exp, A_exp, b_exp, a_exp, p1_exp, p2_exp)) {
+ opt2_ut_fail = true;
+ fprintf(stderr, "Test %i failed for: %s\n", rv, args);
+ } else {
+ if (opt_ut_verbose)
+ fprintf(stderr, "OK\n");
+ }
+}
+
int main(int argc, char* argv[]) {
- Opt2 opt(argc, argv, "v", 0);
- opt_ut_verbose = opt.Has('v', "- some verboseness");
- opt.AutoUsageErr("");
- ut_optspec = "A:ab:C:";
- ut("prog -A argA -a -b 22 -C argC Pos1 Pos2", false, "argA", 22, true, "Pos1", "Pos2");
- ut("prog Pos1 -A argA -a -C argC Pos2", false, "argA", 2, true, "Pos1", "Pos2");
- ut("prog -A argA Pos1 -b22 Pos2 -C argC", false, "argA", 22, false, "Pos1", "Pos2");
- ut("prog -A argA Pos1 -b 22 Pos2 -C", true, "argA", 22, false, "Pos1", "Pos2");
- ut("prog -A argA -a -b 22 -C Pos1 Pos2", true, "argA", 22, true, "Pos1", "Pos2");
- ut("prog -A argA -a -b two -C argC Pos1 Pos2", true, "argA", 2, true, "Pos1", "Pos2");
- ut("prog -a -b 22 -C argC Pos1 Pos2", true, "argA", 22, true, "Pos1", "Pos2");
- ut("prog Pos1 --option-1=argA -a -C argC Pos2", false, "argA", 2, true, "Pos1", "Pos2");
- ut("prog Pos1 -A argA --option-1 -a -C argC Pos2", true, "argA", 2, true, "Pos1", "Pos2");
- ut("prog -A argA --option-2 -b -22 -C argC Pos1 Pos2", false, "argA", -22, true, "Pos1", "Pos2");
- ut("prog -A argA --option-2 -b -22 -- -C argC", false, "argA", -22, true, "-C", "argC");
- ut("prog -A argA --option-2=1 -b -22 -C argC Pos1 Pos2", true, "argA", -22, true, "Pos1", "Pos2");
-
- ut_optspec = "+A:ab:C:";
- ut("prog -A argA --option-2 v1 -C", false, "argA", 2, true, "v1", "-C");
- ut("prog -A argA --option-2 v1 -C argC", true, "argA", 2, true, "v1", "-C");
- if (!opt2_ut_fail)
- fprintf(stderr, "All OK\n");
- return opt2_ut_fail;
-}
-
-#endif // OPT2_TEST
+ Opt2 opt(argc, argv, "v", 0);
+ opt_ut_verbose = opt.Has('v', "- some verboseness");
+ opt.AutoUsageErr("");
+ ut_optspec = "A:ab:C:";
+ ut("prog -A argA -a -b 22 -C argC Pos1 Pos2", false, "argA", 22, true, "Pos1", "Pos2");
+ ut("prog Pos1 -A argA -a -C argC Pos2", false, "argA", 2, true, "Pos1", "Pos2");
+ ut("prog -A argA Pos1 -b22 Pos2 -C argC", false, "argA", 22, false, "Pos1", "Pos2");
+ ut("prog -A argA Pos1 -b 22 Pos2 -C", true, "argA", 22, false, "Pos1", "Pos2");
+ ut("prog -A argA -a -b 22 -C Pos1 Pos2", true, "argA", 22, true, "Pos1", "Pos2");
+ ut("prog -A argA -a -b two -C argC Pos1 Pos2", true, "argA", 2, true, "Pos1", "Pos2");
+ ut("prog -a -b 22 -C argC Pos1 Pos2", true, "argA", 22, true, "Pos1", "Pos2");
+ ut("prog Pos1 --option-1=argA -a -C argC Pos2", false, "argA", 2, true, "Pos1", "Pos2");
+ ut("prog Pos1 -A argA --option-1 -a -C argC Pos2", true, "argA", 2, true, "Pos1", "Pos2");
+ ut("prog -A argA --option-2 -b -22 -C argC Pos1 Pos2", false, "argA", -22, true, "Pos1", "Pos2");
+ ut("prog -A argA --option-2 -b -22 -- -C argC", false, "argA", -22, true, "-C", "argC");
+ ut("prog -A argA --option-2=1 -b -22 -C argC Pos1 Pos2", true, "argA", -22, true, "Pos1", "Pos2");
+
+ ut_optspec = "+A:ab:C:";
+ ut("prog -A argA --option-2 v1 -C", false, "argA", 2, true, "v1", "-C");
+ ut("prog -A argA --option-2 v1 -C argC", true, "argA", 2, true, "v1", "-C");
+ if (!opt2_ut_fail)
+ fprintf(stderr, "All OK\n");
+ return opt2_ut_fail;
+}
+
+#endif // OPT2_TEST
diff --git a/library/cpp/getopt/small/opt2.h b/library/cpp/getopt/small/opt2.h
index 4d9d943237..51800d0f6e 100644
--- a/library/cpp/getopt/small/opt2.h
+++ b/library/cpp/getopt/small/opt2.h
@@ -3,33 +3,33 @@
#include <util/system/defaults.h>
#include <util/generic/string.h>
#include <util/generic/vector.h>
-
-// simplified options parser
-// No 'optional argument' (e.g. "a::" in spec.) support;
-// Supports '+' switch (see opt.h), does not support '-';
-
-/** Typical use
- Opt2 opt(argc, argv, "A:b:c", 3); <- 3 more arguments expected, opt.Pos[0], etc.
- ** Usage description for options is provided through functions that query values **
- const char *a = opt.Arg('A', "<var_name> - usage of -A"); <- This option is required
- int b = opt.Int('b', "<var_name> - usage of -b", 2); <- This option has default value, not required
- bool c = opt.Has('c', "- usage of -c"); <- switches are always optional
-
- ** Additional argument names are provided in AutoUsage call **
- ** AutoUsage generages 'USAGE' text automatically **
- if (opt.AutoUsage("<L> <M>")) <- Returns 1 if there was any error in getopt
- return 1;
- OR: opt.AutoUsageErr("<L> <M>"); <- Will terminate program for you :)
-*/
-
-// Note: struct Opt2Param can be moved to cpp-file
-struct Opt2Param {
- char opt;
- bool HasArg;
- bool IsFound;
- bool IsNumeric;
- bool IsRequired;
- bool MultipleUse;
+
+// simplified options parser
+// No 'optional argument' (e.g. "a::" in spec.) support;
+// Supports '+' switch (see opt.h), does not support '-';
+
+/** Typical use
+ Opt2 opt(argc, argv, "A:b:c", 3); <- 3 more arguments expected, opt.Pos[0], etc.
+ ** Usage description for options is provided through functions that query values **
+ const char *a = opt.Arg('A', "<var_name> - usage of -A"); <- This option is required
+ int b = opt.Int('b', "<var_name> - usage of -b", 2); <- This option has default value, not required
+ bool c = opt.Has('c', "- usage of -c"); <- switches are always optional
+
+ ** Additional argument names are provided in AutoUsage call **
+ ** AutoUsage generages 'USAGE' text automatically **
+ if (opt.AutoUsage("<L> <M>")) <- Returns 1 if there was any error in getopt
+ return 1;
+ OR: opt.AutoUsageErr("<L> <M>"); <- Will terminate program for you :)
+*/
+
+// Note: struct Opt2Param can be moved to cpp-file
+struct Opt2Param {
+ char opt;
+ bool HasArg;
+ bool IsFound;
+ bool IsNumeric;
+ bool IsRequired;
+ bool MultipleUse;
const char* DefValue;
TString DefValueStr;
TString HelpUsage;
@@ -45,10 +45,10 @@ struct Opt2Param {
, LongOptName(nullptr)
{
}
-};
-
-struct IntRange {
- int Left, Right;
+};
+
+struct IntRange {
+ int Left, Right;
IntRange() = delete;
IntRange(int both)
: Left(both)
@@ -61,77 +61,77 @@ struct IntRange {
, Right(right)
{
}
-};
-
-class Opt2 {
-public:
+};
+
+class Opt2 {
+public:
Opt2() = default;
Opt2(int argc, char* const* argv, const char* optspec, IntRange free_args_num = -1, const char* long_alias = nullptr) {
- Init(argc, argv, optspec, free_args_num, long_alias);
- }
-
- // Init throws exception only in case of incorrect optspec.
- // In other cases, consult HasErrors or call AutoUsage()
+ Init(argc, argv, optspec, free_args_num, long_alias);
+ }
+
+ // Init throws exception only in case of incorrect optspec.
+ // In other cases, consult HasErrors or call AutoUsage()
void Init(int argc, char* const* argv, const char* optspec, IntRange free_args_num = -1, const char* long_alias = nullptr);
-
- // In case of incorrect options, constructs and prints Usage text,
- // usually to stderr (however, to stdout if '-?' switch was used), and returns 1.
+
+ // In case of incorrect options, constructs and prints Usage text,
+ // usually to stderr (however, to stdout if '-?' switch was used), and returns 1.
int AutoUsage(const char* free_arg_names = "");
-
- // same as AutoUsage but calls exit(1) instead of error code
+
+ // same as AutoUsage but calls exit(1) instead of error code
void AutoUsageErr(const char* free_arg_names = "");
-
- // For options with parameters
+
+ // For options with parameters
const char* Arg(char opt, const char* helpUsage, const char* defValue, bool required = false);
const char* Arg(char opt, const char* helpUsage) {
return Arg(opt, helpUsage, nullptr, true);
- }
+ }
const char* Arg(char opt, const char* helpUsage, TString defValue, bool required = false);
-
- // Options with parameters that can be specified several times
+
+ // Options with parameters that can be specified several times
const TVector<const char*>& MArg(char opt, const char* helpUsage);
-
- // Get() + strtol, may set up HasErrors
+
+ // Get() + strtol, may set up HasErrors
long Int(char opt, const char* helpUsage, long defValue, bool required = false);
long Int(char opt, const char* helpUsage) {
- return Int(opt, helpUsage, 0, true);
- }
-
+ return Int(opt, helpUsage, 0, true);
+ }
+
// Get() + strtoul, may set up HasErrors
unsigned long UInt(char opt, const char* helpUsage, unsigned long defValue, bool required = false);
unsigned long UInt(char opt, const char* helpUsage) {
return UInt(opt, helpUsage, 0, true);
}
- // For options w/o parameters
+ // For options w/o parameters
bool Has(char opt, const char* helpUsage);
-
+
// Add user defined error message and set error flag
void AddError(const char* message = nullptr);
-public:
+public:
// non-option args
TVector<char*> Pos;
- bool HasErrors;
+ bool HasErrors;
private:
- bool BadPosCount;
- char UnknownOption;
+ bool BadPosCount;
+ char UnknownOption;
char* UnknownLongOption;
- char OptionMissingArg;
- char OptionWrongArg;
- char RequiredOptionMissing;
+ char OptionMissingArg;
+ char OptionWrongArg;
+ char RequiredOptionMissing;
TVector<TString> UserErrorMessages;
-
-protected:
- int Argc;
- char* const* Argv;
- int MinArgs, MaxArgs;
- ui8 SpecsMap[256];
+
+protected:
+ int Argc;
+ char* const* Argv;
+ int MinArgs, MaxArgs;
+ ui8 SpecsMap[256];
TVector<Opt2Param> Specs;
TString alias_copy;
void EatArgv(const char* optspec, const char* long_alias);
- void Clear();
+ void Clear();
Opt2Param& GetInternal(char opt, const char* defValue, const char* helpUsage, bool required);
-};
+};
diff --git a/library/cpp/getopt/ut/opt2_ut.cpp b/library/cpp/getopt/ut/opt2_ut.cpp
index 0e7464747c..01ec1c8173 100644
--- a/library/cpp/getopt/ut/opt2_ut.cpp
+++ b/library/cpp/getopt/ut/opt2_ut.cpp
@@ -2,11 +2,11 @@
#include <library/cpp/testing/unittest/registar.h>
-//using namespace NLastGetopt;
+//using namespace NLastGetopt;
Y_UNIT_TEST_SUITE(Opt2Test) {
Y_UNIT_TEST(TestSimple) {
- int argc = 8;
+ int argc = 8;
char* argv[] = {
(char*)"cmd",
(char*)"--aaaa=aaaa",
@@ -18,7 +18,7 @@ Y_UNIT_TEST_SUITE(Opt2Test) {
(char*)"ww",
};
- Opt2 opt(argc, argv, "A:b:cd:e:x:", 2, "aaaa=A");
+ Opt2 opt(argc, argv, "A:b:cd:e:x:", 2, "aaaa=A");
const char* edef = "edef";
const char* a = opt.Arg('A', "<var_name> - usage of -A");
@@ -33,31 +33,31 @@ Y_UNIT_TEST_SUITE(Opt2Test) {
UNIT_ASSERT_VALUES_EQUAL(2, b);
UNIT_ASSERT(c);
UNIT_ASSERT_VALUES_EQUAL(8, d);
- UNIT_ASSERT_VALUES_EQUAL((void*)edef, e);
+ UNIT_ASSERT_VALUES_EQUAL((void*)edef, e);
UNIT_ASSERT_VALUES_EQUAL(2u, opt.Pos.size());
UNIT_ASSERT_STRINGS_EQUAL("zz", opt.Pos.at(0));
- UNIT_ASSERT_VALUES_EQUAL((void*)argv[2], opt.Pos.at(0));
+ UNIT_ASSERT_VALUES_EQUAL((void*)argv[2], opt.Pos.at(0));
UNIT_ASSERT_STRINGS_EQUAL("ww", opt.Pos.at(1));
- UNIT_ASSERT_STRINGS_EQUAL("1", x.at(0));
- UNIT_ASSERT_STRINGS_EQUAL("2", x.at(1));
+ UNIT_ASSERT_STRINGS_EQUAL("1", x.at(0));
+ UNIT_ASSERT_STRINGS_EQUAL("2", x.at(1));
}
-
+
Y_UNIT_TEST(TestErrors1) {
- int argc = 4;
- char* argv[] = {
+ int argc = 4;
+ char* argv[] = {
(char*)"cmd",
(char*)"zz",
(char*)"-c",
(char*)"-e",
- };
-
- Opt2 opt(argc, argv, "ce:", 2);
-
+ };
+
+ Opt2 opt(argc, argv, "ce:", 2);
+
const char* edef = "edef";
bool c = opt.Has('c', "usage of -c");
const char* e = opt.Arg('e', "<unused> - only default is really used", edef);
- UNIT_ASSERT(c);
- UNIT_ASSERT_VALUES_EQUAL((void*)edef, e);
- }
+ UNIT_ASSERT(c);
+ UNIT_ASSERT_VALUES_EQUAL((void*)edef, e);
+ }
}
diff --git a/library/cpp/packedtypes/packedfloat.cpp b/library/cpp/packedtypes/packedfloat.cpp
index 6039d78969..d965d5a290 100644
--- a/library/cpp/packedtypes/packedfloat.cpp
+++ b/library/cpp/packedtypes/packedfloat.cpp
@@ -1,18 +1,18 @@
-#include "packedfloat.h"
-
-#include <util/stream/output.h>
-
+#include "packedfloat.h"
+
+#include <util/stream/output.h>
+
#define OUT_IMPL(T) \
template <> \
void Out<T>(IOutputStream & os, TTypeTraits<T>::TFuncParam val) { \
os << (float)val; \
- }
-
-OUT_IMPL(f16)
-OUT_IMPL(uf16)
-OUT_IMPL(f8)
-OUT_IMPL(uf8)
-OUT_IMPL(f8d)
-OUT_IMPL(uf8d)
+ }
+
+OUT_IMPL(f16)
+OUT_IMPL(uf16)
+OUT_IMPL(f8)
+OUT_IMPL(uf8)
+OUT_IMPL(f8d)
+OUT_IMPL(uf8d)
#undef OUT_IMPL
diff --git a/library/cpp/string_utils/base64/base64.cpp b/library/cpp/string_utils/base64/base64.cpp
index 05c201f0de..73ff81904a 100644
--- a/library/cpp/string_utils/base64/base64.cpp
+++ b/library/cpp/string_utils/base64/base64.cpp
@@ -150,11 +150,11 @@ char* Base64EncodeUrl(char* outstr, const unsigned char* instr, size_t len) {
}
inline void uudecode_1(char* dst, unsigned char* src) {
- dst[0] = char((base64_bkw[src[0]] << 2) | (base64_bkw[src[1]] >> 4));
- dst[1] = char((base64_bkw[src[1]] << 4) | (base64_bkw[src[2]] >> 2));
- dst[2] = char((base64_bkw[src[2]] << 6) | base64_bkw[src[3]]);
-}
-
+ dst[0] = char((base64_bkw[src[0]] << 2) | (base64_bkw[src[1]] >> 4));
+ dst[1] = char((base64_bkw[src[1]] << 4) | (base64_bkw[src[2]] >> 2));
+ dst[2] = char((base64_bkw[src[2]] << 6) | base64_bkw[src[3]]);
+}
+
static size_t Base64DecodePlain(void* dst, const char* b, const char* e) {
size_t n = 0;
while (b < e) {
@@ -174,8 +174,8 @@ static size_t Base64DecodePlain(void* dst, const char* b, const char* e) {
}
}
- return n;
-}
+ return n;
+}
// Table for Base64StrictDecode
static const char base64_bkw_strict[] =
diff --git a/library/cpp/string_utils/url/url.cpp b/library/cpp/string_utils/url/url.cpp
index 85f4ac5d69..a7f42f0360 100644
--- a/library/cpp/string_utils/url/url.cpp
+++ b/library/cpp/string_utils/url/url.cpp
@@ -16,37 +16,37 @@
#include <cstdlib>
namespace {
- struct TUncheckedSize {
+ struct TUncheckedSize {
static bool Has(size_t) {
- return true;
- }
- };
-
- struct TKnownSize {
- size_t MySize;
+ return true;
+ }
+ };
+
+ struct TKnownSize {
+ size_t MySize;
explicit TKnownSize(size_t sz)
- : MySize(sz)
+ : MySize(sz)
{
}
- bool Has(size_t sz) const {
- return sz <= MySize;
- }
- };
-
- template <typename TChar1, typename TChar2>
- int Compare1Case2(const TChar1* s1, const TChar2* s2, size_t n) {
- for (size_t i = 0; i < n; ++i) {
+ bool Has(size_t sz) const {
+ return sz <= MySize;
+ }
+ };
+
+ template <typename TChar1, typename TChar2>
+ int Compare1Case2(const TChar1* s1, const TChar2* s2, size_t n) {
+ for (size_t i = 0; i < n; ++i) {
if ((TChar1)ToLower(s1[i]) != s2[i])
return (TChar1)ToLower(s1[i]) < s2[i] ? -1 : 1;
- }
- return 0;
- }
-
+ }
+ return 0;
+ }
+
template <typename TChar, typename TBounds>
inline size_t GetHttpPrefixSizeImpl(const TChar* url, const TBounds& urlSize, bool ignorehttps) {
const TChar httpPrefix[] = {'h', 't', 't', 'p', ':', '/', '/', 0};
const TChar httpsPrefix[] = {'h', 't', 't', 'p', 's', ':', '/', '/', 0};
- if (urlSize.Has(7) && Compare1Case2(url, httpPrefix, 7) == 0)
+ if (urlSize.Has(7) && Compare1Case2(url, httpPrefix, 7) == 0)
return 7;
if (!ignorehttps && urlSize.Has(8) && Compare1Case2(url, httpsPrefix, 8) == 0)
return 8;
@@ -113,8 +113,8 @@ size_t GetSchemePrefixSize(const TStringBuf url) noexcept {
}
return n + 3 - url.begin();
-}
-
+}
+
TStringBuf GetSchemePrefix(const TStringBuf url) noexcept {
return url.Head(GetSchemePrefixSize(url));
}
@@ -236,7 +236,7 @@ void GetSchemeHostAndPort(const TStringBuf url, TStringBuf& scheme, TStringBuf&
}
TStringBuf GetOnlyHost(const TStringBuf url) noexcept {
- return GetHost(CutSchemePrefix(url));
+ return GetHost(CutSchemePrefix(url));
}
TStringBuf GetPathAndQuery(const TStringBuf url, bool trimFragment) noexcept {
@@ -248,19 +248,19 @@ TStringBuf GetPathAndQuery(const TStringBuf url, bool trimFragment) noexcept {
return trimFragment ? path.Before('#') : path;
}
-// this strange creature returns 2nd level domain, possibly with port
+// this strange creature returns 2nd level domain, possibly with port
TStringBuf GetDomain(const TStringBuf host) noexcept {
const char* c = !host ? host.data() : host.end() - 1;
for (bool wasPoint = false; c != host.data(); --c) {
- if (*c == '.') {
- if (wasPoint) {
+ if (*c == '.') {
+ if (wasPoint) {
++c;
break;
- }
+ }
wasPoint = true;
}
}
- return TStringBuf(c, host.end());
+ return TStringBuf(c, host.end());
}
TStringBuf GetParentDomain(const TStringBuf host, size_t level) noexcept {
diff --git a/library/cpp/string_utils/url/url.h b/library/cpp/string_utils/url/url.h
index 84137ccc57..47b9f6465b 100644
--- a/library/cpp/string_utils/url/url.h
+++ b/library/cpp/string_utils/url/url.h
@@ -35,10 +35,10 @@ Y_PURE_FUNCTION
size_t GetHttpPrefixSize(const TWtringBuf url, bool ignorehttps = false) noexcept;
/** BEWARE of TStringBuf! You can not use operator ~ or c_str() like in TString
- !!!!!!!!!!!! */
+ !!!!!!!!!!!! */
Y_PURE_FUNCTION
size_t GetSchemePrefixSize(const TStringBuf url) noexcept;
-
+
Y_PURE_FUNCTION
TStringBuf GetSchemePrefix(const TStringBuf url) noexcept;
diff --git a/library/cpp/string_utils/url/url_ut.cpp b/library/cpp/string_utils/url/url_ut.cpp
index 1588013893..66c76a63ff 100644
--- a/library/cpp/string_utils/url/url_ut.cpp
+++ b/library/cpp/string_utils/url/url_ut.cpp
@@ -45,7 +45,7 @@ Y_UNIT_TEST_SUITE(TUtilUrlTest) {
UNIT_ASSERT_VALUES_EQUAL("ya.ru", GetDomain("a.b.ya.ru"));
UNIT_ASSERT_VALUES_EQUAL("ya.ru", GetDomain("ya.ru"));
UNIT_ASSERT_VALUES_EQUAL("ya", GetDomain("ya"));
- UNIT_ASSERT_VALUES_EQUAL("", GetDomain(""));
+ UNIT_ASSERT_VALUES_EQUAL("", GetDomain(""));
}
Y_UNIT_TEST(TestGetParentDomain) {
@@ -88,27 +88,27 @@ Y_UNIT_TEST_SUITE(TUtilUrlTest) {
}
Y_UNIT_TEST(TestSchemeCut) {
- UNIT_ASSERT_VALUES_EQUAL("ya.ru/bebe", CutSchemePrefix("http://ya.ru/bebe"));
- UNIT_ASSERT_VALUES_EQUAL("yaru", CutSchemePrefix("yaru"));
- UNIT_ASSERT_VALUES_EQUAL("ya.ru://zzz", CutSchemePrefix("yaru://ya.ru://zzz"));
- UNIT_ASSERT_VALUES_EQUAL("ya.ru://zzz", CutSchemePrefix("ya.ru://zzz"));
- UNIT_ASSERT_VALUES_EQUAL("ya.ru://zzz", CutSchemePrefix("ftp://ya.ru://zzz"));
- UNIT_ASSERT_VALUES_EQUAL("", CutSchemePrefix("https://")); // is that right?
-
- UNIT_ASSERT_VALUES_EQUAL("ftp://ya.ru", CutHttpPrefix("ftp://ya.ru"));
- UNIT_ASSERT_VALUES_EQUAL("ya.ru/zzz", CutHttpPrefix("http://ya.ru/zzz"));
+ UNIT_ASSERT_VALUES_EQUAL("ya.ru/bebe", CutSchemePrefix("http://ya.ru/bebe"));
+ UNIT_ASSERT_VALUES_EQUAL("yaru", CutSchemePrefix("yaru"));
+ UNIT_ASSERT_VALUES_EQUAL("ya.ru://zzz", CutSchemePrefix("yaru://ya.ru://zzz"));
+ UNIT_ASSERT_VALUES_EQUAL("ya.ru://zzz", CutSchemePrefix("ya.ru://zzz"));
+ UNIT_ASSERT_VALUES_EQUAL("ya.ru://zzz", CutSchemePrefix("ftp://ya.ru://zzz"));
+ UNIT_ASSERT_VALUES_EQUAL("", CutSchemePrefix("https://")); // is that right?
+
+ UNIT_ASSERT_VALUES_EQUAL("ftp://ya.ru", CutHttpPrefix("ftp://ya.ru"));
+ UNIT_ASSERT_VALUES_EQUAL("ya.ru/zzz", CutHttpPrefix("http://ya.ru/zzz"));
UNIT_ASSERT_VALUES_EQUAL("ya.ru/zzz", CutHttpPrefix("http://ya.ru/zzz", true));
- UNIT_ASSERT_VALUES_EQUAL("ya.ru/zzz", CutHttpPrefix("https://ya.ru/zzz"));
+ UNIT_ASSERT_VALUES_EQUAL("ya.ru/zzz", CutHttpPrefix("https://ya.ru/zzz"));
UNIT_ASSERT_VALUES_EQUAL("https://ya.ru/zzz", CutHttpPrefix("https://ya.ru/zzz", true));
UNIT_ASSERT_VALUES_EQUAL("", CutHttpPrefix("https://")); // is that right?
UNIT_ASSERT_VALUES_EQUAL("https://", CutHttpPrefix("https://", true)); // is that right?
- }
-
+ }
+
Y_UNIT_TEST(TestMisc) {
- UNIT_ASSERT_VALUES_EQUAL("", CutWWWPrefix("www."));
- UNIT_ASSERT_VALUES_EQUAL("", CutWWWPrefix("WwW."));
- UNIT_ASSERT_VALUES_EQUAL("www", CutWWWPrefix("www"));
- UNIT_ASSERT_VALUES_EQUAL("ya.ru", CutWWWPrefix("www.ya.ru"));
+ UNIT_ASSERT_VALUES_EQUAL("", CutWWWPrefix("www."));
+ UNIT_ASSERT_VALUES_EQUAL("", CutWWWPrefix("WwW."));
+ UNIT_ASSERT_VALUES_EQUAL("www", CutWWWPrefix("www"));
+ UNIT_ASSERT_VALUES_EQUAL("ya.ru", CutWWWPrefix("www.ya.ru"));
UNIT_ASSERT_VALUES_EQUAL("", CutWWWNumberedPrefix("www."));
UNIT_ASSERT_VALUES_EQUAL("www", CutWWWNumberedPrefix("www"));
@@ -125,7 +125,7 @@ Y_UNIT_TEST_SUITE(TUtilUrlTest) {
UNIT_ASSERT_VALUES_EQUAL("", CutMPrefix("M."));
UNIT_ASSERT_VALUES_EQUAL("m", CutMPrefix("m"));
UNIT_ASSERT_VALUES_EQUAL("ya.ru", CutMPrefix("m.ya.ru"));
- }
+ }
Y_UNIT_TEST(TestSplitUrlToHostAndPath) {
TStringBuf host, path;
diff --git a/library/cpp/testing/unittest/utmain.cpp b/library/cpp/testing/unittest/utmain.cpp
index 305bc6b40f..a29773e5a0 100644
--- a/library/cpp/testing/unittest/utmain.cpp
+++ b/library/cpp/testing/unittest/utmain.cpp
@@ -577,13 +577,13 @@ public:
SetConsoleOutputCP(CP_UTF8);
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
-
- if (!IsDebuggerPresent()) {
- _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
- _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
- _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
- _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
- }
+
+ if (!IsDebuggerPresent()) {
+ _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
+ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
+ _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
+ _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
+ }
}
~TWinEnvironment() {
if (!IsDebuggerPresent()) {
diff --git a/library/cpp/yson/node/node.h b/library/cpp/yson/node/node.h
index 5f90f95df0..63229b5934 100644
--- a/library/cpp/yson/node/node.h
+++ b/library/cpp/yson/node/node.h
@@ -131,9 +131,9 @@ public:
template<typename T>
bool IsOfType() const noexcept;
- // Int64, Uint64, Double, or Bool
- bool IsArithmetic() const;
-
+ // Int64, Uint64, Double, or Bool
+ bool IsArithmetic() const;
+
bool Empty() const;
size_t Size() const;
@@ -290,10 +290,10 @@ bool operator!=(const TNode& lhs, const TNode& rhs);
bool GetBool(const TNode& node);
-inline bool TNode::IsArithmetic() const {
- return IsInt64() || IsUint64() || IsDouble() || IsBool();
-}
-
+inline bool TNode::IsArithmetic() const {
+ return IsInt64() || IsUint64() || IsDouble() || IsBool();
+}
+
template<typename T>
inline T TNode::IntCast() const {
if constexpr (std::is_integral<T>::value) {