Main Page   Reference Manual   Namespace List   Compound List   Namespace Members   Compound Members   File Members  

char2str.h
Go to the documentation of this file.
1 // $Header$
2 //
3 // Copyright (C) 2000 - 2004, by
4 //
5 // Carlo Wood, Run on IRC <carlo@alinoe.com>
6 // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt
7 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61
8 //
9 // This file may be distributed under the terms of the Q Public License
10 // version 1.0 as appearing in the file LICENSE.QPL included in the
11 // packaging of this file.
12 //
13 
22 #ifndef LIBCWD_CHAR2STR_H
23 #define LIBCWD_CHAR2STR_H
24 
25 #ifndef LIBCW_IOSFWD
26 #define LIBCW_IOSFWD
27 #include <iosfwd>
28 #endif
29 
30 namespace libcwd {
31 
53 class char2str {
54 private:
55  char c;
56 
57 private:
58  void print_char_to(std::ostream&) const;
59  void print_escaped_char_to(std::ostream&) const;
60 
61 public:
63  char2str(char ci) : c(ci) { }
64 
69  friend inline std::ostream& operator<<(std::ostream& os, char2str const c2s)
70  {
71  if ((c2s.c > 31 && c2s.c != 92 && c2s.c != 127) || (unsigned char)c2s.c > 159)
72  c2s.print_char_to(os);
73  else
74  c2s.print_escaped_char_to(os);
75  return os;
76  }
77 };
78 
79 } // namespace libcwd
80 
81 #endif // LIBCWD_CHAR2STR_H
namespace for libcwd.
Definition: debug.cc:87
char2str(char ci)
Construct a char2str object with attribute ci.
Definition: char2str.h:63
Print a char to a debug ostream, escaping non-printable characters as needed.
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:69
Copyright © 2001 - 2004 Carlo Wood.  All rights reserved.