aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/getopt/small/last_getopt_parser.h
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:17 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:17 +0300
commitd3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch)
treedd4bd3ca0f36b817e96812825ffaf10d645803f2 /library/cpp/getopt/small/last_getopt_parser.h
parent72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff)
downloadydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/getopt/small/last_getopt_parser.h')
-rw-r--r--library/cpp/getopt/small/last_getopt_parser.h198
1 files changed, 99 insertions, 99 deletions
diff --git a/library/cpp/getopt/small/last_getopt_parser.h b/library/cpp/getopt/small/last_getopt_parser.h
index 6b5c8cbb97..2cf8a6c308 100644
--- a/library/cpp/getopt/small/last_getopt_parser.h
+++ b/library/cpp/getopt/small/last_getopt_parser.h
@@ -8,85 +8,85 @@
#include <util/generic/list.h>
namespace NLastGetopt {
- /**
+ /**
* NLastGetopt::TOptsParser is an implementation of parsing
* argv/argv into TOptsParseResult by rules of TOpts.
*
* The class allows to make complicated handlers.
* Note, that if PERMUTE mode is on, then data, pointed by argv can be changed.
*/
- class TOptsParser {
- enum EIsOpt {
- EIO_NONE, //is not an option name
- EIO_SDASH, //single-dashed ('-c') option name
- EIO_DDASH, //double-dashed ("--opt") option name
- EIO_PLUS, //plus prefix ("+opt") option name
- };
+ class TOptsParser {
+ enum EIsOpt {
+ EIO_NONE, //is not an option name
+ EIO_SDASH, //single-dashed ('-c') option name
+ EIO_DDASH, //double-dashed ("--opt") option name
+ EIO_PLUS, //plus prefix ("+opt") option name
+ };
- public: // TODO: make private
- const TOpts* Opts_; //rules of parsing
+ public: // TODO: make private
+ const TOpts* Opts_; //rules of parsing
- // argc/argv pair
- size_t Argc_;
- const char** Argv_;
+ // argc/argv pair
+ size_t Argc_;
+ const char** Argv_;
- private:
- //the storage of last unkown options. TODO: can be moved to local-method scope
- TCopyPtr<TOpt> TempCurrentOpt_;
+ private:
+ //the storage of last unkown options. TODO: can be moved to local-method scope
+ TCopyPtr<TOpt> TempCurrentOpt_;
- public:
- //storage of argv[0]
- TString ProgramName_;
+ public:
+ //storage of argv[0]
+ TString ProgramName_;
- //state of parsing:
+ //state of parsing:
- size_t Pos_; // current element withing argv
- size_t Sop_; // current char within arg
- bool Stopped_;
- bool GotMinusMinus_; //true if "--" have been seen in argv
+ size_t Pos_; // current element withing argv
+ size_t Sop_; // current char within arg
+ bool Stopped_;
+ bool GotMinusMinus_; //true if "--" have been seen in argv
- protected:
- const TOpt* CurrentOpt_; // ptr on the last meeted option
- TStringBuf CurrentValue_; // the value of the last met argument (corresponding to CurrentOpt_)
+ protected:
+ const TOpt* CurrentOpt_; // ptr on the last meeted option
+ TStringBuf CurrentValue_; // the value of the last met argument (corresponding to CurrentOpt_)
- private:
- typedef THashSet<const TOpt*> TdOptSet;
- TdOptSet OptsSeen_; //the set of options that have been met during parsing
+ private:
+ typedef THashSet<const TOpt*> TdOptSet;
+ TdOptSet OptsSeen_; //the set of options that have been met during parsing
- TList<const TOpt*> OptsDefault_;
+ TList<const TOpt*> OptsDefault_;
- private:
- void Init(const TOpts* options, int argc, const char* argv[]);
- void Init(const TOpts* options, int argc, char* argv[]);
+ private:
+ void Init(const TOpts* options, int argc, const char* argv[]);
+ void Init(const TOpts* options, int argc, char* argv[]);
- bool CommitEndOfOptions(size_t pos);
- bool Commit(const TOpt* currentOption, const TStringBuf& currentValue, size_t pos, size_t sop);
+ bool CommitEndOfOptions(size_t pos);
+ bool Commit(const TOpt* currentOption, const TStringBuf& currentValue, size_t pos, size_t sop);
- bool ParseShortOptArg(size_t pos);
- bool ParseOptArg(size_t pos);
- bool ParseOptParam(const TOpt* opt, size_t pos);
- bool ParseUnknownShortOptWithinArg(size_t pos, size_t sop);
- bool ParseShortOptWithinArg(size_t pos, size_t sop);
- bool ParseWithPermutation();
+ bool ParseShortOptArg(size_t pos);
+ bool ParseOptArg(size_t pos);
+ bool ParseOptParam(const TOpt* opt, size_t pos);
+ bool ParseUnknownShortOptWithinArg(size_t pos, size_t sop);
+ bool ParseShortOptWithinArg(size_t pos, size_t sop);
+ bool ParseWithPermutation();
- bool DoNext();
- void Finish();
+ bool DoNext();
+ void Finish();
- EIsOpt IsOpt(const TStringBuf& arg) const;
+ EIsOpt IsOpt(const TStringBuf& arg) const;
- void Swap(TOptsParser& that);
+ void Swap(TOptsParser& that);
- public:
- TOptsParser(const TOpts* options, int argc, const char* argv[]) {
- Init(options, argc, argv);
- }
+ public:
+ TOptsParser(const TOpts* options, int argc, const char* argv[]) {
+ Init(options, argc, argv);
+ }
- TOptsParser(const TOpts* options, int argc, char* argv[]) {
- Init(options, argc, argv);
- }
+ TOptsParser(const TOpts* options, int argc, char* argv[]) {
+ Init(options, argc, argv);
+ }
- /// fetch next argument, false if no more arguments left
- bool Next();
+ /// fetch next argument, false if no more arguments left
+ bool Next();
bool Seen(const TOpt* opt) const {
return OptsSeen_.contains(opt);
@@ -108,47 +108,47 @@ namespace NLastGetopt {
}
}
- const TOpt* CurOpt() const {
- return CurrentOpt_;
- }
-
- const char* CurVal() const {
- return CurrentValue_.data();
- }
-
- const TStringBuf& CurValStr() const {
- return CurrentValue_;
- }
-
- TStringBuf CurValOrOpt() const {
- TStringBuf val(CurValStr());
- if (!val.IsInited() && CurOpt()->HasOptionalValue())
- val = CurOpt()->GetOptionalValue();
- return val;
- }
-
- TStringBuf CurValOrDef(bool useDef = true) const {
- TStringBuf val(CurValOrOpt());
- if (!val.IsInited() && useDef && CurOpt()->HasDefaultValue())
- val = CurOpt()->GetDefaultValue();
- return val;
- }
-
- // true if this option was actually specified by the user
- bool IsExplicit() const {
- return nullptr == CurrentOpt_ || !OptsSeen_.empty();
- }
-
- bool CurrentIs(const TString& name) const {
- return CurOpt()->NameIs(name);
- }
-
- const TString& ProgramName() const {
- return ProgramName_;
- }
-
- void PrintUsage(IOutputStream& os = Cout) const;
-
- void PrintUsage(IOutputStream& os, const NColorizer::TColors& colors) const;
- };
-} //namespace NLastGetopt
+ const TOpt* CurOpt() const {
+ return CurrentOpt_;
+ }
+
+ const char* CurVal() const {
+ return CurrentValue_.data();
+ }
+
+ const TStringBuf& CurValStr() const {
+ return CurrentValue_;
+ }
+
+ TStringBuf CurValOrOpt() const {
+ TStringBuf val(CurValStr());
+ if (!val.IsInited() && CurOpt()->HasOptionalValue())
+ val = CurOpt()->GetOptionalValue();
+ return val;
+ }
+
+ TStringBuf CurValOrDef(bool useDef = true) const {
+ TStringBuf val(CurValOrOpt());
+ if (!val.IsInited() && useDef && CurOpt()->HasDefaultValue())
+ val = CurOpt()->GetDefaultValue();
+ return val;
+ }
+
+ // true if this option was actually specified by the user
+ bool IsExplicit() const {
+ return nullptr == CurrentOpt_ || !OptsSeen_.empty();
+ }
+
+ bool CurrentIs(const TString& name) const {
+ return CurOpt()->NameIs(name);
+ }
+
+ const TString& ProgramName() const {
+ return ProgramName_;
+ }
+
+ void PrintUsage(IOutputStream& os = Cout) const;
+
+ void PrintUsage(IOutputStream& os, const NColorizer::TColors& colors) const;
+ };
+} //namespace NLastGetopt