libcwdversion 2.0.0
The C++ Debugging Support Library
Loading...
Searching...
No Matches
buf2str.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2000-2004, 2007, 2018, 2020, 2025-2026 Carlo Wood
2// SPDX-License-Identifier: MIT
3
4#pragma once
5
13
14#ifndef LIBCWD_BUF2STR_H
15#define LIBCWD_BUF2STR_H
16
17#include "char2str.h"
18
19#include <cstddef> // Needed for size_t
20#include <iosfwd>
21#if __cpp_concepts >= 201907L
22#include <concepts>
23#endif
24
25namespace libcwd {
26
49
51{
52 private:
53 char const* buf_;
54 size_t size_;
55
56 public:
58 buf2str(char const* buf, size_t size) : buf_(buf), size_(size) { }
59
60#if __cpp_concepts >= 201907L
62 template<typename T>
63 requires requires(T const& t) {
64 { t.data() } -> std::convertible_to<char const*>;
65 { t.size() } -> std::convertible_to<size_t>;
66 }
67 buf2str(T const& view) : buf_(view.data()), size_(view.size())
68 {
69 }
70#endif
71
76 friend inline std::ostream& operator<<(std::ostream& os, buf2str const& __buf2str)
77 {
78 size_t size = __buf2str.size_;
79 for (char const* p1 = __buf2str.buf_; size > 0; --size, ++p1)
80 os << char2str(*p1);
81 return os;
82 }
83};
84
85} // namespace libcwd
86
87#endif // LIBCWD_BUF2STR_H
Definition of utility class char2str.
friend std::ostream & operator<<(std::ostream &os, buf2str const &__buf2str)
Write the contents of the buffer represented by __buf2str to the ostream os, escaping non-printable c...
Definition buf2str.h:76
buf2str(char const *buf, size_t size)
Construct buf2str object with attributes buf and size.
Definition buf2str.h:58
Print a char to a debug ostream, escaping non-printable characters as needed.
Definition char2str.h:43
namespace for libcwd.