cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
file_converter.h
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: Convert file contents to C strings
4
5
Author: Daniel Kroening, kroening@kroening.com
6
7
\*******************************************************************/
8
11
12
#ifndef CPROVER_ANSI_C_FILE_CONVERTER_H
13
#define CPROVER_ANSI_C_FILE_CONVERTER_H
14
15
#include <istream>
16
#include <string>
17
23
inline
void
file_converter_emit_bytes
(std::ostream &out,
const
std::string &s)
24
{
25
for
(
const
char
c : s)
26
{
27
const
unsigned
char
ch =
static_cast<
unsigned
char
>
(c);
28
if
(ch >= 0x80)
29
out <<
"(char)"
<< unsigned(ch) <<
','
;
30
else
31
out << unsigned(ch) <<
','
;
32
}
33
}
34
43
inline
void
file_converter_append
(
44
std::istream &in,
45
std::ostream &out,
46
bool
line_marker,
47
const
std::string &file_name)
48
{
49
if
(line_marker)
50
{
51
file_converter_emit_bytes
(out,
"#line 1 \""
+ file_name +
"\"\n"
);
52
out <<
'\n'
;
53
}
54
55
std::string line;
56
while
(std::getline(in, line))
57
{
58
if
(!line.empty() && line.back() ==
'\r'
)
59
line.pop_back();
60
file_converter_emit_bytes
(out, line);
61
out <<
"'\\n',\n"
;
62
}
63
}
64
65
#endif
// CPROVER_ANSI_C_FILE_CONVERTER_H
file_converter_append
void file_converter_append(std::istream &in, std::ostream &out, bool line_marker, const std::string &file_name)
Append the contents of in to out as the body of a C character-array initialiser; the enclosing braces...
Definition
file_converter.h:43
file_converter_emit_bytes
void file_converter_emit_bytes(std::ostream &out, const std::string &s)
Emit the bytes of s to out as comma-separated decimal byte values (not character literals).
Definition
file_converter.h:23
ansi-c
file_converter.h
Generated by
1.17.0