BuildOn - Step #5:   RegEx in TextSearch

 

BuildOn Project - Text Search with RegEx

Figure 1. TextFinder Packages
Figure 2. TextFinder Structs
This Step replaces simple text search in TextSearch::Finder with regular expression matches. Figure 1 is a package diagram for Textfinder, showing how its parts fit together.
TextFinder Specification

TextFinder Specification:

  1. Identify all files in a directory subtree that match a pattern and contain a specified text.
  2. Specify root path, one or more file patterns (.h, .cpp, .cs, .rs, ...), and search text on command line.
  3. Specify options /s [true|false], /v [true|false], /H [true|false] /h [true|false] for recursive directory walk, verbose output header, Hidden dirs with no match, and help message, respectively.
  4. Display file name and path, without duplication of path name, e.g., organized by directory, for files containing the search text.
  5. Interesting extensions:
    • Replace text by regular expressions for both search text and file patterns.
    • Replace sequential file searches with parallel searches to improve performance and useability.
Executive uses CmdlnParser to access the program's starting path, file patterns, search text, and options. Executive configures the CLPparser instance for TextFinder's Finder operations by defining default values of program attributes not already defined on the command line. It then creates a member instance of DirNav, providing it access to TextSearch::Finder as a generic parameter. DirNav creates an instance of TextSearch's Finder and provides access to it via a member function DirNav<App>::getApp(). This may be used to configure Finder before starting a search. It may also be used to collect results that are specific to DirNav, e.g., the number of files and directories processed. Executive uses getApp() to configure it with search text.
 

Step #5 - Replace text search with RegEx matching

In this step we replace the simple String::find in TextSearch::Finder with a RegEx match operation. This should be a relatively minor modification of Finder's processing. Rust does not have regular expression processing in its std libraries. However, there is a widely used RegEx crate in crates.io. The documentation provided has a nice set of examples and a good summary of RegEx syntax supported by the crate.
 

Step #5 References

The table below provides references relevant for Step #5 : RegEx.
 

Table 1. - Step #5 References

Topic Description Link
RegEx Regular expressions are a "little language" for specifying text to find. RegEx crate
RustBites RegEx
Strings Rust std strings come in two flavors: String and str, representing string objects and literal strings. Each contains utf-8 characters. The Rust library path also provides PathBuf, similar to String, and Path, similar to &str, but uses the encoding for paths provided by the current platform, e.g., Windows, Linux, or macOS. std::String
std::str
std::path
std::path::PathBuf std::path::Path
Rust by Example
You don't need to use all of the references in the right-most column. Just look at each quickly and use the one(s) that work(s) best for you.
 
 toggle menu