MCPcopy Create free account
hub / github.com/EmbeddedRPC/erpc / ParseFlagValue

Function ParseFlagValue

test/common/gtest/gtest.cpp:6593–6619  ·  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

6591//
6592// Returns the value of the flag, or NULL if the parsing failed.
6593const char* ParseFlagValue(const char* str,
6594 const char* flag,
6595 bool def_optional) {
6596 // str and flag must not be NULL.
6597 if (str == NULL || flag == NULL) return NULL;
6598
6599 // The flag must start with "--" followed by GTEST_FLAG_PREFIX_.
6600 const std::string flag_str = std::string("--") + GTEST_FLAG_PREFIX_ + flag;
6601 const size_t flag_len = flag_str.length();
6602 if (strncmp(str, flag_str.c_str(), flag_len) != 0) return NULL;
6603
6604 // Skips the flag name.
6605 const char* flag_end = str + flag_len;
6606
6607 // When def_optional is true, it's OK to not have a "=value" part.
6608 if (def_optional && (flag_end[0] == '\0')) {
6609 return flag_end;
6610 }
6611
6612 // If def_optional is true and there are more characters after the
6613 // flag name, or if def_optional is false, there must be a '=' after
6614 // the flag name.
6615 if (flag_end[0] != '=') return NULL;
6616
6617 // Returns the string after "=".
6618 return flag_end + 1;
6619}
6620
6621// Parses a string for a bool flag, in the form of either
6622// "--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