Function in string compiler

match_at

fn match_at(string s, string needle, int at) -> bool
Import
use string::{match_at};
Source: compiler/src/builtin_docs/string.hy

Returns whether needle occurs in s starting exactly at byte offset at.

false when at is negative or the match would run past the end. An empty needle matches at any offset in 0..=s.len().

Parameters#

NameType
sstring
needlestring
atint

Returns#

bool

Examples#

use string::{match_at};
use tests::assert;
assert!(match_at("key=value", "=", 3));
assert!(!match_at("key=value", "=", 2));
assert!(!match_at("ab", "abc", 0));

See also#

  • byte_at: Returns the byte at byte offset i of s, or -1 when i is out of range.
  • find_from: Returns the byte offset of the first needle in hay at or after start, or -1.
  • format: Builds a string from the literal fmt and the arguments that follow it.
  • from_bytes: Decodes bytes as UTF-8 text.
  • rfind: Returns the byte offset of the last needle in hay, or -1.
  • slice_bytes: Returns the part of s between byte offsets start (inclusive) and end (exclusive).
  • to_bytes: Encodes s as UTF-8 into a new Vec<byte>.
↑ ↓ navigate ↵ open