lisette-stdlib 0.1.21

Little language inspired by Rust that compiles to Go
Documentation
// Generated by Lisette bindgen
// Source: regexp (Go stdlib)
// Go: 1.25.5
// Lisette: 0.1.20

import "go:io"

pub fn Compile(expr: string) -> Result<Ref<Regexp>, error>

pub fn CompilePOSIX(expr: string) -> Result<Ref<Regexp>, error>

/// Match reports whether the byte slice b
/// contains any match of the regular expression pattern.
/// More complicated queries need to use [Compile] and the full [Regexp] interface.
pub fn Match(pattern: string, b: Slice<uint8>) -> Result<bool, error>

/// MatchReader reports whether the text returned by the [io.RuneReader]
/// contains any match of the regular expression pattern.
/// More complicated queries need to use [Compile] and the full [Regexp] interface.
pub fn MatchReader(pattern: string, r: io.RuneReader) -> Result<bool, error>

/// MatchString reports whether the string s
/// contains any match of the regular expression pattern.
/// More complicated queries need to use [Compile] and the full [Regexp] interface.
pub fn MatchString(pattern: string, s: string) -> Result<bool, error>

pub fn MustCompile(str: string) -> Ref<Regexp>

pub fn MustCompilePOSIX(str: string) -> Ref<Regexp>

/// QuoteMeta returns a string that escapes all regular expression metacharacters
/// inside the argument text; the returned string is a regular expression matching
/// the literal text.
pub fn QuoteMeta(s: string) -> string

/// Regexp is the representation of a compiled regular expression.
/// A Regexp is safe for concurrent use by multiple goroutines,
/// except for configuration methods, such as [Regexp.Longest].
pub type Regexp

impl Regexp {
  /// AppendText implements [encoding.TextAppender]. The output
  /// matches that of calling the [Regexp.String] method.
  /// 
  /// Note that the output is lossy in some cases: This method does not indicate
  /// POSIX regular expressions (i.e. those compiled by calling [CompilePOSIX]), or
  /// those for which the [Regexp.Longest] method has been called.
  fn AppendText(self: Ref<Regexp>, mut b: Slice<uint8>) -> Result<Slice<uint8>, error>

  /// Copy returns a new [Regexp] object copied from re.
  /// Calling [Regexp.Longest] on one copy does not affect another.
  /// 
  /// Deprecated: In earlier releases, when using a [Regexp] in multiple goroutines,
  /// giving each goroutine its own copy helped to avoid lock contention.
  /// As of Go 1.12, using Copy is no longer necessary to avoid lock contention.
  /// Copy may still be appropriate if the reason for its use is to make
  /// two copies with different [Regexp.Longest] settings.
  fn Copy(self: Ref<Regexp>) -> Ref<Regexp>

  /// Expand appends template to dst and returns the result; during the
  /// append, Expand replaces variables in the template with corresponding
  /// matches drawn from src. The match slice should have been returned by
  /// [Regexp.FindSubmatchIndex].
  /// 
  /// In the template, a variable is denoted by a substring of the form
  /// $name or ${name}, where name is a non-empty sequence of letters,
  /// digits, and underscores. A purely numeric name like $1 refers to
  /// the submatch with the corresponding index; other names refer to
  /// capturing parentheses named with the (?P<name>...) syntax. A
  /// reference to an out of range or unmatched index or a name that is not
  /// present in the regular expression is replaced with an empty slice.
  /// 
  /// In the $name form, name is taken to be as long as possible: $1x is
  /// equivalent to ${1x}, not ${1}x, and, $10 is equivalent to ${10}, not ${1}0.
  /// 
  /// To insert a literal $ in the output, use $$ in the template.
  fn Expand(
    self: Ref<Regexp>,
    mut dst: Slice<uint8>,
    template: Slice<uint8>,
    src: Slice<uint8>,
    match_: Slice<int>,
  ) -> Slice<uint8>

  /// ExpandString is like [Regexp.Expand] but the template and source are strings.
  /// It appends to and returns a byte slice in order to give the calling
  /// code control over allocation.
  fn ExpandString(
    self: Ref<Regexp>,
    mut dst: Slice<uint8>,
    template: string,
    src: string,
    match_: Slice<int>,
  ) -> Slice<uint8>

