]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_codesigning/antlr2/src/CharBuffer.cpp
Security-58286.251.4.tar.gz
[apple/security.git] / OSX / libsecurity_codesigning / antlr2 / src / CharBuffer.cpp
1 /* ANTLR Translator Generator
2 * Project led by Terence Parr at http://www.jGuru.com
3 * Software rights: http://www.antlr.org/license.html
4 *
5 * $Id: //depot/code/org.antlr/release/antlr-2.7.7/lib/cpp/src/CharBuffer.cpp#2 $
6 */
7
8 #include "antlr/CharBuffer.hpp"
9 //#include <iostream>
10
11 //#include <ios>
12
13 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
14 namespace antlr {
15 #endif
16
17 /* RK: Per default istream does not throw exceptions. This can be
18 * enabled with:
19 * stream.exceptions(ios_base::badbit|ios_base::failbit|ios_base::eofbit);
20 *
21 * We could try catching the bad/fail stuff. But handling eof via this is
22 * not a good idea. EOF is best handled as a 'normal' character.
23 *
24 * So this does not work yet with gcc... Comment it until I get to a platform
25 * that does..
26 */
27
28 /** Create a character buffer. Enable fail and bad exceptions, if supported
29 * by platform. */
30 CharBuffer::CharBuffer(ANTLR_USE_NAMESPACE(std)istream& input_)
31 : input(input_)
32 {
33 // input.exceptions(ANTLR_USE_NAMESPACE(std)ios_base::badbit|
34 // ANTLR_USE_NAMESPACE(std)ios_base::failbit);
35 }
36
37 /** Get the next character from the stream. May throw CharStreamIOException
38 * when something bad happens (not EOF) (if supported by platform).
39 */
40 int CharBuffer::getChar()
41 {
42 // try {
43 int i = input.get();
44
45 if (i == -1) {
46 // pass through EOF
47 return -1;
48 }
49
50 // prevent negative-valued characters through sign extension of high-bit characters
51 return static_cast<int>(static_cast<unsigned char>(i));
52 // }
53 // catch (ANTLR_USE_NAMESPACE(std)ios_base::failure& e) {
54 // throw CharStreamIOException(e);
55 // }
56 }
57
58 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
59 }
60 #endif