Switched the utf bom checking to putback in the stream (instead of keeping a secondary buffer), which fixes a bug when there's only one ascii character

This commit is contained in:
beder
2011-10-20 22:29:41 -05:00
parent df9bcd5f12
commit e4e410af5b
2 changed files with 7 additions and 17 deletions

View File

@@ -178,7 +178,7 @@ namespace YAML
} }
Stream::Stream(std::istream& input) Stream::Stream(std::istream& input)
: m_input(input), m_nPushedBack(0), : m_input(input),
m_pPrefetched(new unsigned char[YAML_PREFETCH_SIZE]), m_pPrefetched(new unsigned char[YAML_PREFETCH_SIZE]),
m_nPrefetchedAvailable(0), m_nPrefetchedUsed(0) m_nPrefetchedAvailable(0), m_nPrefetchedUsed(0)
{ {
@@ -199,11 +199,10 @@ namespace YAML
UtfIntroState newState = s_introTransitions[state][charType]; UtfIntroState newState = s_introTransitions[state][charType];
int nUngets = s_introUngetCount[state][charType]; int nUngets = s_introUngetCount[state][charType];
if(nUngets > 0) { if(nUngets > 0) {
input.clear();
for(; nUngets > 0; --nUngets) { for(; nUngets > 0; --nUngets) {
if (char_traits::eof() != intro[--nIntroUsed]) { if(char_traits::eof() != intro[--nIntroUsed])
m_bufPushback[m_nPushedBack++] = input.putback(char_traits::to_char_type(intro[nIntroUsed]));
char_traits::to_char_type(intro[nIntroUsed]);
}
} }
} }
state = newState; state = newState;
@@ -398,11 +397,6 @@ namespace YAML
unsigned char Stream::GetNextByte() const unsigned char Stream::GetNextByte() const
{ {
if (m_nPushedBack)
{
return m_bufPushback[--m_nPushedBack];
}
if (m_nPrefetchedUsed >= m_nPrefetchedAvailable) if (m_nPrefetchedUsed >= m_nPrefetchedAvailable)
{ {
std::streambuf *pBuf = m_input.rdbuf(); std::streambuf *pBuf = m_input.rdbuf();

View File

@@ -17,8 +17,6 @@
namespace YAML namespace YAML
{ {
static const size_t MAX_PARSER_PUSHBACK = 8;
class Stream: private noncopyable class Stream: private noncopyable
{ {
public: public:
@@ -50,8 +48,6 @@ namespace YAML
Mark m_mark; Mark m_mark;
CharacterSet m_charSet; CharacterSet m_charSet;
unsigned char m_bufPushback[MAX_PARSER_PUSHBACK];
mutable size_t m_nPushedBack;
mutable std::deque<char> m_readahead; mutable std::deque<char> m_readahead;
unsigned char* const m_pPrefetched; unsigned char* const m_pPrefetched;
mutable size_t m_nPrefetchedAvailable; mutable size_t m_nPrefetchedAvailable;