diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-18 17:02:53 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-18 17:02:53 -0300 |
| commit | 959575a5ca598bf5f37fb5cebe7ed1d80d3d71f7 (patch) | |
| tree | acc8d60aedb12b70048e676e8a7349deb0010db8 /src/mongo/base/string_data.h | |
| parent | 76588293975fc059cf076779e4283e6ffaf8afff (diff) | |
New upstream version 6.0.20upstream
Diffstat (limited to 'src/mongo/base/string_data.h')
| -rw-r--r-- | src/mongo/base/string_data.h | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/mongo/base/string_data.h b/src/mongo/base/string_data.h index ad26243afc0..be2c6592ea9 100644 --- a/src/mongo/base/string_data.h +++ b/src/mongo/base/string_data.h @@ -128,7 +128,7 @@ public: */ bool equalCaseInsensitive(StringData other) const; - void copyTo(char* dest, bool includeEndingNull) const; + size_t copy(char* dest, size_t count, size_t pos = 0) const; constexpr StringData substr(size_t pos, size_t n = std::numeric_limits<size_t>::max()) const; @@ -237,11 +237,13 @@ inline bool StringData::equalCaseInsensitive(StringData other) const { }); } -inline void StringData::copyTo(char* dest, bool includeEndingNull) const { - if (_data) - memcpy(dest, _data, size()); - if (includeEndingNull) - dest[size()] = 0; +inline size_t StringData::copy(char* dest, size_t count, size_t pos) const { + if (MONGO_unlikely(pos > size())) + throw std::out_of_range("pos > size()"); + + const auto rcount = std::min(count, size() - pos); + std::char_traits<char>::copy(dest, rawData() + pos, rcount); + return rcount; } inline size_t StringData::find(char c, size_t fromPos) const { |
