mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 20:51:16 +00:00
Merged utf branch changes r178:187 into the trunk
This commit is contained in:
58
src/stream.h
58
src/stream.h
@@ -1,42 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
#include <deque>
|
||||
#include <ios>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
// a simple buffer wrapper that knows how big it is
|
||||
struct Buffer {
|
||||
Buffer(const char *b, int s): buffer(b), size(s) {}
|
||||
|
||||
operator bool() const { return size > 0; }
|
||||
bool operator !() const { return !static_cast <bool> (*this); }
|
||||
char operator [] (int i) const { return buffer[i]; }
|
||||
const Buffer operator + (int offset) const { return Buffer(buffer + offset, size - offset); }
|
||||
Buffer& operator ++ () { ++buffer; --size; return *this; }
|
||||
|
||||
const char *buffer;
|
||||
int size;
|
||||
};
|
||||
static const size_t MAX_PARSER_PUSHBACK = 8;
|
||||
|
||||
class Stream
|
||||
{
|
||||
public:
|
||||
friend class StreamCharSource;
|
||||
|
||||
Stream(std::istream& input);
|
||||
~Stream();
|
||||
|
||||
operator bool() const;
|
||||
bool operator !() const { return !static_cast <bool>(*this); }
|
||||
|
||||
const Buffer current() const { return Buffer(buffer + pos, size - pos); }
|
||||
char peek();
|
||||
char peek() const;
|
||||
char get();
|
||||
std::string get(int n);
|
||||
void eat(int n = 1);
|
||||
|
||||
int pos, line, column, size;
|
||||
static char eof() { return 0x04; }
|
||||
|
||||
int pos, line, column;
|
||||
|
||||
private:
|
||||
char *buffer;
|
||||
enum CharacterSet {utf8, utf16le, utf16be, utf32le, utf32be};
|
||||
|
||||
std::istream& m_input;
|
||||
CharacterSet m_charSet;
|
||||
unsigned char m_bufPushback[MAX_PARSER_PUSHBACK];
|
||||
mutable size_t m_nPushedBack;
|
||||
mutable std::deque<char> m_readahead;
|
||||
unsigned char* const m_pPrefetched;
|
||||
mutable size_t m_nPrefetchedAvailable;
|
||||
mutable size_t m_nPrefetchedUsed;
|
||||
|
||||
void AdvanceCurrent();
|
||||
char CharAt(size_t i) const;
|
||||
bool ReadAheadTo(size_t i) const;
|
||||
bool _ReadAheadTo(size_t i) const;
|
||||
void StreamInUtf8() const;
|
||||
void StreamInUtf16() const;
|
||||
void StreamInUtf32() const;
|
||||
unsigned char GetNextByte() const;
|
||||
};
|
||||
|
||||
// CharAt
|
||||
// . Unchecked access
|
||||
inline char Stream::CharAt(size_t i) const {
|
||||
return m_readahead[i];
|
||||
}
|
||||
|
||||
inline bool Stream::ReadAheadTo(size_t i) const {
|
||||
if(m_readahead.size() > i)
|
||||
return true;
|
||||
return _ReadAheadTo(i);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user