From 860365b263712ea4bda11fb1cf05abc27c6426fb Mon Sep 17 00:00:00 2001 From: Jesse Beder Date: Thu, 20 Oct 2011 22:29:41 -0500 Subject: [PATCH] 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 --- src/stream.cpp | 20 +++++++------------- src/stream.h | 4 ---- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/stream.cpp b/src/stream.cpp index 0d1426a..5cfb1bb 100644 --- a/src/stream.cpp +++ b/src/stream.cpp @@ -178,7 +178,7 @@ namespace YAML } Stream::Stream(std::istream& input) - : m_input(input), m_nPushedBack(0), + : m_input(input), m_pPrefetched(new unsigned char[YAML_PREFETCH_SIZE]), m_nPrefetchedAvailable(0), m_nPrefetchedUsed(0) { @@ -192,18 +192,17 @@ namespace YAML char_traits::int_type intro[4]; int nIntroUsed = 0; UtfIntroState state = uis_start; - for (; !s_introFinalState[state]; ) { + for(; !s_introFinalState[state]; ) { std::istream::int_type ch = input.get(); intro[nIntroUsed++] = ch; UtfIntroCharType charType = IntroCharTypeOf(ch); UtfIntroState newState = s_introTransitions[state][charType]; int nUngets = s_introUngetCount[state][charType]; - if (nUngets > 0) { - for (; nUngets > 0; --nUngets) { - if (char_traits::eof() != intro[--nIntroUsed]) { - m_bufPushback[m_nPushedBack++] = - char_traits::to_char_type(intro[nIntroUsed]); - } + if(nUngets > 0) { + input.clear(); + for(; nUngets > 0; --nUngets) { + if(char_traits::eof() != intro[--nIntroUsed]) + input.putback(char_traits::to_char_type(intro[nIntroUsed])); } } state = newState; @@ -398,11 +397,6 @@ namespace YAML unsigned char Stream::GetNextByte() const { - if (m_nPushedBack) - { - return m_bufPushback[--m_nPushedBack]; - } - if (m_nPrefetchedUsed >= m_nPrefetchedAvailable) { std::streambuf *pBuf = m_input.rdbuf(); diff --git a/src/stream.h b/src/stream.h index 90a401e..87f48dc 100644 --- a/src/stream.h +++ b/src/stream.h @@ -17,8 +17,6 @@ namespace YAML { - static const size_t MAX_PARSER_PUSHBACK = 8; - class Stream: private noncopyable { public: @@ -50,8 +48,6 @@ namespace YAML Mark m_mark; CharacterSet m_charSet; - unsigned char m_bufPushback[MAX_PARSER_PUSHBACK]; - mutable size_t m_nPushedBack; mutable std::deque m_readahead; unsigned char* const m_pPrefetched; mutable size_t m_nPrefetchedAvailable;