diff options
author | Billy Donahue <billy.donahue@mongodb.com> | 2019-04-01 13:07:09 -0400 |
---|---|---|
committer | Billy Donahue <billy.donahue@mongodb.com> | 2019-04-08 10:22:17 -0400 |
commit | 2def9c02b31425551cf904d4b6e9920b64dd1c06 (patch) | |
tree | e1ad4ee413fe37e73e95375602f82c98cea9f8ce /src/mongo/base | |
parent | c8a133c3714d80d02cb8524d5278e6c1321e26f1 (diff) | |
download | mongo-2def9c02b31425551cf904d4b6e9920b64dd1c06.tar.gz |
SERVER-40389 small tweaks to third_party/fmt & related.
Add an option to scons: --use-system-fmt
import.sh: use the upstream libfmt github repo.
StringData fmt interop
noexcept for to_string_view(StringData) hook
noexcept for StringData's rawData() and size()
add fmt to THIRD-PARTY-NOTICES + markdown tweaks
import the fmt LICENSE.rst
update fmt lib revision
Diffstat (limited to 'src/mongo/base')
-rw-r--r-- | src/mongo/base/string_data.h | 10 | ||||
-rw-r--r-- | src/mongo/base/string_data_test.cpp | 6 |
2 files changed, 14 insertions, 2 deletions
diff --git a/src/mongo/base/string_data.h b/src/mongo/base/string_data.h index ffb7941e7ac..4192ccd60f6 100644 --- a/src/mongo/base/string_data.h +++ b/src/mongo/base/string_data.h @@ -36,6 +36,8 @@ #include <stdexcept> #include <string> +#include <fmt/format.h> + #include "mongo/stdx/type_traits.h" #define MONGO_INCLUDE_INVARIANT_H_WHITELISTED #include "mongo/util/invariant.h" @@ -166,11 +168,11 @@ public: * null-terminated, so if using this without checking size(), you are likely doing * something wrong. */ - constexpr const char* rawData() const { + constexpr const char* rawData() const noexcept { return _data; } - constexpr size_t size() const { + constexpr size_t size() const noexcept { return _size; } constexpr bool empty() const { @@ -352,4 +354,8 @@ inline std::string operator+(StringData lhs, std::string rhs) { return rhs; } +constexpr fmt::string_view to_string_view(StringData s) noexcept { + return fmt::string_view(s.rawData(), s.size()); +} + } // namespace mongo diff --git a/src/mongo/base/string_data_test.cpp b/src/mongo/base/string_data_test.cpp index 3e19a557d8e..a1d9d7d7773 100644 --- a/src/mongo/base/string_data_test.cpp +++ b/src/mongo/base/string_data_test.cpp @@ -319,4 +319,10 @@ TEST(ConstIterator, StdReplaceCopy) { } } +TEST(StringDataFmt, Fmt) { + using namespace fmt::literals; + ASSERT_EQUALS(fmt::format("-{}-", "abc"_sd), "-abc-"); + ASSERT_EQUALS("-{}-"_format("abc"_sd), "-abc-"); +} + } // namespace mongo |