Text
found by a Pattern
.core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
core :: Match :: defaultinit
core :: Object :: defaultinit
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: native_class_name
The class name of the object in CString format.core :: Object :: output_class_name
Display class name on stdout (debug only).
# 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
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