-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlockReader.cs
84 lines (73 loc) · 1.91 KB
/
BlockReader.cs
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
using System;
using System.Collections.Generic;
namespace AspCodeAnalyzer {
public class BlockReader {
private List<CodeBlock> _blocks;
private CodeBlock _curBlock;
private int _curLineNumber;
private bool _eof = false;
private string _curLine;
public BlockReader( List<CodeBlock> pBlocks) {
_blocks = pBlocks;
}
public void ReadLine() {
if ( _eof ) {
_curLine = null;
return;
}
if ( _curBlock == null ) {
if ( _blocks == null || _blocks.Count == 0 ) {
_eof = true;
_curLine = null;
return;
}
_curLineNumber = 0;
_curBlock = _blocks[ 0];
_blocks.RemoveAt( 0);
_curLine = _curBlock.Text[ _curLineNumber];
return;
}
_curLineNumber++;
if ( _curLineNumber >= _curBlock.Text.Count ) {
if ( _blocks == null || _blocks.Count == 0 ) {
_eof = true;
_curLine = null;
return;
}
_curLineNumber = 0;
_curBlock = _blocks[ 0];
_blocks.RemoveAt( 0);
_curLine = _curBlock.Text[ _curLineNumber];
return;
}
_curLine = _curBlock.Text[ _curLineNumber];
}
public int GetLineNumber() {
if ( _curBlock == null || _eof ) {
throw new Exception( "Wrong state");
}
return _curBlock.Row + _curLineNumber;
}
public int GetCol() {
if ( _curBlock == null || _eof ) {
throw new Exception( "Wrong state");
}
if ( _curLineNumber == 0 ) {
return _curBlock.Col;
} else {
return 0;
}
}
public string GetCurLine() {
if ( _eof ) {
return null;
}
return _curLine;
}
public void SetCurLine( string pLine)
{
_curLine = pLine;
_curBlock.Text[_curLineNumber] = pLine;
}
}
}