Rust

glob

Module

Shell glob matching: PHP's fnmatch().

PHP calls the C library's fnmatch(3). The runtimes this port is held to run on Alpine Linux, so this is musl's implementation (src/regex/fnmatch.c) in the C.UTF-8 locale PHP runs in there: characters are UTF-8 sequences, character classes are musl's Unicode tables (classes), an invalid sequence in the pattern matches nothing and one in the name only matches ? or a negated bracket, as musl reads them.

PHPRust
fnmatch($pattern, $filename) (no flags)fnmatch

Contents

use utopia_php_std::glob::fnmatch;
Rust
pub fn fnmatch(pattern: &[u8], filename: &[u8]) -> Result<bool, EngineError>

PHP fnmatch($pattern, $filename): whether filename matches the shell glob pattern (*, ?, [...] with !/^, ranges and [:class:], \ escapes; * crosses / and a leading . is not special).

A null byte in either argument is the ValueError PHP throws; an argument of 4096 bytes or more does not match (PHP warns).

Rust
use php_std::glob::fnmatch;

assert_eq!(fnmatch(b"v1.*", b"v1.2.0"), Ok(true));
assert_eq!(fnmatch(b"v?.0.0", b"v10.0.0"), Ok(false));
assert_eq!(fnmatch(b"[!a]*", b"beta"), Ok(true));