@@ -15,51 +15,57 @@ bool has_prefix(const std::string &s, const std::string &prefix)
15
15
return std::string (s, 0 , prefix.size ())==prefix;
16
16
}
17
17
18
- int main ( )
18
+ static void convert_line ( const std::string &line, bool first )
19
19
{
20
- std::string line;
21
- bool first=true ;
20
+ if (has_prefix (line, " /* FUNCTION: " ))
21
+ {
22
+ if (!first)
23
+ std::cout << " },\n " ;
22
24
23
- std::cout << " {\n " ;
25
+ std::string function = std::string (line, 13 , std::string::npos);
26
+ std::size_t pos = function.find (' ' );
27
+ if (pos != std::string::npos)
28
+ function = std::string (function, 0 , pos);
24
29
25
- while (getline (std::cin, line))
30
+ std::cout << " { \" " << function << " \" ,\n " ;
31
+ std::cout << " \" #line 1 \\\" <builtin-library-" << function
32
+ << " >\\\"\\ n\"\n " ;
33
+ }
34
+ else if (!first)
26
35
{
27
- if (has_prefix (line, " /* FUNCTION: " ))
36
+ std::cout << " \" " ;
37
+
38
+ for (unsigned i = 0 ; i < line.size (); i++)
28
39
{
29
- if (first)
30
- first=false ;
40
+ const char ch = line[i];
41
+ if (ch == ' \\ ' )
42
+ std::cout << " \\\\ " ;
43
+ else if (ch == ' "' )
44
+ std::cout << " \\\" " ;
45
+ else if (ch == ' \r ' || ch == ' \n ' )
46
+ {
47
+ }
31
48
else
32
- std::cout << " },\n " ;
49
+ std::cout << ch;
50
+ }
33
51
34
- std::string function=std::string (line, 13 , std::string::npos);
35
- std::size_t pos=function.find (' ' );
36
- if (pos!=std::string::npos)
37
- function=std::string (function, 0 , pos);
52
+ std::cout << " \\ n\"\n " ;
53
+ }
54
+ }
38
55
39
- std::cout << " { \" " << function << " \" ,\n " ;
40
- std::cout << " \" #line 1 \\\" <builtin-library-"
41
- << function << " >\\\"\\ n\"\n " ;
42
- }
43
- else if (!first)
44
- {
45
- std::cout << " \" " ;
56
+ int main ()
57
+ {
58
+ std::string line;
59
+ bool first = true ;
46
60
47
- for (unsigned i=0 ; i<line.size (); i++)
48
- {
49
- const char ch=line[i];
50
- if (ch==' \\ ' )
51
- std::cout << " \\\\ " ;
52
- else if (ch==' "' )
53
- std::cout << " \\\" " ;
54
- else if (ch==' \r ' || ch==' \n ' )
55
- {
56
- }
57
- else
58
- std::cout << ch;
59
- }
61
+ std::cout << " {\n " ;
60
62
61
- std::cout << " \\ n\"\n " ;
62
- }
63
+ if (getline (std::cin, line))
64
+ {
65
+ convert_line (line, true );
66
+ first = false ;
67
+ while (getline (std::cin, line))
68
+ convert_line (line, false );
63
69
}
64
70
65
71
if (!first)
0 commit comments