From fc662341e6f85da78ada0e443f6116b978f79f22 Mon Sep 17 00:00:00 2001 From: Igor Pavlov <87184205+ip7z@users.noreply.github.com> Date: Tue, 14 May 2024 00:00:00 +0000 Subject: 24.05 --- CPP/Common/StdOutStream.cpp | 120 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 104 insertions(+), 16 deletions(-) (limited to 'CPP/Common/StdOutStream.cpp') 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 int codePage = CodePage; if (codePage == -1) codePage = CP_OEMCP; - if (codePage == CP_UTF8) + if ((unsigned)codePage == CP_UTF8) ConvertUnicodeToUTF8(src, dest); else - UnicodeStringToMultiByte2(dest, src, (UINT)codePage); + UnicodeStringToMultiByte2(dest, src, (UINT)(unsigned)codePage); } static const wchar_t kReplaceChar = '_'; +/* void CStdOutStream::Normalize_UString_LF_Allowed(UString &s) { - unsigned len = s.Len(); + if (!IsTerminalMode) + return; + + const unsigned len = s.Len(); wchar_t *d = s.GetBuf(); - if (IsTerminalMode) for (unsigned i = 0; i < len; i++) { - wchar_t c = d[i]; - if (c <= 13 && c >= 7 && c != '\n') + const wchar_t c = d[i]; + if (c == 0x1b || (c <= 13 && c >= 7 && c != '\n')) d[i] = kReplaceChar; } } +*/ void CStdOutStream::Normalize_UString(UString &s) { - unsigned len = s.Len(); + const unsigned len = s.Len(); wchar_t *d = s.GetBuf(); if (IsTerminalMode) for (unsigned i = 0; i < len; i++) { - wchar_t c = d[i]; - if (c <= 13 && c >= 7) + const wchar_t c = d[i]; + if ((c <= 13 && c >= 7) || c == 0x1b) d[i] = kReplaceChar; } else for (unsigned i = 0; i < len; i++) { - wchar_t c = d[i]; + const wchar_t c = d[i]; if (c == '\n') d[i] = kReplaceChar; } } -void CStdOutStream::NormalizePrint_UString(const UString &s, UString &tempU, AString &tempA) +void CStdOutStream::Normalize_UString_Path(UString &s) +{ + if (ListPathSeparatorSlash.Def) + { +#ifdef _WIN32 + if (ListPathSeparatorSlash.Val) + s.Replace(L'\\', L'/'); +#else + if (!ListPathSeparatorSlash.Val) + s.Replace(L'/', L'\\'); +#endif + } + Normalize_UString(s); +} + + +/* +void CStdOutStream::Normalize_UString(UString &src) +{ + const wchar_t *s = src.Ptr(); + const unsigned len = src.Len(); + unsigned i; + for (i = 0; i < len; i++) + { + const wchar_t c = s[i]; +#if 0 && !defined(_WIN32) + if (c == '\\') // IsTerminalMode && + break; +#endif + if ((unsigned)c < 0x20) + break; + } + if (i == len) + return; + + UString temp; + for (i = 0; i < len; i++) + { + wchar_t c = s[i]; +#if 0 && !defined(_WIN32) + if (c == '\\') + temp += (wchar_t)L'\\'; + else +#endif + if ((unsigned)c < 0x20) + { + if (c == '\n' + || (IsTerminalMode && (c == 0x1b || (c <= 13 && c >= 7)))) + { +#if 1 || defined(_WIN32) + c = (wchar_t)kReplaceChar; +#else + temp += (wchar_t)L'\\'; + if (c == '\n') c = L'n'; + else if (c == '\r') c = L'r'; + else if (c == '\a') c = L'a'; + else if (c == '\b') c = L'b'; + else if (c == '\t') c = L't'; + else if (c == '\v') c = L'v'; + else if (c == '\f') c = L'f'; + else + { + temp += (wchar_t)(L'0' + (unsigned)c / 64); + temp += (wchar_t)(L'0' + (unsigned)c / 8 % 8); + c = (wchar_t)(L'0' + (unsigned)c % 8); + } +#endif + } + } + temp += c; + } + src = temp; +} +*/ + +void CStdOutStream::NormalizePrint_UString_Path(const UString &s, UString &tempU, AString &tempA) { tempU = s; - Normalize_UString(tempU); + Normalize_UString_Path(tempU); PrintUString(tempU, tempA); } -void CStdOutStream::NormalizePrint_UString(const UString &s) +void CStdOutStream::NormalizePrint_UString_Path(const UString &s) { - NormalizePrint_wstr(s); + UString tempU; + AString tempA; + NormalizePrint_UString_Path(s, tempU, tempA); } -void CStdOutStream::NormalizePrint_wstr(const wchar_t *s) +void CStdOutStream::NormalizePrint_wstr_Path(const wchar_t *s) { UString tempU = s; - Normalize_UString(tempU); + Normalize_UString_Path(tempU); AString tempA; PrintUString(tempU, tempA); } +void CStdOutStream::NormalizePrint_UString(const UString &s) +{ + UString tempU = s; + Normalize_UString(tempU); + AString tempA; + PrintUString(tempU, tempA); +} CStdOutStream & CStdOutStream::operator<<(Int32 number) throw() { -- cgit v1.2.3-55-g6feb