From d439bbccd4b90583a89d209d2cc81308aabca8ac Mon Sep 17 00:00:00 2001 From: Gil Date: Tue, 22 May 2018 13:21:08 -0700 Subject: Add a HARD_ASSERT C++ assertion macro (#1304) * Add HARD_ASSERT * Use HARD_ASSERT * Remove FIREBASE_ASSERT * Remove StringPrintf --- .../src/firebase/firestore/model/field_path.cc | 27 ++++++++-------------- 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'Firestore/core/src/firebase/firestore/model/field_path.cc') diff --git a/Firestore/core/src/firebase/firestore/model/field_path.cc b/Firestore/core/src/firebase/firestore/model/field_path.cc index bc0e97c..5636b53 100644 --- a/Firestore/core/src/firebase/firestore/model/field_path.cc +++ b/Firestore/core/src/firebase/firestore/model/field_path.cc @@ -19,7 +19,7 @@ #include #include -#include "Firestore/core/src/firebase/firestore/util/firebase_assert.h" +#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" #include "absl/strings/str_join.h" #include "absl/strings/str_replace.h" #include "absl/strings/str_split.h" @@ -71,18 +71,11 @@ FieldPath FieldPath::FromServerFormat(const absl::string_view path) { std::string segment; segment.reserve(path.size()); - // string_view doesn't have a c_str() method, because it might not be - // null-terminated. Assertions expect C strings, so construct std::string on - // the fly, so that c_str() might be called on it. - const auto to_string = [](const absl::string_view view) { - return std::string{view.data(), view.data() + view.size()}; - }; - const auto finish_segment = [&segments, &segment, &path, &to_string] { - FIREBASE_ASSERT_MESSAGE( - !segment.empty(), - "Invalid field path (%s). Paths must not be empty, begin with " - "'.', end with '.', or contain '..'", - to_string(path).c_str()); + const auto finish_segment = [&segments, &segment, &path] { + HARD_ASSERT(!segment.empty(), + "Invalid field path (%s). Paths must not be empty, begin with " + "'.', end with '.', or contain '..'", + path); // Move operation will clear segment, but capacity will remain the same // (not, strictly speaking, required by the standard, but true in practice). segments.push_back(std::move(segment)); @@ -116,9 +109,8 @@ FieldPath FieldPath::FromServerFormat(const absl::string_view path) { case '\\': // TODO(b/37244157): Make this a user-facing exception once we // finalize field escaping. - FIREBASE_ASSERT_MESSAGE(i + 1 != path.size(), - "Trailing escape characters not allowed in %s", - to_string(path).c_str()); + HARD_ASSERT(i + 1 != path.size(), + "Trailing escape characters not allowed in %s", path); ++i; segment += path[i]; break; @@ -131,8 +123,7 @@ FieldPath FieldPath::FromServerFormat(const absl::string_view path) { } finish_segment(); - FIREBASE_ASSERT_MESSAGE(!inside_backticks, "Unterminated ` in path %s", - to_string(path).c_str()); + HARD_ASSERT(!inside_backticks, "Unterminated ` in path %s", path); return FieldPath{std::move(segments)}; } -- cgit v1.2.3