stream.cpp 759 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "crt.h"
#include "stream.h"
#include <iostream>

namespace YAML
{
	int Stream::pos() const
	{
		return input.tellg();
	}
	
	char Stream::peek()
	{
		return input.peek();
	}
	
	Stream::operator bool()
	{
		return input.good();
	}

	// get
	// . Extracts a character from the stream and updates our position
	char Stream::get()
	{
		char ch = input.get();
		column++;
		if(ch == '\n') {
			column = 0;
			line++;
		}
		return ch;
	}

	// get
	// . Extracts 'n' characters from the stream and updates our position
	std::string Stream::get(int n)
	{
		std::string ret;
		for(int i=0;i<n;i++)
			ret += get();
		return ret;
	}

	// eat
	// . Eats 'n' characters and updates our position.
	void Stream::eat(int n)
	{
		for(int i=0;i<n;i++)
			get();
	}

}