final class · System.Text

Match

public final class Match

A match: where it is, its text, and its groups (an unmatched group gives the empty text).

Kind
final class
Namespace
System.Text
Assembly
System.Core
Access
public, final
Source file
Regex.ant

Inheritance

Base classes
Any Match

Constructors

new(u8[] text, i32[] groupStarts, i32[] groupEnds, i32 index, i32 end)
#

Properties

i32 GroupCount { get; }
#

read-only

Methods

static Slice(u8[] s, i32 from, i32 to) : str
#

static

The text between two positions.

Group(i32 i) : str
#

Group i (1-based; 0 is the whole match).

Fields

bool Success
#
i32 Index
#
i32 Length
#
str Value
#

Private and internal members (3)

u8[] s
#

private

i32[] starts
#

private

i32[] ends
#

private

Inherited members (5)

Source

Match as Antril, decompiled from its Larva HIR.

System.Text.Match.ant
// System.Text.Match — System.Core (decompiled from Larva HIR)

import System;

into namespace System.Text
{
	/// A match: where it is, its text, and its groups (an unmatched group gives the empty text).
	public final class Match
	{
		u8[] s;
		i32[] starts;
		i32[] ends;

		public:
			bool Success;
			i32 Index;
			i32 Length;
			str Value;

			/// The text between two positions.
			static Slice(u8[] s, i32 from, i32 to) : str
			{
				u8[] bytes = new u8[to - from];
				Array.Copy(s, from, bytes, 0, to - from);
				return new str(bytes);
			}

			new(u8[] text, i32[] groupStarts, i32[] groupEnds, i32 index, i32 end)
			{
				s = text;
				starts = groupStarts;
				ends = groupEnds;
				Success = index >= 0;
				Index = index;
				Length = Success ? end - index : 0;
				Value = Success ? Slice(text, index, end) : "";
			}

			/// Group `i` (1-based; 0 is the whole match).
			Group(i32 i) : str
			{
				if (i == 0)
					return Value;
				if (i < 0 || i >= starts.Length || starts[i] < 0 || ends[i] < 0)
					return "";
				return Slice(s, starts[i], ends[i]);
			}

			i32 GroupCount
			{
				get => starts.Length - 1;
			}
	}
}
Esc