mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 20:51:16 +00:00
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:
@@ -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)
|
||||||
{
|
{
|
||||||
@@ -192,18 +192,17 @@ namespace YAML
|
|||||||
char_traits::int_type intro[4];
|
char_traits::int_type intro[4];
|
||||||
int nIntroUsed = 0;
|
int nIntroUsed = 0;
|
||||||
UtfIntroState state = uis_start;
|
UtfIntroState state = uis_start;
|
||||||
for (; !s_introFinalState[state]; ) {
|
for(; !s_introFinalState[state]; ) {
|
||||||
std::istream::int_type ch = input.get();
|
std::istream::int_type ch = input.get();
|
||||||
intro[nIntroUsed++] = ch;
|
intro[nIntroUsed++] = ch;
|
||||||
UtfIntroCharType charType = IntroCharTypeOf(ch);
|
UtfIntroCharType charType = IntroCharTypeOf(ch);
|
||||||
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) {
|
||||||
for (; nUngets > 0; --nUngets) {
|
input.clear();
|
||||||
if (char_traits::eof() != intro[--nIntroUsed]) {
|
for(; nUngets > 0; --nUngets) {
|
||||||
m_bufPushback[m_nPushedBack++] =
|
if(char_traits::eof() != intro[--nIntroUsed])
|
||||||
char_traits::to_char_type(intro[nIntroUsed]);
|
input.putback(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();
|
||||||
|
@@ -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;
|
||||||
|
Reference in New Issue
Block a user