diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /library/cpp/getopt/small/last_getopt_opt.cpp | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/getopt/small/last_getopt_opt.cpp')
-rw-r--r-- | library/cpp/getopt/small/last_getopt_opt.cpp | 156 |
1 files changed, 78 insertions, 78 deletions
diff --git a/library/cpp/getopt/small/last_getopt_opt.cpp b/library/cpp/getopt/small/last_getopt_opt.cpp index 9a99437f4b..576b8f03d5 100644 --- a/library/cpp/getopt/small/last_getopt_opt.cpp +++ b/library/cpp/getopt/small/last_getopt_opt.cpp @@ -11,95 +11,95 @@ namespace NLastGetopt { static const TStringBuf ExcludedShortNameChars = "= -\t\n"; static const TStringBuf ExcludedLongNameChars = "= \t\n"; - bool TOpt::NameIs(const TString& name) const { - for (const auto& next : LongNames_) { - if (next == name) - return true; - } - return false; - } - - bool TOpt::CharIs(char c) const { - for (auto next : Chars_) { - if (next == c) - return true; - } - return false; - } - - char TOpt::GetChar() const { - ; - if (Chars_.empty()) - ythrow TConfException() << "no char for option " << this->ToShortString(); - return Chars_.at(0); + bool TOpt::NameIs(const TString& name) const { + for (const auto& next : LongNames_) { + if (next == name) + return true; + } + return false; + } + + bool TOpt::CharIs(char c) const { + for (auto next : Chars_) { + if (next == c) + return true; + } + return false; + } + + char TOpt::GetChar() const { + ; + if (Chars_.empty()) + ythrow TConfException() << "no char for option " << this->ToShortString(); + return Chars_.at(0); } - char TOpt::GetCharOr0() const { - if (Chars_.empty()) - return 0; - return GetChar(); + char TOpt::GetCharOr0() const { + if (Chars_.empty()) + return 0; + return GetChar(); } - TString TOpt::GetName() const { - ; - if (LongNames_.empty()) - ythrow TConfException() << "no name for option " << this->ToShortString(); - return LongNames_.at(0); - } + TString TOpt::GetName() const { + ; + if (LongNames_.empty()) + ythrow TConfException() << "no name for option " << this->ToShortString(); + return LongNames_.at(0); + } - bool TOpt::IsAllowedShortName(unsigned char c) { - return isprint(c) && TStringBuf::npos == ExcludedShortNameChars.find(c); - } + bool TOpt::IsAllowedShortName(unsigned char c) { + return isprint(c) && TStringBuf::npos == ExcludedShortNameChars.find(c); + } - TOpt& TOpt::AddShortName(unsigned char c) { - ; - if (!IsAllowedShortName(c)) + TOpt& TOpt::AddShortName(unsigned char c) { + ; + if (!IsAllowedShortName(c)) throw TUsageException() << "option char '" << c << "' is not allowed"; - Chars_.push_back(c); - return *this; - } - - bool TOpt::IsAllowedLongName(const TString& name, unsigned char* out) { - for (size_t i = 0; i != name.size(); ++i) { - const unsigned char c = name[i]; - if (!isprint(c) || TStringBuf::npos != ExcludedLongNameChars.find(c)) { - if (nullptr != out) - *out = c; - return false; - } + Chars_.push_back(c); + return *this; + } + + bool TOpt::IsAllowedLongName(const TString& name, unsigned char* out) { + for (size_t i = 0; i != name.size(); ++i) { + const unsigned char c = name[i]; + if (!isprint(c) || TStringBuf::npos != ExcludedLongNameChars.find(c)) { + if (nullptr != out) + *out = c; + return false; + } } - return true; + return true; } - TOpt& TOpt::AddLongName(const TString& name) { - ; - unsigned char c = 0; - if (!IsAllowedLongName(name, &c)) + TOpt& TOpt::AddLongName(const TString& name) { + ; + unsigned char c = 0; + if (!IsAllowedLongName(name, &c)) throw TUsageException() << "option char '" << c - << "' in long '" << name << "' is not allowed"; - LongNames_.push_back(name); - return *this; - } - - namespace NPrivate { - TString OptToString(char c); - - TString OptToString(const TString& longOption); - } - - TString TOpt::ToShortString() const { - ; - if (!LongNames_.empty()) - return NPrivate::OptToString(LongNames_.front()); - if (!Chars_.empty()) - return NPrivate::OptToString(Chars_.front()); - return "?"; - } - - void TOpt::FireHandlers(const TOptsParser* parser) const { - for (const auto& handler : Handlers_) { - handler->HandleOpt(parser); - } + << "' in long '" << name << "' is not allowed"; + LongNames_.push_back(name); + return *this; + } + + namespace NPrivate { + TString OptToString(char c); + + TString OptToString(const TString& longOption); + } + + TString TOpt::ToShortString() const { + ; + if (!LongNames_.empty()) + return NPrivate::OptToString(LongNames_.front()); + if (!Chars_.empty()) + return NPrivate::OptToString(Chars_.front()); + return "?"; + } + + void TOpt::FireHandlers(const TOptsParser* parser) const { + for (const auto& handler : Handlers_) { + handler->HandleOpt(parser); + } } TOpt& TOpt::IfPresentDisableCompletionFor(const TOpt& opt) { |