package aho-corasick

All checked builds pass
  1. Overview
  2. Docs
Aho-Corasick multi-pattern string matching

Install

dune-project
 Dependency

Authors

Maintainers

Sources

v0.1.1.tar.gz
md5=f1d1c262b14a9ab81e6933c5cb62b545
sha512=369d9b7fe1cd2c4af1eb20739f357ed1259f05590b53c7b3e77da9138bd50155ce966a1a2a521c70c598092c4d7d788c02bc6cce97a65eda69985d2d4a132952

Description

Multi-pattern matching over byte strings in pure OCaml, with no runtime dependencies beyond the standard library. Supports overlapping search, lazy iteration, leftmost-longest selection, replacement, ASCII case folding, and chunked streaming in three match modes. Automata are immutable and reusable. Search is linear in the input plus matches examined; leftmost-longest selection uses lookahead bounded by the longest pattern.

Tags

string search aho-corasick

Added to opam-repository:

README

ocaml-aho-corasick

CI

Find many literal patterns in one pass over a byte string. Pure OCaml, with no runtime dependencies beyond the standard library.

Supports overlapping matches, lazy iteration, leftmost-longest selection, replacement, ASCII case folding, and streaming across chunk boundaries.

Install

Requires OCaml 4.14 or newer and Dune 3.14 or newer.

Until v0.1.1 is published to opam, install from this checkout:

opam install .

After publication:

opam install aho-corasick

Add (libraries aho-corasick) to your executable or library's Dune stanza.

Quick start

let matcher = Aho_corasick.build [ "he"; "she"; "his"; "hers" ]
let matches = Aho_corasick.find_all matcher "ushers"
(* she: 1..4, he: 2..4, hers: 2..6 *)

let words = Aho_corasick.build [ "cat"; "dog" ]
let replaced =
  Aho_corasick.replace_all words ~f:(fun _ -> "[pet]") "cat and dog"
(* "[pet] and [pet]" *)

Each match has a pattern index into the original pattern list, a start byte offset, and an exclusive stop byte offset. Build once and reuse the immutable matcher.

find_all and find_iter include overlaps. find_leftmost_longest and replace_all choose non-overlapping matches, preferring the longest match at the earliest position. mem stops at the first match.

Matching uses bytes, including for UTF-8. ~ignore_case:true folds ASCII letters only. Empty pattern lists are allowed; empty strings as patterns raise Invalid_argument.

Documentation

License

MIT.

Dependencies (2)

  1. ocaml >= "4.14"
  2. dune >= "3.14"

Dev Dependencies (4)

  1. odoc with-doc
  2. qcheck-alcotest with-test & >= "0.25"
  3. qcheck-core with-test & >= "0.25"
  4. alcotest with-test & >= "1.5.0"

Optional Dependencies

None

Used by

None

Conflicts

None

Build status

Results of building aho-corasick with each compiler on check.ci.ocaml.org, run of against opam-repository 78c202b. All results for this package.

Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.

Version OCaml 4.11 OCaml 4.14 OCaml 5.2 OCaml 5.4 OCaml 5.5
0.1.1 (this version) n/a good good good good
  • good Package successfully built
  • partial One of the dependencies failed to build
  • bad Package failed to build
  • n/a Package is not available in this environment
  • internal Internal failure