Update to have two distinct methods

pull/10385/head
Deanna Garcia 2 years ago committed by mheyndrickx
parent 71af7209d9
commit 8fee1dea9d
  1. 20
      src/google/protobuf/stubs/common.cc
  2. 4
      src/google/protobuf/stubs/common.h

@ -92,7 +92,7 @@ void VerifyVersion(int headerVersion,
} }
} }
std::string VersionString(int version, bool cppMajor) { std::string VersionString(int version) {
int major = version / 1000000; int major = version / 1000000;
int minor = (version / 1000) % 1000; int minor = (version / 1000) % 1000;
int micro = version % 1000; int micro = version % 1000;
@ -100,11 +100,7 @@ std::string VersionString(int version, bool cppMajor) {
// 128 bytes should always be enough, but we use snprintf() anyway to be // 128 bytes should always be enough, but we use snprintf() anyway to be
// safe. // safe.
char buffer[128]; char buffer[128];
if (cppMajor) {
snprintf(buffer, sizeof(buffer), "%d.%d.%d", major, minor, micro); snprintf(buffer, sizeof(buffer), "%d.%d.%d", major, minor, micro);
} else {
snprintf(buffer, sizeof(buffer), "%d.%d", minor, micro);
}
// Guard against broken MSVC snprintf(). // Guard against broken MSVC snprintf().
buffer[sizeof(buffer)-1] = '\0'; buffer[sizeof(buffer)-1] = '\0';
@ -113,7 +109,19 @@ std::string VersionString(int version, bool cppMajor) {
} }
std::string ProtocVersionString(int version) { std::string ProtocVersionString(int version) {
return VersionString(version, false); int minor = (version / 1000) % 1000;
int micro = version % 1000;
// 128 bytes should always be enough, but we use snprintf() anyway to be
// safe.
char buffer[128];
snprintf(buffer, sizeof(buffer), "%d.%d", minor, micro);
// Guard against broken MSVC snprintf().
buffer[sizeof(buffer)-1] = '\0';
return buffer;
} }
} // namespace internal } // namespace internal

@ -106,9 +106,7 @@ void PROTOBUF_EXPORT VerifyVersion(int headerVersion, int minLibraryVersion,
const char* filename); const char* filename);
// Converts a numeric version number to a string. // Converts a numeric version number to a string.
// If cppMajor is true the string will have the C++ major version, otherwise std::string PROTOBUF_EXPORT VersionString(int version);
// the string will be the protoc version.
std::string PROTOBUF_EXPORT VersionString(int version, bool cppMajor = true);
// Prints the protoc compiler version (no major version) // Prints the protoc compiler version (no major version)
std::string PROTOBUF_EXPORT ProtocVersionString(int version); std::string PROTOBUF_EXPORT ProtocVersionString(int version);

Loading…
Cancel
Save