$ show google/re2
RE2 is a C++ regular expression library designed for safety and performance, guaranteeing linear-time matching to prevent ReDoS attacks. It provides a thread-safe, immutable API for compiling and executing regex patterns with full Unicode support. The library uses multiple matching engines (DFA, NFA, OnePass, BitState) with automatic fallback based on pattern complexity. Beyond the core C++ library, it includes Python bindings, a WebAssembly demo, and extensive test/fuzz suites. RE2 is used in production at Google and widely adopted for applications requiring reliable, high-performance regex matching.
The LLM identified 5 files worth highlighting for reuse:
Provides a lightweight, non-owning string reference similar to absl::string_view. Used throughout RE2 for efficient string handling without copying. Demonstrates encapsulation of string reference semantics and is easily reusable in any C++ project needing zero-overhead string views.
Implements a sparse array for efficient storage of data where most elements are empty/default, providing O(1) access. Used internally for Unicode property tables. The template-based design is self-contained and reusable for any sparse data scenario.
Implements a sparse set for efficient storage of sparse integer sets with O(1) insertion, deletion, and lookup. Used internally for Unicode range tracking. Like sparse_array.h, it is a generic, reusable component.
A simple, efficient array for trivially copyable (POD) types that avoids std::vector initialization overhead. Demonstrates careful memory management for performance-critical code and is easily reusable.
Provides a non-recursive walker for traversing abstract syntax trees (specifically the Regexp AST in RE2). Prevents stack overflow in deep recursion and demonstrates the visitor pattern applied to tree traversal. The pattern is reusable for any tree structure.