  /// Find returns a slice holding the text of the leftmost match in b of the regular expression.
  /// A return value of nil indicates no match.
  fn Find(self: Ref<Regexp>, b: Slice<uint8>) -> Slice<uint8>

  /// FindAll is the 'All' version of [Regexp.Find]; it returns a slice of all successive
  /// matches of the expression, as defined by the 'All' description in the
  /// package comment.
  /// A return value of nil indicates no match.
  fn FindAll(self: Ref<Regexp>, b: Slice<uint8>, n: int) -> Slice<Slice<uint8>>

  /// FindAllIndex is the 'All' version of [Regexp.FindIndex]; it returns a slice of all
  /// successive matches of the expression, as defined by the 'All' description
  /// in the package comment.
  /// A return value of nil indicates no match.
  fn FindAllIndex(self: Ref<Regexp>, b: Slice<uint8>, n: int) -> Slice<Slice<int>>

  /// FindAllString is the 'All' version of [Regexp.FindString]; it returns a slice of all
  /// successive matches of the expression, as defined by the 'All' description
  /// in the package comment.
  /// A return value of nil indicates no match.
  fn FindAllString(self: Ref<Regexp>, s: string, n: int) -> Slice<string>

  /// FindAllStringIndex is the 'All' version of [Regexp.FindStringIndex]; it returns a
  /// slice of all successive matches of the expression, as defined by the 'All'
  /// description in the package comment.
  /// A return value of nil indicates no match.
  fn FindAllStringIndex(self: Ref<Regexp>, s: string, n: int) -> Slice<Slice<int>>

  /// FindAllStringSubmatch is the 'All' version of [Regexp.FindStringSubmatch]; it
  /// returns a slice of all successive matches of the expression, as defined by
  /// the 'All' description in the package comment.
  /// A return value of nil indicates no match.
  fn FindAllStringSubmatch(self: Ref<Regexp>, s: string, n: int) -> Slice<Slice<string>>

  /// FindAllStringSubmatchIndex is the 'All' version of
  /// [Regexp.FindStringSubmatchIndex]; it returns a slice of all successive matches of
  /// the expression, as defined by the 'All' description in the package
  /// comment.
  /// A return value of nil indicates no match.
  fn FindAllStringSubmatchIndex(self: Ref<Regexp>, s: string, n: int) -> Slice<Slice<int>>

  /// FindAllSubmatch is the 'All' version of [Regexp.FindSubmatch]; it returns a slice
  /// of all successive matches of the expression, as defined by the 'All'
  /// description in the package comment.
  /// A return value of nil indicates no match.
  fn FindAllSubmatch(self: Ref<Regexp>, b: Slice<uint8>, n: int) -> Slice<Slice<Slice<uint8>>>

  /// FindAllSubmatchIndex is the 'All' version of [Regexp.FindSubmatchIndex]; it returns
  /// a slice of all successive matches of the expression, as defined by the
  /// 'All' description in the package comment.
  /// A return value of nil indicates no match.
  fn FindAllSubmatchIndex(self: Ref<Regexp>, b: Slice<uint8>, n: int) -> Slice<Slice<int>>

  /// FindIndex returns a two-element slice of integers defining the location of
  /// the leftmost match in b of the regular expression. The match itself is at
  /// b[loc[0]:loc[1]].
  /// A return value of nil indicates no match.
  fn FindIndex(self: Ref<Regexp>, b: Slice<uint8>) -> Slice<int>

  /// FindReaderIndex returns a two-element slice of integers defining the
  /// location of the leftmost match of the regular expression in text read from
  /// the [io.RuneReader]. The match text was found in the input stream at
  /// byte offset loc[0] through loc[1]-1.
  /// A return value of nil indicates no match.
  fn FindReaderIndex(self: Ref<Regexp>, r: io.RuneReader) -> Slice<int>

