#include <common/StrCharStream.h>
Inheritance diagram for ACEXML_StrCharStream:
Public Member Functions | |
ACEXML_StrCharStream (void) | |
Default constructor. | |
virtual | ~ACEXML_StrCharStream (void) |
Destructor. | |
int | open (const ACEXML_Char *str, const ACEXML_Char *name) |
Initializing StrCharStream with str and name. | |
virtual int | available (void) |
virtual int | close (void) |
virtual int | determine_encoding (void) |
virtual int | get (ACEXML_Char &ch) |
virtual int | read (ACEXML_Char *str, size_t len) |
virtual int | peek (void) |
virtual const ACEXML_Char * | getEncoding (void) |
virtual const ACEXML_Char * | getSystemId (void) |
virtual void | rewind (void) |
Private Attributes | |
ACEXML_Char * | start_ |
ACEXML_Char * | ptr_ |
ACEXML_Char * | end_ |
ACEXML_Char * | encoding_ |
ACEXML_Char * | name_ |
Definition at line 31 of file StrCharStream.h.
ACEXML_StrCharStream::ACEXML_StrCharStream | ( | void | ) |
ACEXML_StrCharStream::~ACEXML_StrCharStream | ( | void | ) | [virtual] |
Destructor.
Definition at line 15 of file StrCharStream.cpp.
References close().
00016 { 00017 this->close(); 00018 }
int ACEXML_StrCharStream::available | ( | void | ) | [virtual] |
Returns the available ACEXML_Char in the buffer. -1 if the object is not initialized properly.
Implements ACEXML_CharStream.
Definition at line 40 of file StrCharStream.cpp.
00041 { 00042 if (this->start_ != 0) 00043 return static_cast<int> (this->end_ - this->start_); // @@ Will this work on all platforms? 00044 return -1; 00045 }
int ACEXML_StrCharStream::close | ( | void | ) | [virtual] |
Close this stream and release all resources used by it.
Implements ACEXML_CharStream.
Definition at line 48 of file StrCharStream.cpp.
References encoding_, end_, name_, ptr_, and start_.
Referenced by ~ACEXML_StrCharStream().
00049 { 00050 delete[] this->start_; 00051 delete[] this->encoding_; 00052 this->encoding_ = 0; 00053 delete[] this->name_; 00054 this->name_ = 0; 00055 this->start_ = this->ptr_ = this->end_ = 0; 00056 return 0; 00057 }
int ACEXML_StrCharStream::determine_encoding | ( | void | ) | [virtual] |
Determine the encoding of the file.
Definition at line 60 of file StrCharStream.cpp.
References encoding_, ACEXML_Encoding::get_encoding(), and ACE::strnew().
Referenced by open(), and rewind().
00061 { 00062 if (this->start_ == 0) 00063 return -1; 00064 char input[4] = {0,0,0,0}; 00065 char* sptr = (char*)this->start_; 00066 int i = 0; 00067 for ( ; i < 4 && sptr != (char*)this->end_; ++sptr, ++i) 00068 input[i] = *sptr; 00069 const ACEXML_Char* temp = ACEXML_Encoding::get_encoding (input); 00070 if (!temp) 00071 return -1; 00072 else 00073 { 00074 delete [] this->encoding_; 00075 this->encoding_ = ACE::strnew (temp); 00076 // ACE_DEBUG ((LM_DEBUG, "String's encoding is %s\n", this->encoding_)); 00077 } 00078 return 0; 00079 }
int ACEXML_StrCharStream::get | ( | ACEXML_Char & | ch | ) | [virtual] |
Read the next ACEXML_Char. Return -1 if we are not able to return an ACEXML_Char, 0 if EOS is reached, or 1 if succeed.
Implements ACEXML_CharStream.
Definition at line 89 of file StrCharStream.cpp.
References ptr_.
00090 { 00091 if (this->start_ != 0 && this->ptr_ != this->end_) 00092 { 00093 ch = *this->ptr_++; 00094 return 0; 00095 } 00096 return -1; 00097 }
const ACEXML_Char * ACEXML_StrCharStream::getEncoding | ( | void | ) | [virtual] |
Implements ACEXML_CharStream.
Definition at line 123 of file StrCharStream.cpp.
References encoding_.
00124 { 00125 return this->encoding_; 00126 }
const ACEXML_Char * ACEXML_StrCharStream::getSystemId | ( | void | ) | [virtual] |
Implements ACEXML_CharStream.
Definition at line 129 of file StrCharStream.cpp.
References name_.
00130 { 00131 return this->name_; 00132 }
int ACEXML_StrCharStream::open | ( | const ACEXML_Char * | str, | |
const ACEXML_Char * | name | |||
) |
Initializing StrCharStream with str and name.
Definition at line 21 of file StrCharStream.cpp.
References determine_encoding(), end_, name_, ptr_, start_, ACE_OS::strlen(), and ACE::strnew().
Referenced by ACEXML_Parser::parse_entity_reference(), and ACEXML_Parser::parse_PE_reference().
00022 { 00023 00024 if (str != 0 && name != 0) 00025 { 00026 delete [] this->start_; 00027 if ((this->start_ = ACE::strnew (str)) == 0) 00028 return -1; 00029 delete [] this->name_; 00030 if ((this->name_ = ACE::strnew (name)) == 0) 00031 return -1; 00032 this->ptr_ = this->start_; 00033 this->end_ = this->start_ + ACE_OS::strlen (this->start_); 00034 return this->determine_encoding(); 00035 } 00036 return -1; // Invalid string passed. 00037 }
int ACEXML_StrCharStream::peek | ( | void | ) | [virtual] |
Peek the next ACEXML_Char in the CharStream. Return the character if succeess, -1 if EOS is reached.
Implements ACEXML_CharStream.
Definition at line 115 of file StrCharStream.cpp.
References ptr_.
00116 { 00117 if (this->start_ != 0 && this->ptr_ != this->end_) 00118 return *this->ptr_; 00119 return -1; 00120 }
int ACEXML_StrCharStream::read | ( | ACEXML_Char * | str, | |
size_t | len | |||
) | [virtual] |
Read the next batch of ACEXML_Char strings
Implements ACEXML_CharStream.
Definition at line 100 of file StrCharStream.cpp.
References end_, ptr_, and ACE_OS::strncpy().
00101 { 00102 if (this->start_ != 0 && 00103 this->ptr_ != this->end_) 00104 { 00105 if (len * sizeof (ACEXML_Char) > (size_t) (this->end_ - this->ptr_)) 00106 len = this->end_ - this->ptr_; 00107 ACE_OS::strncpy (str, this->ptr_, len); 00108 this->ptr_ += len; 00109 return static_cast<int> (len); 00110 } 00111 return 0; 00112 }
void ACEXML_StrCharStream::rewind | ( | void | ) | [virtual] |
Resets the pointer to the beginning of the stream.
Implements ACEXML_CharStream.
Definition at line 82 of file StrCharStream.cpp.
References determine_encoding(), ptr_, and start_.
00083 { 00084 this->ptr_ = this->start_; 00085 this->determine_encoding(); 00086 }
ACEXML_Char* ACEXML_StrCharStream::encoding_ [private] |
Definition at line 95 of file StrCharStream.h.
Referenced by close(), determine_encoding(), and getEncoding().
ACEXML_Char* ACEXML_StrCharStream::end_ [private] |
Definition at line 94 of file StrCharStream.h.
Referenced by available(), close(), open(), and read().
ACEXML_Char* ACEXML_StrCharStream::name_ [private] |
ACEXML_Char* ACEXML_StrCharStream::ptr_ [private] |
ACEXML_Char* ACEXML_StrCharStream::start_ [private] |
Definition at line 92 of file StrCharStream.h.
Referenced by available(), close(), open(), and rewind().