XU XUv0.16.0

#regexp

import: #regexp

counts: 2 functions, 14 methods, 4 types, 0 constants, 0 method sets

Matching, finding, splitting, expansion and replacement use a shared work budget and explicit heap stacks. Handle errors from these operations, for example matched := re.match_string(&text) >>> (err) { << 1 }. Budget exhaustion is an error; a valid nonmatch retains its empty or false result. Expressions are limited to 65,536 bytes and 64 nested groups. quote_meta, num_subexp and literal_prefix do not perform matching.

struct Regexp

XuAPI
pub struct Regexp {
    pub nodes []Node
    pub root int
    pub class_data string
    pub steps_max int
    pub num_caps int
}

Purpose

Structure encapsulating nodes, root, class_data, steps_max, num_caps.

Public fields

nodes []Node
field ([]Node)
root int
field (int)
class_data string
field (string)
steps_max int
field (int)
num_caps int
field (int)

quote_meta

XuAPI
pub fn quote_meta(s &string) string

Purpose

Quote meta.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)

Returns

string — result string

compile

XuAPI
pub fn compile(expr string) Regexp

Purpose

Execute compile. Throws on failure; handle the error or propagate it to the caller.

Parameters

expr string
expr (string)

Returns

Regexp — a value of this type

(Regexp) num_subexp

XuAPI
pub fn (re Regexp) num_subexp() int

Purpose

Operation on Regexp: num subexp.

Parameters

re Regexp
The Regexp instance used by this call (value receiver).

Returns

int — a value of this type

(Regexp) find_submatch

XuAPI
pub fn (re Regexp) find_submatch(s &string) []string

Purpose

Operation on Regexp: find submatch.

Parameters

re Regexp
The Regexp instance used by this call (value receiver).
s &string
source string (read-only borrow; caller keeps the original; type &string)

Returns

[]string — slice result

struct Submatch

XuAPI
pub struct Submatch {
    pub start int
    pub end int
    pub parts []string
}

Purpose

Structure encapsulating start, end, parts.

Public fields

start int
field (int)
end int
field (int)
parts []string
parts

(Regexp) find_all_submatch

XuAPI
pub fn (re Regexp) find_all_submatch(s &string, n int) [][]string

Purpose

Operation on Regexp: find all submatch.

Parameters

re Regexp
The Regexp instance used by this call (value receiver).
s &string
source string (read-only borrow; caller keeps the original; type &string)
n int
count, length, or limit (int)

Returns

[][]string — slice result

(Regexp) expand

XuAPI
pub fn (re Regexp) expand(s &string, repl &string) string

Purpose

Execute expand on Regexp.

Parameters

re Regexp
The Regexp instance used by this call (value receiver).
s &string
source string (read-only borrow; caller keeps the original; type &string)
repl &string
repl (read-only borrow; caller keeps the original; type &string)

Returns

string — result string

struct LiteralPrefix

XuAPI
pub struct LiteralPrefix {
    pub prefix string
    pub complete bool
}

Purpose

Structure encapsulating prefix, complete.

Public fields

prefix string
prefix
complete bool
field (bool)

(Regexp) literal_prefix

XuAPI
pub fn (re Regexp) literal_prefix() LiteralPrefix

Purpose

Operation on Regexp: literal prefix.

Parameters

re Regexp
The Regexp instance used by this call (value receiver).

Returns

LiteralPrefix — a value of this type

(Regexp) match_string

XuAPI
pub fn (re Regexp) match_string(s &string) bool

Purpose

Operation on Regexp: match string.

Parameters

re Regexp
The Regexp instance used by this call (value receiver).
s &string
source string (read-only borrow; caller keeps the original; type &string)

Returns

bool — true or false

(Regexp) find

XuAPI
pub fn (re Regexp) find(s &string) string

Purpose

Execute find on Regexp.

Parameters

re Regexp
The Regexp instance used by this call (value receiver).
s &string
source string (read-only borrow; caller keeps the original; type &string)

Returns

string — result string

struct Index

XuAPI
pub struct Index {
    pub start int
    pub end int
}

Purpose

Structure encapsulating start, end.

Public fields

start int
field (int)
end int
field (int)

(Regexp) find_index

XuAPI
pub fn (re Regexp) find_index(s &string) Index

Purpose

Operation on Regexp: find index.

Parameters

re Regexp
The Regexp instance used by this call (value receiver).
s &string
source string (read-only borrow; caller keeps the original; type &string)

Returns

Index — a value of this type

(Regexp) find_all_index

XuAPI
pub fn (re Regexp) find_all_index(s &string, n int) []Index

Purpose

Operation on Regexp: find all index.

Parameters

re Regexp
The Regexp instance used by this call (value receiver).
s &string
source string (read-only borrow; caller keeps the original; type &string)
n int
count, length, or limit (int)

Returns

[]Index — slice result

(Regexp) find_all

XuAPI
pub fn (re Regexp) find_all(s &string, n int) []string

Purpose

Operation on Regexp: find all.

Parameters

re Regexp
The Regexp instance used by this call (value receiver).
s &string
source string (read-only borrow; caller keeps the original; type &string)
n int
count, length, or limit (int)

Returns

[]string — slice result

(Regexp) split

XuAPI
pub fn (re Regexp) split(s &string, n int) []string

Purpose

Operation on Regexp: split on the separator.

Parameters

re Regexp
The Regexp instance used by this call (value receiver).
s &string
source string (read-only borrow; caller keeps the original; type &string)
n int
count, length, or limit (int)

Returns

[]string — slice result

(Regexp) find_submatch_index

XuAPI
pub fn (re Regexp) find_submatch_index(s &string) []Index

Purpose

Operation on Regexp: find submatch index.

Parameters

re Regexp
The Regexp instance used by this call (value receiver).
s &string
source string (read-only borrow; caller keeps the original; type &string)

Returns

[]Index — slice result

(Regexp) replace_all_literal

XuAPI
pub fn (re Regexp) replace_all_literal(s &string, repl &string) string

Purpose

Operation on Regexp: replace all literal.

Parameters

re Regexp
The Regexp instance used by this call (value receiver).
s &string
source string (read-only borrow; caller keeps the original; type &string)
repl &string
repl (read-only borrow; caller keeps the original; type &string)

Returns

string — result string

(Regexp) replace_all

XuAPI
pub fn (re Regexp) replace_all(s &string, repl &string) string

Purpose

Operation on Regexp: replace every occurrence of the substring.

Parameters

re Regexp
The Regexp instance used by this call (value receiver).
s &string
source string (read-only borrow; caller keeps the original; type &string)
repl &string
repl (read-only borrow; caller keeps the original; type &string)

Returns

string — result string