summaryrefslogtreecommitdiff
path: root/absl/log/internal/log_message.cc
diff options
context:
space:
mode:
authorGravatar Andy Getzendanner <durandal@google.com>2022-11-07 14:12:00 -0800
committerGravatar Copybara-Service <copybara-worker@google.com>2022-11-07 14:12:47 -0800
commit615f2147028688b5e36f159ccd2958552488215c (patch)
treebacddcb19743bd9ea8b7986e86ef368fa3605435 /absl/log/internal/log_message.cc
parentd459fe7137411d13852229e5eb269e1190f869f1 (diff)
Factor out the internal helper AppendTruncated, which is used and redefined in a couple places, plus several more that have yet to be released.
PiperOrigin-RevId: 486759835 Change-Id: Ib1b24f287f856ca38b691fbce7e747f0f5a34626
Diffstat (limited to 'absl/log/internal/log_message.cc')
-rw-r--r--absl/log/internal/log_message.cc11
1 files changed, 2 insertions, 9 deletions
diff --git a/absl/log/internal/log_message.cc b/absl/log/internal/log_message.cc
index f32c7e63..98e45f87 100644
--- a/absl/log/internal/log_message.cc
+++ b/absl/log/internal/log_message.cc
@@ -41,6 +41,7 @@
#include "absl/container/inlined_vector.h"
#include "absl/debugging/internal/examine_stack.h"
#include "absl/log/globals.h"
+#include "absl/log/internal/append_truncated.h"
#include "absl/log/internal/config.h"
#include "absl/log/internal/globals.h"
#include "absl/log/internal/log_format.h"
@@ -65,14 +66,6 @@ ABSL_NAMESPACE_BEGIN
namespace log_internal {
namespace {
-// Copies into `dst` as many bytes of `src` as will fit, then truncates the
-// copied bytes from the front of `dst` and returns the number of bytes written.
-size_t AppendTruncated(absl::string_view src, absl::Span<char>* dst) {
- if (src.size() > dst->size()) src = src.substr(0, dst->size());
- memcpy(dst->data(), src.data(), src.size());
- dst->remove_prefix(src.size());
- return src.size();
-}
absl::string_view Basename(absl::string_view filepath) {
#ifdef _WIN32
@@ -163,7 +156,7 @@ class LogEntryStreambuf final : public std::streambuf {
size_t Append(absl::string_view data) {
absl::Span<char> remaining(pptr(), static_cast<size_t>(epptr() - pptr()));
- const size_t written = AppendTruncated(data, &remaining);
+ const size_t written = log_internal::AppendTruncated(data, remaining);
pbump(static_cast<int>(written));
return written;
}