Coverage Report

Created: 2026-09-14 06:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/abseil-cpp/absl/strings/internal/stringify_sink.h
Line
Count
Source
1
// Copyright 2022 The Abseil Authors
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     https://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#ifndef ABSL_STRINGS_INTERNAL_STRINGIFY_SINK_H_
16
#define ABSL_STRINGS_INTERNAL_STRINGIFY_SINK_H_
17
18
#include <array>
19
#include <cstddef>
20
#include <string>
21
#include <type_traits>
22
#include <utility>
23
24
#include "absl/base/config.h"
25
#include "absl/strings/numbers.h"
26
#include "absl/strings/string_view.h"
27
#include "absl/types/source_location.h"
28
29
namespace absl {
30
ABSL_NAMESPACE_BEGIN
31
32
namespace strings_internal {
33
class StringifySink {
34
 public:
35
  void Append(size_t count, char ch);
36
37
  void Append(string_view v);
38
39
  // Support `absl::Format(&sink, format, args...)`.
40
0
  friend void AbslFormatFlush(StringifySink* sink, absl::string_view v) {
41
0
    sink->Append(v);
42
0
  }
43
44
 private:
45
  template <typename T>
46
  friend string_view ExtractStringification(StringifySink& sink, const T& v);
47
48
  std::string buffer_;
49
};
50
51
template <typename T>
52
string_view ExtractStringification(StringifySink& sink, const T& v) {
53
  AbslStringify(sink, v);
54
  return sink.buffer_;
55
}
56
57
}  // namespace strings_internal
58
59
template <typename Sink>
60
void AbslStringify(Sink& sink, SourceLocation l) {
61
  sink.Append(l.file_name());
62
  sink.Append(":");
63
  std::array<char, numbers_internal::kFastToBufferSize> buffer;
64
  numbers_internal::FastIntToBuffer(l.line(), buffer.data());
65
  sink.Append(buffer.data());
66
}
67
68
ABSL_NAMESPACE_END
69
}  // namespace absl
70
71
#endif  // ABSL_STRINGS_INTERNAL_STRINGIFY_SINK_H_