  /// FindReaderSubmatchIndex returns a slice holding the index pairs
  /// identifying the leftmost match of the regular expression of text read by
  /// the [io.RuneReader], and the matches, if any, of its subexpressions, as defined
  /// by the 'Submatch' and 'Index' descriptions in the package comment. A
  /// return value of nil indicates no match.
  fn FindReaderSubmatchIndex(self: Ref<Regexp>, r: io.RuneReader) -> Slice<int>

  /// FindString returns a string holding the text of the leftmost match in s of the regular
  /// expression. If there is no match, the return value is an empty string,
  /// but it will also be empty if the regular expression successfully matches
  /// an empty string. Use [Regexp.FindStringIndex] or [Regexp.FindStringSubmatch] if it is
  /// necessary to distinguish these cases.
  fn FindString(self: Ref<Regexp>, s: string) -> string

  /// FindStringIndex returns a two-element slice of integers defining the
  /// location of the leftmost match in s of the regular expression. The match
  /// itself is at s[loc[0]:loc[1]].
  /// A return value of nil indicates no match.
  fn FindStringIndex(self: Ref<Regexp>, s: string) -> Slice<int>

  /// FindStringSubmatch returns a slice of strings holding the text of the
  /// leftmost match of the regular expression in s and the matches, if any, of
  /// its subexpressions, as defined by the 'Submatch' description in the
  /// package comment.
  /// A return value of nil indicates no match.
  fn FindStringSubmatch(self: Ref<Regexp>, s: string) -> Slice<string>

  /// FindStringSubmatchIndex returns a slice holding the index pairs
  /// identifying the leftmost match of the regular expression in s and the
  /// matches, if any, of its subexpressions, as defined by the 'Submatch' and
  /// 'Index' descriptions in the package comment.
  /// A return value of nil indicates no match.
  fn FindStringSubmatchIndex(self: Ref<Regexp>, s: string) -> Slice<int>

  /// FindSubmatch returns a slice of slices holding the text of the leftmost
  /// match of the regular expression in b and the matches, if any, of its
  /// subexpressions, as defined by the 'Submatch' descriptions in the package
  /// comment.
  /// A return value of nil indicates no match.
  fn FindSubmatch(self: Ref<Regexp>, b: Slice<uint8>) -> Slice<Slice<uint8>>

  /// FindSubmatchIndex returns a slice holding the index pairs identifying the
  /// leftmost match of the regular expression in b and the matches, if any, of
  /// its subexpressions, as defined by the 'Submatch' and 'Index' descriptions
  /// in the package comment.
  /// A return value of nil indicates no match.
  fn FindSubmatchIndex(self: Ref<Regexp>, b: Slice<uint8>) -> Slice<int>

  /// LiteralPrefix returns a literal string that must begin any match
  /// of the regular expression re. It returns the boolean true if the
  /// literal string comprises the entire regular expression.
  fn LiteralPrefix(self: Ref<Regexp>) -> (string, bool)

  /// Longest makes future searches prefer the leftmost-longest match.
  /// That is, when matching against text, the regexp returns a match that
  /// begins as early as possible in the input (leftmost), and among those
  /// it chooses a match that is as long as possible.
  /// This method modifies the [Regexp] and may not be called concurrently
  /// with any other methods.
  fn Longest(self: Ref<Regexp>)

  /// MarshalText implements [encoding.TextMarshaler]. The output
  /// matches that of calling the [Regexp.AppendText] method.
  /// 
  /// See [Regexp.AppendText] for more information.
  fn MarshalText(self: Ref<Regexp>) -> Result<Slice<uint8>, error>

  /// Match reports whether the byte slice b
  /// contains any match of the regular expression re.
  fn Match(self: Ref<Regexp>, b: Slice<uint8>) -> bool

  /// MatchReader reports whether the text returned by the [io.RuneReader]
  /// contains any match of the regular expression re.
  fn MatchReader(self: Ref<Regexp>, r: io.RuneReader) -> bool

  /// MatchString reports whether the string s
  /// contains any match of the regular expression re.
  fn MatchString(self: Ref<Regexp>, s: string) -> bool

  /// NumSubexp returns the number of parenthesized subexpressions in this [Regexp].
  fn NumSubexp(self: Ref<Regexp>) -> int

