diff options
author | 2023-05-04 02:41:16 +1000 | |
---|---|---|
committer | 2023-05-04 02:41:16 +1000 | |
commit | a504bde3a7462b54fafd5cfc2f52e58d0f3218e1 (patch) | |
tree | 8b3108d572b1a0873a6cdbb4e8af1f17179545c3 /3rdparty/lzma/CPP/Common/StdOutStream.cpp | |
parent | befb9bf4a8cfdb2b693a32e32535b5eac522c5d8 (diff) |
3rdparty/lzma: Updated to LZMA SDK version 22.01
Diffstat (limited to '3rdparty/lzma/CPP/Common/StdOutStream.cpp')
-rw-r--r-- | 3rdparty/lzma/CPP/Common/StdOutStream.cpp | 94 |
1 files changed, 73 insertions, 21 deletions
diff --git a/3rdparty/lzma/CPP/Common/StdOutStream.cpp b/3rdparty/lzma/CPP/Common/StdOutStream.cpp index 6aed31a3143..40799e22642 100644 --- a/3rdparty/lzma/CPP/Common/StdOutStream.cpp +++ b/3rdparty/lzma/CPP/Common/StdOutStream.cpp @@ -2,18 +2,16 @@ #include "StdAfx.h" +#ifdef _WIN32 #include <tchar.h> +#endif #include "IntToString.h" #include "StdOutStream.h" #include "StringConvert.h" #include "UTFConvert.h" -static const char kNewLineChar = '\n'; - -static const char *kFileOpenMode = "wt"; - -extern int g_CodePage; +#define kFileOpenMode "wt" CStdOutStream g_StdOut(stdout); CStdOutStream g_StdErr(stderr); @@ -44,39 +42,93 @@ bool CStdOutStream::Flush() throw() CStdOutStream & endl(CStdOutStream & outStream) throw() { - return outStream << kNewLineChar; + return outStream << '\n'; } CStdOutStream & CStdOutStream::operator<<(const wchar_t *s) { - int codePage = g_CodePage; + AString temp; + UString s2(s); + PrintUString(s2, temp); + return *this; +} + +void CStdOutStream::PrintUString(const UString &s, AString &temp) +{ + Convert_UString_to_AString(s, temp); + *this << (const char *)temp; +} + +void CStdOutStream::Convert_UString_to_AString(const UString &src, AString &dest) +{ + int codePage = CodePage; if (codePage == -1) codePage = CP_OEMCP; - AString dest; if (codePage == CP_UTF8) - ConvertUnicodeToUTF8(s, dest); + ConvertUnicodeToUTF8(src, dest); else - UnicodeStringToMultiByte2(dest, s, (UINT)codePage); - return operator<<((const char *)dest); + UnicodeStringToMultiByte2(dest, src, (UINT)codePage); } -void StdOut_Convert_UString_to_AString(const UString &s, AString &temp) + +static const wchar_t kReplaceChar = '_'; + +void CStdOutStream::Normalize_UString__LF_Allowed(UString &s) { - int codePage = g_CodePage; - if (codePage == -1) - codePage = CP_OEMCP; - if (codePage == CP_UTF8) - ConvertUnicodeToUTF8(s, temp); + 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') + d[i] = kReplaceChar; + } +} + +void CStdOutStream::Normalize_UString(UString &s) +{ + 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) + d[i] = kReplaceChar; + } else - UnicodeStringToMultiByte2(temp, s, (UINT)codePage); + for (unsigned i = 0; i < len; i++) + { + wchar_t c = d[i]; + if (c == '\n') + d[i] = kReplaceChar; + } } -void CStdOutStream::PrintUString(const UString &s, AString &temp) +void CStdOutStream::NormalizePrint_UString(const UString &s, UString &tempU, AString &tempA) { - StdOut_Convert_UString_to_AString(s, temp); - *this << (const char *)temp; + tempU = s; + Normalize_UString(tempU); + PrintUString(tempU, tempA); } +void CStdOutStream::NormalizePrint_UString(const UString &s) +{ + NormalizePrint_wstr(s); +} + +void CStdOutStream::NormalizePrint_wstr(const wchar_t *s) +{ + UString tempU = s; + Normalize_UString(tempU); + AString tempA; + PrintUString(tempU, tempA); +} + + CStdOutStream & CStdOutStream::operator<<(Int32 number) throw() { char s[32]; |