aboutsummaryrefslogtreecommitdiff
path: root/CPP/Common/StdOutStream.cpp
diff options
context:
space:
mode:
authorIgor Pavlov <87184205+ip7z@users.noreply.github.com>2024-05-14 00:00:00 +0000
committerIgor Pavlov <87184205+ip7z@users.noreply.github.com>2024-05-15 23:55:04 +0500
commitfc662341e6f85da78ada0e443f6116b978f79f22 (patch)
tree1be1cc402a7a9cbc18d4eeea6b141354c2d559e3 /CPP/Common/StdOutStream.cpp
parent5b39dc76f1bc82f941d5c800ab9f34407a06b53a (diff)
download7zip-24.05.tar.gz
7zip-24.05.tar.bz2
7zip-24.05.zip
24.0524.05
Diffstat (limited to 'CPP/Common/StdOutStream.cpp')
-rw-r--r--CPP/Common/StdOutStream.cpp120
1 files changed, 104 insertions, 16 deletions
diff --git a/CPP/Common/StdOutStream.cpp b/CPP/Common/StdOutStream.cpp
index cfa5fde..ba179d9 100644
--- a/CPP/Common/StdOutStream.cpp
+++ b/CPP/Common/StdOutStream.cpp
@@ -66,70 +66,158 @@ void CStdOutStream::Convert_UString_to_AString(const UString &src, AString &dest
66 int codePage = CodePage; 66 int codePage = CodePage;
67 if (codePage == -1) 67 if (codePage == -1)
68 codePage = CP_OEMCP; 68 codePage = CP_OEMCP;
69 if (codePage == CP_UTF8) 69 if ((unsigned)codePage == CP_UTF8)
70 ConvertUnicodeToUTF8(src, dest); 70 ConvertUnicodeToUTF8(src, dest);
71 else 71 else
72 UnicodeStringToMultiByte2(dest, src, (UINT)codePage); 72 UnicodeStringToMultiByte2(dest, src, (UINT)(unsigned)codePage);
73} 73}
74 74
75 75
76static const wchar_t kReplaceChar = '_'; 76static const wchar_t kReplaceChar = '_';
77 77
78/*
78void CStdOutStream::Normalize_UString_LF_Allowed(UString &s) 79void CStdOutStream::Normalize_UString_LF_Allowed(UString &s)
79{ 80{
80 unsigned len = s.Len(); 81 if (!IsTerminalMode)
82 return;
83
84 const unsigned len = s.Len();
81 wchar_t *d = s.GetBuf(); 85 wchar_t *d = s.GetBuf();
82 86
83 if (IsTerminalMode)
84 for (unsigned i = 0; i < len; i++) 87 for (unsigned i = 0; i < len; i++)
85 { 88 {
86 wchar_t c = d[i]; 89 const wchar_t c = d[i];
87 if (c <= 13 && c >= 7 && c != '\n') 90 if (c == 0x1b || (c <= 13 && c >= 7 && c != '\n'))
88 d[i] = kReplaceChar; 91 d[i] = kReplaceChar;
89 } 92 }
90} 93}
94*/
91 95
92void CStdOutStream::Normalize_UString(UString &s) 96void CStdOutStream::Normalize_UString(UString &s)
93{ 97{
94 unsigned len = s.Len(); 98 const unsigned len = s.Len();
95 wchar_t *d = s.GetBuf(); 99 wchar_t *d = s.GetBuf();
96 100
97 if (IsTerminalMode) 101 if (IsTerminalMode)
98 for (unsigned i = 0; i < len; i++) 102 for (unsigned i = 0; i < len; i++)
99 { 103 {
100 wchar_t c = d[i]; 104 const wchar_t c = d[i];
101 if (c <= 13 && c >= 7) 105 if ((c <= 13 && c >= 7) || c == 0x1b)
102 d[i] = kReplaceChar; 106 d[i] = kReplaceChar;
103 } 107 }
104 else 108 else
105 for (unsigned i = 0; i < len; i++) 109 for (unsigned i = 0; i < len; i++)
106 { 110 {
107 wchar_t c = d[i]; 111 const wchar_t c = d[i];
108 if (c == '\n') 112 if (c == '\n')
109 d[i] = kReplaceChar; 113 d[i] = kReplaceChar;
110 } 114 }
111} 115}
112 116
113void CStdOutStream::NormalizePrint_UString(const UString &s, UString &tempU, AString &tempA) 117void CStdOutStream::Normalize_UString_Path(UString &s)
118{
119 if (ListPathSeparatorSlash.Def)
120 {
121#ifdef _WIN32
122 if (ListPathSeparatorSlash.Val)
123 s.Replace(L'\\', L'/');
124#else
125 if (!ListPathSeparatorSlash.Val)
126 s.Replace(L'/', L'\\');
127#endif
128 }
129 Normalize_UString(s);
130}
131
132
133/*
134void CStdOutStream::Normalize_UString(UString &src)
135{
136 const wchar_t *s = src.Ptr();
137 const unsigned len = src.Len();
138 unsigned i;
139 for (i = 0; i < len; i++)
140 {
141 const wchar_t c = s[i];
142#if 0 && !defined(_WIN32)
143 if (c == '\\') // IsTerminalMode &&
144 break;
145#endif
146 if ((unsigned)c < 0x20)
147 break;
148 }
149 if (i == len)
150 return;
151
152 UString temp;
153 for (i = 0; i < len; i++)
154 {
155 wchar_t c = s[i];
156#if 0 && !defined(_WIN32)
157 if (c == '\\')
158 temp += (wchar_t)L'\\';
159 else
160#endif
161 if ((unsigned)c < 0x20)
162 {
163 if (c == '\n'
164 || (IsTerminalMode && (c == 0x1b || (c <= 13 && c >= 7))))
165 {
166#if 1 || defined(_WIN32)
167 c = (wchar_t)kReplaceChar;
168#else
169 temp += (wchar_t)L'\\';
170 if (c == '\n') c = L'n';
171 else if (c == '\r') c = L'r';
172 else if (c == '\a') c = L'a';
173 else if (c == '\b') c = L'b';
174 else if (c == '\t') c = L't';
175 else if (c == '\v') c = L'v';
176 else if (c == '\f') c = L'f';
177 else
178 {
179 temp += (wchar_t)(L'0' + (unsigned)c / 64);
180 temp += (wchar_t)(L'0' + (unsigned)c / 8 % 8);
181 c = (wchar_t)(L'0' + (unsigned)c % 8);
182 }
183#endif
184 }
185 }
186 temp += c;
187 }
188 src = temp;
189}
190*/
191
192void CStdOutStream::NormalizePrint_UString_Path(const UString &s, UString &tempU, AString &tempA)
114{ 193{
115 tempU = s; 194 tempU = s;
116 Normalize_UString(tempU); 195 Normalize_UString_Path(tempU);
117 PrintUString(tempU, tempA); 196 PrintUString(tempU, tempA);
118} 197}
119 198
120void CStdOutStream::NormalizePrint_UString(const UString &s) 199void CStdOutStream::NormalizePrint_UString_Path(const UString &s)
121{ 200{
122 NormalizePrint_wstr(s); 201 UString tempU;
202 AString tempA;
203 NormalizePrint_UString_Path(s, tempU, tempA);
123} 204}
124 205
125void CStdOutStream::NormalizePrint_wstr(const wchar_t *s) 206void CStdOutStream::NormalizePrint_wstr_Path(const wchar_t *s)
126{ 207{
127 UString tempU = s; 208 UString tempU = s;
128 Normalize_UString(tempU); 209 Normalize_UString_Path(tempU);
129 AString tempA; 210 AString tempA;
130 PrintUString(tempU, tempA); 211 PrintUString(tempU, tempA);
131} 212}
132 213
214void CStdOutStream::NormalizePrint_UString(const UString &s)
215{
216 UString tempU = s;
217 Normalize_UString(tempU);
218 AString tempA;
219 PrintUString(tempU, tempA);
220}
133 221
134CStdOutStream & CStdOutStream::operator<<(Int32 number) throw() 222CStdOutStream & CStdOutStream::operator<<(Int32 number) throw()
135{ 223{