summaryrefslogtreecommitdiff
path: root/src/xmlreader.cpp
blob: 432ecc1a07ecc1e80203b9b0ac96fa0732136490 (plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "xmlreader.h"

Bu::XmlReader::XmlReader( Bu::Stream &sIn ) :
	sIn( sIn )
{
}

Bu::XmlReader::~XmlReader()
{
}

const char *Bu::XmlReader::lookahead( int nAmnt )
{
	if( sBuf.getSize() >= nAmnt )
		return sBuf.getStr();

	int nNew = nAmnt - sBuf.getSize();
	char *buf = new char[nNew];
	sIn.read( buf, nNew );
	sBuf.append( buf );

	return sBuf.getStr();
}

void Bu::XmlReader::burn( int nAmnt )
{
	if( sBuf.getSize() < nAmnt )
	{
		lookahead( nAmnt );
	}

	sBuf.remove( nAmnt );
}

void Bu::XmlNode::checkString( const char *str, int nLen )
{
	if( !strncmp( str, lookahead( nLen ), nLen ) )
	{
		burn( nLen );
		return;
	}

	throw Bu::ExceptionBase("Expected string '%s'", str );
}

Bu::XmlNode *Bu::XmlReader::read()
{
	prolog();
}

void Bu::XmlReader::prolog()
{
	XMLDecl();
	Misc();
}

void Bu::XmlReader::XMLDecl()
{
	checkString("<?xml", 5 );
	VersionInfo();
	EncodingDecl();
	SDDecl();
	S();
}

void Bu::XmlReader::Misc()
{
}

void Bu::XmlReader::S()
{
	for( int j = 0;; j++ )
	{
		char c = *lookahead( 1 );
		if( c == 0x20 || c == 0x9 || c == 0xD || c == 0xA )
			continue;
		if( j == 0 )
			printf("Error, expected whitespace!\n");
		return;
	}
}

void Bu::XmlReader::S()
{
	for(;;)
	{
		char c = *lookahead( 1 );
		if( c == 0x20 || c == 0x9 || c == 0xD || c == 0xA )
			continue;
		return;
	}
}

void Bu::XmlReader::VersionInfo()
{
	S();
	checkString("version", 7 );
	
}

void Bu::XmlReader::Eq()
{
	Sq();
	checkString("=", 1 );
	Sq();
}