1 #include "ACEXML/common/StrCharStream.h"
2 #include "ACEXML/common/Encoding.h"
4 #include "ace/Log_Msg.h"
5 #include "ace/OS_NS_string.h"
7 ACEXML_StrCharStream::ACEXML_StrCharStream ()
8 : start_ (0), ptr_ (0), end_ (0), encoding_ (0), name_ (0)
13 ACEXML_StrCharStream::~ACEXML_StrCharStream ()
19 ACEXML_StrCharStream::open (const ACEXML_Char
*str
, const ACEXML_Char
* name
)
21 if (str
!= 0 && name
!= 0)
23 delete [] this->start_
;
24 if ((this->start_
= ACE::strnew (str
)) == 0)
26 delete [] this->name_
;
27 if ((this->name_
= ACE::strnew (name
)) == 0)
29 this->ptr_
= this->start_
;
30 this->end_
= this->start_
+ ACE_OS::strlen (this->start_
);
31 return this->determine_encoding();
33 return -1; // Invalid string passed.
37 ACEXML_StrCharStream::available ()
39 if (this->start_
!= 0)
40 return static_cast<int> (this->end_
- this->start_
); // @@ Will this work on all platforms?
45 ACEXML_StrCharStream::close ()
47 delete[] this->start_
;
48 delete[] this->encoding_
;
52 this->start_
= this->ptr_
= this->end_
= 0;
57 ACEXML_StrCharStream::determine_encoding ()
59 if (this->start_
== 0)
61 char input
[4] = {0,0,0,0};
62 char* sptr
= (char*)this->start_
;
64 for ( ; i
< 4 && sptr
!= (char*)this->end_
; ++sptr
, ++i
)
66 const ACEXML_Char
* temp
= ACEXML_Encoding::get_encoding (input
);
71 delete [] this->encoding_
;
72 this->encoding_
= ACE::strnew (temp
);
73 // ACE_DEBUG ((LM_DEBUG, "String's encoding is %s\n", this->encoding_));
79 ACEXML_StrCharStream::rewind ()
81 this->ptr_
= this->start_
;
82 this->determine_encoding();
86 ACEXML_StrCharStream::get (ACEXML_Char
& ch
)
88 if (this->start_
!= 0 && this->ptr_
!= this->end_
)
97 ACEXML_StrCharStream::read (ACEXML_Char
*str
, size_t len
)
99 if (this->start_
!= 0 &&
100 this->ptr_
!= this->end_
)
102 if (len
* sizeof (ACEXML_Char
) > (size_t) (this->end_
- this->ptr_
))
103 len
= this->end_
- this->ptr_
;
104 ACE_OS::strncpy (str
, this->ptr_
, len
);
106 return static_cast<int> (len
);
112 ACEXML_StrCharStream::peek ()
114 if (this->start_
!= 0 && this->ptr_
!= this->end_
)
120 ACEXML_StrCharStream::getEncoding ()
122 return this->encoding_
;
126 ACEXML_StrCharStream::getSystemId()