  /// ReplaceAll returns a copy of src, replacing matches of the [Regexp]
  /// with the replacement text repl.
  /// Inside repl, $ signs are interpreted as in [Regexp.Expand].
  fn ReplaceAll(self: Ref<Regexp>, src: Slice<uint8>, repl: Slice<uint8>) -> Slice<uint8>

  /// ReplaceAllFunc returns a copy of src in which all matches of the
  /// [Regexp] have been replaced by the return value of function repl applied
  /// to the matched byte slice. The replacement returned by repl is substituted
  /// directly, without using [Regexp.Expand].
  fn ReplaceAllFunc(
    self: Ref<Regexp>,
    src: Slice<uint8>,
    repl: fn(Slice<uint8>) -> Slice<uint8>,
  ) -> Slice<uint8>

  /// ReplaceAllLiteral returns a copy of src, replacing matches of the [Regexp]
  /// with the replacement bytes repl. The replacement repl is substituted directly,
  /// without using [Regexp.Expand].
  fn ReplaceAllLiteral(self: Ref<Regexp>, src: Slice<uint8>, repl: Slice<uint8>) -> Slice<uint8>

  /// ReplaceAllLiteralString returns a copy of src, replacing matches of the [Regexp]
  /// with the replacement string repl. The replacement repl is substituted directly,
  /// without using [Regexp.Expand].
  fn ReplaceAllLiteralString(self: Ref<Regexp>, src: string, repl: string) -> string

  /// ReplaceAllString returns a copy of src, replacing matches of the [Regexp]
  /// with the replacement string repl.
  /// Inside repl, $ signs are interpreted as in [Regexp.Expand].
  fn ReplaceAllString(self: Ref<Regexp>, src: string, repl: string) -> string

  /// ReplaceAllStringFunc returns a copy of src in which all matches of the
  /// [Regexp] have been replaced by the return value of function repl applied
  /// to the matched substring. The replacement returned by repl is substituted
  /// directly, without using [Regexp.Expand].
  fn ReplaceAllStringFunc(
    self: Ref<Regexp>,
    src: string,
    repl: fn(string) -> string,
  ) -> string

  /// Split slices s into substrings separated by the expression and returns a slice of
  /// the substrings between those expression matches.
  /// 
  /// The slice returned by this method consists of all the substrings of s
  /// not contained in the slice returned by [Regexp.FindAllString]. When called on an expression
  /// that contains no metacharacters, it is equivalent to [strings.SplitN].
  /// 
  /// Example:
  /// 
  /// 	s := regexp.MustCompile("a*").Split("abaabaccadaaae", 5)
  /// 	// s: ["", "b", "b", "c", "cadaaae"]
  /// 
  /// The count determines the number of substrings to return:
  ///   - n > 0: at most n substrings; the last substring will be the unsplit remainder;
  ///   - n == 0: the result is nil (zero substrings);
  ///   - n < 0: all substrings.
  fn Split(self: Ref<Regexp>, s: string, n: int) -> Slice<string>

  /// String returns the source text used to compile the regular expression.
  fn String(self: Ref<Regexp>) -> string

  /// SubexpIndex returns the index of the first subexpression with the given name,
  /// or -1 if there is no subexpression with that name.
  /// 
  /// Note that multiple subexpressions can be written using the same name, as in
  /// (?P<bob>a+)(?P<bob>b+), which declares two subexpressions named "bob".
  /// In this case, SubexpIndex returns the index of the leftmost such subexpression
  /// in the regular expression.
  fn SubexpIndex(self: Ref<Regexp>, name: string) -> int

  /// SubexpNames returns the names of the parenthesized subexpressions
  /// in this [Regexp]. The name for the first sub-expression is names[1],
  /// so that if m is a match slice, the name for m[i] is SubexpNames()[i].
  /// Since the Regexp as a whole cannot be named, names[0] is always
  /// the empty string. The slice should not be modified.
  fn SubexpNames(self: Ref<Regexp>) -> Slice<string>

  /// UnmarshalText implements [encoding.TextUnmarshaler] by calling
  /// [Compile] on the encoded value.
  fn UnmarshalText(self: Ref<Regexp>, text: Slice<uint8>) -> Result<(), error>
}