-
Notifications
You must be signed in to change notification settings - Fork 0
/
NewLineDetector.cs
66 lines (59 loc) · 1.64 KB
/
NewLineDetector.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
namespace AndroidUITestFramework
{
public class NewLineDetector
{
System.IO.TextWriter textWriter;
int index;
int previousIndex;
public System.Func<string> NewLine;
private static object LOCK = new();
public NewLineDetector(System.IO.TextWriter textWriter, string from)
{
this.textWriter = textWriter;
NewLine = () => from ?? this.textWriter.NewLine;
reset();
}
public NewLineDetector(System.IO.TextWriter textWriter) : this(textWriter, null)
{
}
public bool processNext(char c)
{
lock (LOCK)
{
string n = NewLine?.Invoke();
if (n == null || n.Length == 0)
return false;
previousIndex = index;
if (n[index] == c)
{
// n[0] = '\r'
// n[1] = '\n'
// index = 0
// n.Length = 2
// 0 == 1
if (index == n.Length - 1)
{
index = 0;
return true;
}
index++;
}
else
{
index = 0;
}
return false;
}
}
public void reset()
{
lock (LOCK)
{
index = 0;
previousIndex = 0;
}
}
public int getIndex() => index;
public int getPreviousIndex() => previousIndex;
}
}