about summary refs log tree commit diff
path: root/absl/flags/marshalling.cc
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2019-09-19T16·27-0700
committerShaindel Schwartz <shaindel@google.com>2019-09-19T21·08-0400
commitddf8e52a2918dd0ccec75d3e2426125fa3926724 (patch)
tree3aa7151866a9a76bcad92467bc23cc4f25fec558 /absl/flags/marshalling.cc
parent6ec136281086b71da32b5fb068bd6e46b78a5c79 (diff)
Export of internal Abseil changes
--
cf6037b985b629c253b8a87e4408c88a61baf89a by Abseil Team <absl-team@google.com>:

Adds an example of using ABSL_DEPRECATED on a template.
Without this, it's unclear where to add this annotation (e.g. before template <> or after it).

PiperOrigin-RevId: 270057224

--
c53bc14dd683cc1e41c940a337001b42a0270eaf by Andy Getzendanner <durandal@google.com>:

Parser and unparser for command-line flags of type absl::LogSeverity.

PiperOrigin-RevId: 269939999

--
d91174b02f3b213f0b26701d9d97c79f809e6fea by Abseil Team <absl-team@google.com>:

Fix a typo.

PiperOrigin-RevId: 269738777
GitOrigin-RevId: cf6037b985b629c253b8a87e4408c88a61baf89a
Change-Id: I6cec3101014e4c77f4ff2edb4c91740982dbb459
Diffstat (limited to 'absl/flags/marshalling.cc')
-rw-r--r--absl/flags/marshalling.cc40
1 files changed, 40 insertions, 0 deletions
diff --git a/absl/flags/marshalling.cc b/absl/flags/marshalling.cc
index f025ae7e86c4..f4ebe0e34330 100644
--- a/absl/flags/marshalling.cc
+++ b/absl/flags/marshalling.cc
@@ -16,6 +16,7 @@
 #include "absl/flags/marshalling.h"
 
 #include <limits>
+#include <type_traits>
 
 #include "absl/base/macros.h"
 #include "absl/strings/match.h"
@@ -186,4 +187,43 @@ std::string AbslUnparseFlag(const std::vector<std::string>& v) {
 }
 
 }  // namespace flags_internal
+
+bool AbslParseFlag(absl::string_view text, absl::LogSeverity* dst,
+                   std::string* err) {
+  text = absl::StripAsciiWhitespace(text);
+  if (text.empty()) {
+    *err = "no value provided";
+    return false;
+  }
+  if (text.front() == 'k' || text.front() == 'K') text.remove_prefix(1);
+  if (absl::EqualsIgnoreCase(text, "info")) {
+    *dst = absl::LogSeverity::kInfo;
+    return true;
+  }
+  if (absl::EqualsIgnoreCase(text, "warning")) {
+    *dst = absl::LogSeverity::kWarning;
+    return true;
+  }
+  if (absl::EqualsIgnoreCase(text, "error")) {
+    *dst = absl::LogSeverity::kError;
+    return true;
+  }
+  if (absl::EqualsIgnoreCase(text, "fatal")) {
+    *dst = absl::LogSeverity::kFatal;
+    return true;
+  }
+  std::underlying_type<absl::LogSeverity>::type numeric_value;
+  if (absl::ParseFlag(text, &numeric_value, err)) {
+    *dst = static_cast<absl::LogSeverity>(numeric_value);
+    return true;
+  }
+  *err = "only integers and absl::LogSeverity enumerators are accepted";
+  return false;
+}
+
+std::string AbslUnparseFlag(absl::LogSeverity v) {
+  if (v == absl::NormalizeLogSeverity(v)) return absl::LogSeverityName(v);
+  return absl::UnparseFlag(static_cast<int>(v));
+}
+
 }  // namespace absl