MCPcopy Create free account
hub / github.com/awslabs/aws-lambda-cpp / ParseFlagValue

Function ParseFlagValue

tests/gtest/gtest-all.cc:7162–7187  ·  view source on GitHub ↗

Parses a string as a command line flag. The string should have the format "--flag=value". When def_optional is true, the "=value" part can be omitted. Returns the value of the flag, or NULL if the parsing failed.

Source from the content-addressed store, hash-verified

7160//
7161// Returns the value of the flag, or NULL if the parsing failed.
7162static const char* ParseFlagValue(const char* str, const char* flag,
7163 bool def_optional) {
7164 // str and flag must not be NULL.
7165 if (str == nullptr || flag == nullptr) return nullptr;
7166
7167 // The flag must start with "--" followed by GTEST_FLAG_PREFIX_.
7168 const std::string flag_str = std::string("--") + GTEST_FLAG_PREFIX_ + flag;
7169 const size_t flag_len = flag_str.length();
7170 if (strncmp(str, flag_str.c_str(), flag_len) != 0) return nullptr;
7171
7172 // Skips the flag name.
7173 const char* flag_end = str + flag_len;
7174
7175 // When def_optional is true, it's OK to not have a "=value" part.
7176 if (def_optional && (flag_end[0] == '\0')) {
7177 return flag_end;
7178 }
7179
7180 // If def_optional is true and there are more characters after the
7181 // flag name, or if def_optional is false, there must be a '=' after
7182 // the flag name.
7183 if (flag_end[0] != '=') return nullptr;
7184
7185 // Returns the string after "=".
7186 return flag_end + 1;
7187}
7188
7189// Parses a string for a bool flag, in the form of either
7190// "--flag=value" or "--flag".

Callers 3

ParseBoolFlagFunction · 0.85
ParseInt32FlagFunction · 0.85
ParseStringFlagFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected