diff --git a/include/flatbuffers/base.h b/include/flatbuffers/base.h index 038b5ab0e..ad474bb70 100644 --- a/include/flatbuffers/base.h +++ b/include/flatbuffers/base.h @@ -235,11 +235,11 @@ template FLATBUFFERS_CONSTEXPR inline bool IsConstTrue(T t) { return !!t; } -// Enable of std:c++17 or higher. +// Enable C++ attribute [[]] if std:c++17 or higher. #if (defined(__cplusplus) && (__cplusplus >= 201703L)) || \ (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)) // All attributes unknown to an implementation are ignored without causing an error. - #define FLATBUFFERS_ATTRIBUTE(attr) // [[attr]] - will be enabled in a future release + #define FLATBUFFERS_ATTRIBUTE(attr) [[attr]] #else #define FLATBUFFERS_ATTRIBUTE(attr) #endif diff --git a/include/flatbuffers/flatbuffers.h b/include/flatbuffers/flatbuffers.h index 4a292f1dc..062c7f5b9 100644 --- a/include/flatbuffers/flatbuffers.h +++ b/include/flatbuffers/flatbuffers.h @@ -390,7 +390,7 @@ const Vector> *VectorCast(const Vector> *ptr) { // Convenient helper function to get the length of any vector, regardless // of whether it is null or not (the field is not set). template static inline size_t VectorLength(const Vector *v) { - return v ? v->Length() : 0; + return v ? v->size() : 0; } // Lexicographically compare two strings (possibly containing nulls), and @@ -403,12 +403,12 @@ static inline bool StringLessThan(const char *a_data, uoffset_t a_size, struct String : public Vector { const char *c_str() const { return reinterpret_cast(Data()); } - std::string str() const { return std::string(c_str(), Length()); } + std::string str() const { return std::string(c_str(), size()); } // clang-format off #ifdef FLATBUFFERS_HAS_STRING_VIEW flatbuffers::string_view string_view() const { - return flatbuffers::string_view(c_str(), Length()); + return flatbuffers::string_view(c_str(), size()); } #endif // FLATBUFFERS_HAS_STRING_VIEW // clang-format on @@ -1340,7 +1340,7 @@ class FlatBufferBuilder { /// @param[in] str A const pointer to a `String` struct to add to the buffer. /// @return Returns the offset in the buffer where the string starts Offset CreateString(const String *str) { - return str ? CreateString(str->c_str(), str->Length()) : 0; + return str ? CreateString(str->c_str(), str->size()) : 0; } /// @brief Store a string in the buffer, which can contain any binary data. @@ -1400,7 +1400,7 @@ class FlatBufferBuilder { /// @param[in] str A const pointer to a `String` struct to add to the buffer. /// @return Returns the offset in the buffer where the string starts Offset CreateSharedString(const String *str) { - return CreateSharedString(str->c_str(), str->Length()); + return CreateSharedString(str->c_str(), str->size()); } /// @cond FLATBUFFERS_INTERNAL diff --git a/src/idl_gen_text.cpp b/src/idl_gen_text.cpp index c12948865..fb75a7955 100644 --- a/src/idl_gen_text.cpp +++ b/src/idl_gen_text.cpp @@ -119,7 +119,7 @@ bool Print(const void *val, Type type, int indent, break; case BASE_TYPE_STRING: { auto s = reinterpret_cast(val); - if (!EscapeString(s->c_str(), s->Length(), _text, opts.allow_non_utf8, + if (!EscapeString(s->c_str(), s->size(), _text, opts.allow_non_utf8, opts.natural_utf8)) { return false; } diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index 698c9ab08..cda786513 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -94,7 +94,7 @@ std::string MakeCamel(const std::string &in, bool first) { void DeserializeDoc( std::vector &doc, const Vector> *documentation) { if (documentation == nullptr) return; - for (uoffset_t index = 0; index < documentation->Length(); index++) + for (uoffset_t index = 0; index < documentation->size(); index++) doc.push_back(documentation->Get(index)->str()); } @@ -2755,8 +2755,8 @@ bool StructDef::Deserialize(Parser &parser, const reflection::Object *object) { predecl = false; sortbysize = attributes.Lookup("original_order") == nullptr && !fixed; std::vector indexes = - std::vector(object->fields()->Length()); - for (uoffset_t i = 0; i < object->fields()->Length(); i++) + std::vector(object->fields()->size()); + for (uoffset_t i = 0; i < object->fields()->size(); i++) indexes[object->fields()->Get(i)->id()] = i; for (size_t i = 0; i < indexes.size(); i++) { auto field = object->fields()->Get(indexes[i]); diff --git a/src/reflection.cpp b/src/reflection.cpp index 61c1ba732..1058f9d51 100644 --- a/src/reflection.cpp +++ b/src/reflection.cpp @@ -299,13 +299,13 @@ class ResizeContext { void SetString(const reflection::Schema &schema, const std::string &val, const String *str, std::vector *flatbuf, const reflection::Object *root_table) { - auto delta = static_cast(val.size()) - static_cast(str->Length()); + auto delta = static_cast(val.size()) - static_cast(str->size()); auto str_start = static_cast( reinterpret_cast(str) - vector_data(*flatbuf)); auto start = str_start + static_cast(sizeof(uoffset_t)); if (delta) { // Clear the old string, since we don't want parts of it remaining. - memset(vector_data(*flatbuf) + start, 0, str->Length()); + memset(vector_data(*flatbuf) + start, 0, str->size()); // Different size, we must expand (or contract). ResizeContext(schema, start, delta, flatbuf, root_table); // Set the new length. diff --git a/tests/test.cpp b/tests/test.cpp index 829ccc2c2..509db6c7b 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -283,7 +283,7 @@ void AccessFlatBufferTest(const uint8_t *flatbuf, size_t length, // Example of accessing a vector of strings: auto vecofstrings = monster->testarrayofstring(); - TEST_EQ(vecofstrings->Length(), 4U); + TEST_EQ(vecofstrings->size(), 4U); TEST_EQ_STR(vecofstrings->Get(0)->c_str(), "bob"); TEST_EQ_STR(vecofstrings->Get(1)->c_str(), "fred"); if (pooled) { @@ -294,14 +294,14 @@ void AccessFlatBufferTest(const uint8_t *flatbuf, size_t length, auto vecofstrings2 = monster->testarrayofstring2(); if (vecofstrings2) { - TEST_EQ(vecofstrings2->Length(), 2U); + TEST_EQ(vecofstrings2->size(), 2U); TEST_EQ_STR(vecofstrings2->Get(0)->c_str(), "jane"); TEST_EQ_STR(vecofstrings2->Get(1)->c_str(), "mary"); } // Example of accessing a vector of tables: auto vecoftables = monster->testarrayoftables(); - TEST_EQ(vecoftables->Length(), 3U); + TEST_EQ(vecoftables->size(), 3U); for (auto it = vecoftables->begin(); it != vecoftables->end(); ++it) TEST_EQ(strlen(it->name()->c_str()) >= 4, true); TEST_EQ_STR(vecoftables->Get(0)->name()->c_str(), "Barney");