File tree Expand file tree Collapse file tree 3 files changed +10
-0
lines changed
Expand file tree Collapse file tree 3 files changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,10 @@ static_assert(
4747 "absl::Status assumes it can use the bottom 2 bits of a StatusRep*.");
4848
4949std::string StatusCodeToString (StatusCode code) {
50+ return std::string (absl::StatusCodeToStringView (code));
51+ }
52+
53+ absl::string_view StatusCodeToStringView (StatusCode code) {
5054 switch (code) {
5155 case StatusCode::kOk :
5256 return " OK" ;
Original file line number Diff line number Diff line change @@ -284,6 +284,11 @@ enum class StatusCode : int {
284284// Returns the name for the status code, or "" if it is an unknown value.
285285std::string StatusCodeToString (StatusCode code);
286286
287+ // StatusCodeToStringView()
288+ //
289+ // Same as StatusCodeToString(), but returns a string_view.
290+ absl::string_view StatusCodeToStringView (StatusCode code);
291+
287292// operator<<
288293//
289294// Streams StatusCodeToString(code) to `os`.
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ TEST(StatusCode, InsertionOperator) {
3939 std::ostringstream oss;
4040 oss << code;
4141 EXPECT_EQ (oss.str (), absl::StatusCodeToString (code));
42+ EXPECT_EQ (oss.str (), absl::StatusCodeToStringView (code));
4243}
4344
4445// This structure holds the details for testing a single error code,
You can’t perform that action at this time.
0 commit comments