diff options
Diffstat (limited to '3rdparty/lzma/CPP/Common/StdInStream.cpp')
-rw-r--r-- | 3rdparty/lzma/CPP/Common/StdInStream.cpp | 82 |
1 files changed, 43 insertions, 39 deletions
diff --git a/3rdparty/lzma/CPP/Common/StdInStream.cpp b/3rdparty/lzma/CPP/Common/StdInStream.cpp index c35747bbe69..7b209f1ca75 100644 --- a/3rdparty/lzma/CPP/Common/StdInStream.cpp +++ b/3rdparty/lzma/CPP/Common/StdInStream.cpp @@ -2,28 +2,34 @@ #include "StdAfx.h" +#ifdef _WIN32 #include <tchar.h> +#endif #include "StdInStream.h" #include "StringConvert.h" #include "UTFConvert.h" -static const char kNewLineChar = '\n'; +// #define kEOFMessage "Unexpected end of input stream" +// #define kReadErrorMessage "Error reading input stream" +// #define kIllegalCharMessage "Illegal zero character in input stream" -static const char *kEOFMessage = "Unexpected end of input stream"; -static const char *kReadErrorMessage ="Error reading input stream"; -static const char *kIllegalCharMessage = "Illegal character in input stream"; - -static LPCTSTR kFileOpenMode = TEXT("r"); - -extern int g_CodePage; CStdInStream g_StdIn(stdin); +/* +#define kFileOpenMode TEXT("r") + bool CStdInStream::Open(LPCTSTR fileName) throw() { Close(); - _stream = _tfopen(fileName, kFileOpenMode); + _stream = + #ifdef _WIN32 + _tfopen + #else + fopen + #endif + (fileName, kFileOpenMode); _streamIsOpen = (_stream != 0); return _streamIsOpen; } @@ -35,60 +41,58 @@ bool CStdInStream::Close() throw() _streamIsOpen = (fclose(_stream) != 0); return !_streamIsOpen; } +*/ -AString CStdInStream::ScanStringUntilNewLine(bool allowEOF) +bool CStdInStream::ScanAStringUntilNewLine(AString &s) { - AString s; + s.Empty(); for (;;) { int intChar = GetChar(); if (intChar == EOF) - { - if (allowEOF) - break; - throw kEOFMessage; - } + return true; char c = (char)intChar; if (c == 0) - throw kIllegalCharMessage; - if (c == kNewLineChar) - break; + return false; + if (c == '\n') + return true; s += c; } - return s; } -UString CStdInStream::ScanUStringUntilNewLine() +bool CStdInStream::ScanUStringUntilNewLine(UString &dest) { - AString s = ScanStringUntilNewLine(true); - int codePage = g_CodePage; + dest.Empty(); + AString s; + bool res = ScanAStringUntilNewLine(s); + int codePage = CodePage; if (codePage == -1) codePage = CP_OEMCP; - UString dest; if (codePage == CP_UTF8) ConvertUTF8ToUnicode(s, dest); else - dest = MultiByteToUnicodeString(s, (UINT)codePage); - return dest; + MultiByteToUnicodeString2(dest, s, (UINT)codePage); + return res; } -void CStdInStream::ReadToString(AString &resultString) +/* +bool CStdInStream::ReadToString(AString &resultString) { resultString.Empty(); - int c; - while ((c = GetChar()) != EOF) - resultString += (char)c; -} - -bool CStdInStream::Eof() throw() -{ - return (feof(_stream) != 0); + for (;;) + { + int intChar = GetChar(); + if (intChar == EOF) + return !Error(); + char c = (char)intChar; + if (c == 0) + return false; + resultString += c; + } } +*/ int CStdInStream::GetChar() { - int c = fgetc(_stream); // getc() doesn't work in BeOS? - if (c == EOF && !Eof()) - throw kReadErrorMessage; - return c; + return fgetc(_stream); // getc() doesn't work in BeOS? } |