Skip to content

Commit

Permalink
syntax highlighting in example code
Browse files Browse the repository at this point in the history
  • Loading branch information
tringi authored Feb 12, 2023
1 parent daefe53 commit e8241f1
Showing 1 changed file with 34 additions and 32 deletions.
66 changes: 34 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,41 @@
## Usage
*[SearchTest.cpp](https://github.com/tringi/code-style-agnostic-search/blob/main/test/SearchTest.cpp)*

#include "agsearch.h"

struct search : public agsearch {
std::vector <std::pair <location, location>> results;

std::size_t find (std::wstring_view needle) {
this->results.clear ();
return this->agsearch::find (needle);
}

private:
bool found (std::wstring_view needle, std::size_t i, location begin, location end) override {
this->results.push_back ({ begin, end });
return true;
}
} search;

int main () {

// ...

search.parameters.whole_words = false; // configure the engine

search.load (text); // 'text' is container of std::wstring_view
search.append (line); // 'line' is single line of code std::wstring_view

// ...

search.find (needle); // 'needle' is code to be searched for
search.results; // contains pair of 'location' for every found instance

// ...
```cpp
#include "agsearch.h"

struct search : public agsearch {
std::vector <std::pair <location, location>> results;

std::size_t find (std::wstring_view needle) {
this->results.clear ();
return this->agsearch::find (needle);
}

private:
bool found (std::wstring_view needle, std::size_t i, location begin, location end) override {
this->results.push_back ({ begin, end });
return true;
}
} search;

int main () {

// ...

search.parameters.whole_words = false; // configure the engine

search.load (text); // 'text' is container of std::wstring_view
search.append (line); // 'line' is single line of code std::wstring_view

// ...

search.find (needle); // 'needle' is code to be searched for
search.results; // contains pair of 'location' for every found instance

// ...
}
```
**Notes:**
Expand Down

0 comments on commit e8241f1

Please sign in to comment.