Welcome to mirror list, hosted at ThFree Co, Russian Federation.

RegexTrial.cs « System.Text.RegularExpressions « Test « System « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 73fc6876f096765c0b159a202c7c371d89f312a0 (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
using System;
using System.Text.RegularExpressions;

namespace MonoTests.System.Text.RegularExpressions {

	class RegexTrial {
		public string pattern;
		public RegexOptions options;
		public string input;

		public string expected;

		public RegexTrial (string pattern, RegexOptions options, string input, string expected) {
			this.pattern = pattern;
			this.options = options;
			this.input = input;
			this.expected = expected;
		}

		public string Expected {
			get { return expected; }
		}

		public string Execute () {
			string result;
			try {
				Regex re = new Regex (pattern, options);
				Match m = re.Match (input);

				if (m.Success) {
					result = "Pass.";

					for (int i = 0; i < m.Groups.Count; ++ i) {
						Group group = m.Groups[i];
						
						result += " Group[" + i + "]=";
						foreach (Capture cap in group.Captures) {
							result += "(" + cap.Index + "," + cap.Length + ")";
						}
					}
				}
				else
					result = "Fail.";
			}
			catch (Exception) {
				result = "Error.";
			}

			return result;
		}

		public override string ToString () {
			return
				"Matching input '" + input +
				"' against pattern '" + pattern +
				"' with options '" + options + "'.";
		}
	}

	class Checksum {
		public Checksum () {
			this.sum = 0;
		}

		public uint Value {
			get { return sum; }
		}

		public void Add (string str) {
			for (int i = 0; i < str.Length; ++ i)
				Add (str[i], 16);
		}

		public void Add (uint n) {
			Add (n, 32);
		}

		public void Add (ulong n, int bits) {
			ulong mask = 1ul << (bits - 1);
			for (int i = 0; i < bits; ++ i) {
				Add ((n & mask) != 0);
				mask >>= 1;
			}
		}

		public void Add (bool bit) {
			bool top = (sum & 0x80000000) != 0;
			sum <<= 1;
			sum ^= bit ? (uint)1 : (uint)0;

			if (top)
				sum ^= key;
		}

		private uint sum;
		private readonly uint key = 0x04c11db7;
	}
}