File tree 1 file changed +20
-29
lines changed
1 file changed +20
-29
lines changed Original file line number Diff line number Diff line change 11
11
12
12
#include " c_misc.h"
13
13
14
- #include < cstdio >
14
+ #include < sstream >
15
15
16
- #ifdef _WIN32
17
- #ifndef __MINGW32__
18
- #define snprintf sprintf_s
19
- #endif
20
- #endif
21
-
22
- static void MetaChar (std::string &out, char c, bool inString)
16
+ static void MetaChar (std::ostringstream &out, char c, bool inString)
23
17
{
24
18
switch (c)
25
19
{
26
20
case ' \' ' :
27
21
if (inString)
28
- out+= " '" ;
22
+ out << " '" ;
29
23
else
30
- out+= " \\ '" ;
24
+ out << " \\ '" ;
31
25
break ;
32
26
33
27
case ' "' :
34
28
if (inString)
35
- out+= " \\\" " ;
29
+ out << " \\\" " ;
36
30
else
37
- out+= " \" " ;
31
+ out << " \" " ;
38
32
break ;
39
33
40
34
case ' \0 ' :
41
- out+= " \\ 0" ;
35
+ out << " \\ 0" ;
42
36
break ;
43
37
44
38
case ' \\ ' :
45
- out+= " \\\\ " ;
39
+ out << " \\\\ " ;
46
40
break ;
47
41
48
42
case ' \n ' :
49
- out+= " \\ n" ;
43
+ out << " \\ n" ;
50
44
break ;
51
45
52
46
case ' \t ' :
53
- out+= " \\ t" ;
47
+ out << " \\ t" ;
54
48
break ;
55
49
56
50
case ' \r ' :
57
- out+= " \\ r" ;
51
+ out << " \\ r" ;
58
52
break ;
59
53
60
54
case ' \f ' :
61
- out+= " \\ f" ;
55
+ out << " \\ f" ;
62
56
break ;
63
57
64
58
case ' \b ' :
65
- out+= " \\ b" ;
59
+ out << " \\ b" ;
66
60
break ;
67
61
68
62
case ' \v ' :
69
- out+= " \\ v" ;
63
+ out << " \\ v" ;
70
64
break ;
71
65
72
66
case ' \a ' :
73
- out+= " \\ a" ;
67
+ out << " \\ a" ;
74
68
break ;
75
69
76
70
default :
77
71
// Show low and certain high ascii as octal
78
- if ((( unsigned char )c < ' ' ) || (c == 127 ))
72
+ if ((static_cast < unsigned char >(c)< ' ' ) || (c== 127 ))
79
73
{
80
- char octbuf[8 ];
81
- snprintf (octbuf, sizeof (octbuf), " %03o" , (unsigned char ) c);
82
- out+=" \\ " ;
83
- out+=octbuf;
74
+ out << " \\ " << std::oct << static_cast <unsigned char >(c);
84
75
}
85
76
else
86
77
{
87
78
// leave everything else to permit UTF-8 and 8-bit codepages
88
- out+= c;
79
+ out << c;
89
80
}
90
81
91
82
break ;
@@ -103,10 +94,10 @@ static std::string MetaChar(char c)
103
94
104
95
std::string MetaString (const std::string &in)
105
96
{
106
- std::string result;
97
+ std::ostringstream result;
107
98
108
99
for (const auto &ch : in)
109
100
MetaChar (result, ch, true );
110
101
111
- return result;
102
+ return result. str () ;
112
103
}
You can’t perform that action at this time.
0 commit comments