Matches are a part of a Text found by a Pattern.

Introduced properties

fun [](n: Int): nullable Match

core :: Match :: []

Get the nth expression in this match
fun after: Int

core :: Match :: after

The position of the first character just after the matching part.
init defaultinit(string: String, from: Int, length: Int)

core :: Match :: defaultinit

fun from: Int

core :: Match :: from

The starting position in the string
protected fun from=(from: Int)

core :: Match :: from=

The starting position in the string
fun length: Int

core :: Match :: length

The length of the matching part
protected fun length=(length: Int)

core :: Match :: length=

The length of the matching part
fun string: String

core :: Match :: string

The base string matched
protected fun string=(string: String)

core :: Match :: string=

The base string matched
fun subs: Array[nullable Match]

core :: Match :: subs

Parenthesized subexpressions in this match
protected fun subs=(subs: Array[nullable Match])

core :: Match :: subs=

Parenthesized subexpressions in this match
fun text_after: String

core :: Match :: text_after

The content of string after the match
fun text_before: String

core :: Match :: text_before

The content of string before the match

Redefined properties

redef type SELF: Match

core $ Match :: SELF

Type of this instance, automatically specialized in every class
redef init init

core $ Match :: init

redef fun to_s: String

core $ Match :: to_s

The contents of the matching part

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
fun [](n: Int): nullable Match

core :: Match :: []

Get the nth expression in this match
fun after: Int

core :: Match :: after

The position of the first character just after the matching part.
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
init defaultinit(string: String, from: Int, length: Int)

core :: Match :: defaultinit

fun from: Int

core :: Match :: from

The starting position in the string
protected fun from=(from: Int)

core :: Match :: from=

The starting position in the string
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
fun length: Int

core :: Match :: length

The length of the matching part
protected fun length=(length: Int)

core :: Match :: length=

The length of the matching part
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
fun string: String

core :: Match :: string

The base string matched
protected fun string=(string: String)

core :: Match :: string=

The base string matched
fun subs: Array[nullable Match]

core :: Match :: subs

Parenthesized subexpressions in this match
protected fun subs=(subs: Array[nullable Match])

core :: Match :: subs=

Parenthesized subexpressions in this match
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
fun text_after: String

core :: Match :: text_after

The content of string after the match
fun text_before: String

core :: Match :: text_before

The content of string before the match
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
package_diagram core::Match Match core::Object Object core::Match->core::Object

Parents

interface Object

core :: Object

The root of the class hierarchy.

Class definitions

core $ Match
# Matches are a part of a `Text` found by a `Pattern`.
class Match
	# The base string matched
	#
	# ~~~
	# var m = "hello world".search("lo")
	# assert m.string == "hello world"
	# ~~~
	var string: String

	# The starting position in the string
	#
	# ~~~
	# var m = "hello world".search("lo")
	# assert m.from == 3
	# ~~~
	var from: Int

	# The length of the matching part
	#
	# ~~~
	# var m = "hello world".search("lo")
	# assert m.length == 2
	# ~~~
	var length: Int

	# The position of the first character just after the matching part.
	# May be out of the base string
	#
	# ~~~
	# var m = "hello world".search("lo")
	# assert m.after == 5
	# ~~~
	fun after: Int do return from + length

	# The contents of the matching part
	#
	# ~~~
	# var m = "hello world".search("lo")
	# assert m.to_s == "lo"
	# ~~~
	redef fun to_s do return string.substring(from,length)

	# The content of `string` before the match
	#
	# ~~~
	# var m = "hello world".search("lo")
	# assert m.text_before == "hel"
	# ~~~
	fun text_before: String do return string.substring(0, from)

	# The content of `string` after the match
	#
	# ~~~
	# var m = "hello world".search("lo")
	# assert m.text_after == " world"
	# ~~~
	fun text_after: String do return string.substring_from(after)

	init
	do
		assert positive_length: length >= 0
		assert valid_from: from >= 0
		assert valid_after: from + length <= string.length
	end
end
lib/core/text/string_search.nit:237,1--302,3

core :: re $ Match
redef class Match
	# Parenthesized subexpressions in this match
	#
	# ~~~
	# var re = "c (d e+) f".to_re
	# var match = "a b c d eee f g".search(re)
	# assert match.subs.length == 1
	# assert match.subs.first.to_s == "d eee"
	# ~~~
	var subs = new Array[nullable Match] is lazy

	# Get the `n`th expression in this match
	#
	# `n == 0` returns this match, and a greater `n` returns the corresponding
	# subexpression.
	#
	# Require: `n >= 0 and n <= subs.length`
	#
	# ~~~
	# var re = "c (d e+) f".to_re
	# var match = "a b c d eee f g".search(re)
	# assert match[0].to_s == "c d eee f"
	# assert match[1].to_s == "d eee"
	# ~~~
	fun [](n: Int): nullable Match do
		if n == 0 then return self
		assert n > 0 and n <= subs.length
		return subs[n-1]
	end
end
lib/core/re.nit:481,1--510,3