MCPcopy Create free account
hub / github.com/OpenPTrack/open_ptrack_v2 / ParseFlagValue

Function ParseFlagValue

rtpose_wrapper/src/gtest/gtest-all.cpp:5863–5889  ·  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

5861//
5862// Returns the value of the flag, or NULL if the parsing failed.
5863const char* ParseFlagValue(const char* str,
5864 const char* flag,
5865 bool def_optional) {
5866 // str and flag must not be NULL.
5867 if (str == NULL || flag == NULL) return NULL;
5868
5869 // The flag must start with "--" followed by GTEST_FLAG_PREFIX_.
5870 const String flag_str = String::Format("--%s%s", GTEST_FLAG_PREFIX_, flag);
5871 const size_t flag_len = flag_str.length();
5872 if (strncmp(str, flag_str.c_str(), flag_len) != 0) return NULL;
5873
5874 // Skips the flag name.
5875 const char* flag_end = str + flag_len;
5876
5877 // When def_optional is true, it's OK to not have a "=value" part.
5878 if (def_optional && (flag_end[0] == '\0')) {
5879 return flag_end;
5880 }
5881
5882 // If def_optional is true and there are more characters after the
5883 // flag name, or if def_optional is false, there must be a '=' after
5884 // the flag name.
5885 if (flag_end[0] != '=') return NULL;
5886
5887 // Returns the string after "=".
5888 return flag_end + 1;
5889}
5890
5891// Parses a string for a bool flag, in the form of either
5892// "--flag=value" or "--flag".

Callers 3

ParseBoolFlagFunction · 0.85
ParseInt32FlagFunction · 0.85
ParseStringFlagFunction · 0.85

Calls 1

FormatClass · 0.85

Tested by

no test coverage detected