aboutsummaryrefslogtreecommitdiff
path: root/CPP/Common/StdInStream.cpp
diff options
context:
space:
mode:
authorIgor Pavlov <87184205+ip7z@users.noreply.github.com>2021-12-27 00:00:00 +0000
committerIgor Pavlov <87184205+ip7z@users.noreply.github.com>2022-03-18 15:35:13 +0500
commitf19f813537c7aea1c20749c914e756b54a9c3cf5 (patch)
tree816ba62ca7c0fa19f2eb46d9e9d6f7dd7c3a744d /CPP/Common/StdInStream.cpp
parent98e06a519b63b81986abe76d28887f6984a7732b (diff)
download7zip-21.07.tar.gz
7zip-21.07.tar.bz2
7zip-21.07.zip
'21.07'21.07
Diffstat (limited to '')
-rw-r--r--CPP/Common/StdInStream.cpp95
1 files changed, 95 insertions, 0 deletions
diff --git a/CPP/Common/StdInStream.cpp b/CPP/Common/StdInStream.cpp
new file mode 100644
index 0000000..abad34b
--- /dev/null
+++ b/CPP/Common/StdInStream.cpp
@@ -0,0 +1,95 @@
1// Common/StdInStream.cpp
2
3#include "StdAfx.h"
4
5#ifdef _WIN32
6#include <tchar.h>
7#endif
8
9#include "StdInStream.h"
10#include "StringConvert.h"
11#include "UTFConvert.h"
12
13// #define kEOFMessage "Unexpected end of input stream"
14// #define kReadErrorMessage "Error reading input stream"
15// #define kIllegalCharMessage "Illegal zero character in input stream"
16
17#define kFileOpenMode TEXT("r")
18
19CStdInStream g_StdIn(stdin);
20
21bool CStdInStream::Open(LPCTSTR fileName) throw()
22{
23 Close();
24 _stream =
25 #ifdef _WIN32
26 _tfopen
27 #else
28 fopen
29 #endif
30 (fileName, kFileOpenMode);
31 _streamIsOpen = (_stream != 0);
32 return _streamIsOpen;
33}
34
35bool CStdInStream::Close() throw()
36{
37 if (!_streamIsOpen)
38 return true;
39 _streamIsOpen = (fclose(_stream) != 0);
40 return !_streamIsOpen;
41}
42
43bool CStdInStream::ScanAStringUntilNewLine(AString &s)
44{
45 s.Empty();
46 for (;;)
47 {
48 int intChar = GetChar();
49 if (intChar == EOF)
50 return true;
51 char c = (char)intChar;
52 if (c == 0)
53 return false;
54 if (c == '\n')
55 return true;
56 s += c;
57 }
58}
59
60bool CStdInStream::ScanUStringUntilNewLine(UString &dest)
61{
62 dest.Empty();
63 AString s;
64 bool res = ScanAStringUntilNewLine(s);
65 int codePage = CodePage;
66 if (codePage == -1)
67 codePage = CP_OEMCP;
68 if (codePage == CP_UTF8)
69 ConvertUTF8ToUnicode(s, dest);
70 else
71 MultiByteToUnicodeString2(dest, s, (UINT)codePage);
72 return res;
73}
74
75/*
76bool CStdInStream::ReadToString(AString &resultString)
77{
78 resultString.Empty();
79 for (;;)
80 {
81 int intChar = GetChar();
82 if (intChar == EOF)
83 return !Error();
84 char c = (char)intChar;
85 if (c == 0)
86 return false;
87 resultString += c;
88 }
89}
90*/
91
92int CStdInStream::GetChar()
93{
94 return fgetc(_stream); // getc() doesn't work in BeOS?
95}