libcwdversion 2.0.0
The C++ Debugging Support Library
Loading...
Searching...
No Matches
char2str.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2000-2004, 2007, 2018, 2020, 2026 Carlo Wood
2// SPDX-License-Identifier: MIT
3
4#pragma once
5
13
14#ifndef LIBCWD_CHAR2STR_H
15#define LIBCWD_CHAR2STR_H
16
17#include <iosfwd>
18
19namespace libcwd {
20
41
43{
44 private:
45 char c;
46
47 private:
48 void print_char_to(std::ostream&) const;
49 void print_escaped_char_to(std::ostream&) const;
50
51 public:
53 char2str(char ci) : c(ci) { }
54
59 friend inline std::ostream& operator<<(std::ostream& os, char2str const c2s)
60 {
61 if ((c2s.c > 31 && c2s.c != 92 && c2s.c != 127) /* || (unsigned char)c2s.c > 159 */)
62 c2s.print_char_to(os);
63 else
64 c2s.print_escaped_char_to(os);
65 return os;
66 }
67};
68
69} // namespace libcwd
70
71#endif // LIBCWD_CHAR2STR_H
char2str(char ci)
Construct a char2str object with attribute ci.
Definition char2str.h:53
friend std::ostream & operator<<(std::ostream &os, char2str const c2s)
Write the character represented by c2s to the ostream os, escaping it when it is a non-printable char...
Definition char2str.h:59
namespace for libcwd.