Skip to content

Commit

Permalink
feat: README
Browse files Browse the repository at this point in the history
  • Loading branch information
anhoderai committed Sep 4, 2021
1 parent 7f04206 commit 5b8ca9e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
PHP实现的Boyer-Moore字符搜索算法,支持中文。
PHP implementation of Boyer-Moore character search algorithm, support for Chinese.

![GitHub repo size](https://img.shields.io/github/repo-size/anhoder/) ![GitHub](https://img.shields.io/github/license/anhoder/go-musicfox) ![Last Tag](https://badgen.net/github/tag/anhoder/go-musicfox) ![GitHub last commit](https://badgen.net/github/last-commit/anhoder/go-musicfox) ![GitHub All Releases](https://img.shields.io/github/downloads/anhoder/go-musicfox/total)

![GitHub stars](https://img.shields.io/github/stars/anhoder/go-musicfox?style=social) ![GitHub forks](https://img.shields.io/github/forks/anhoder/go-musicfox?style=social)

## Requirement

```php
"symfony/polyfill-mbstring": "^1.23"
```

## Install

```shell
composer require anhoder/boyer-moore
```

## Usage

```php
require './vendor/autoload.php';

$text = 'ababa';
$matcher = new \Anhoder\Matcher\BoyerMooreMatcher('aba');
$res = $matcher->match($text, \Anhoder\Matcher\BoyerMooreMatcher::MODE_REUSE_MATCHED);
var_dump($res);
```

* `BoyerMooreMatcher::MODE_ONLY_ONE`: 匹配到一个就返回
* `BoyerMooreMatcher::MODE_SKIP_MATCHED`: 找出所有匹配的字串,已匹配的字符不参与后续匹配,例如:在`ababa`中搜索`aba`结果为`[0]`
* `BoyerMooreMatcher::MODE_SKIP_MATCHED`: 找出所有匹配的字串,已匹配字符继续参与匹配,例如:在`ababa`中搜索`aba`结果为`[0, 2]`

8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
"name": "anhoder/boyer-moore",
"description": "Boyer-Moore algorithm in PHP(support Chinese).",
"type": "library",
"keywords": [
"Boyer-Moore",
"string match",
"Chinese",
"Unicode"
],
"require": {
"symfony/polyfill-mbstring": "^1.23"
},
Expand All @@ -11,7 +17,7 @@
"license": "MIT",
"autoload": {
"psr-4": {
"Anhoder\\BoyerMoore\\": "src/"
"Anhoder\\Matcher\\": "src/"
}
},
"authors": [
Expand Down
2 changes: 1 addition & 1 deletion src/BoyerMooreMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* 2021/9/4 12:47 上午
*/

namespace Anhoder\BoyerMoore;
namespace Anhoder\Matcher;

use RuntimeException;

Expand Down
2 changes: 1 addition & 1 deletion tests/BoyerMooreMatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* 2021/9/4 12:59 上午
*/

use Anhoder\BoyerMoore\BoyerMooreMatcher;
use Anhoder\Matcher\BoyerMooreMatcher;
use PHPUnit\Framework\TestCase;

class BoyerMooreMatcherTest extends TestCase
Expand Down

0 comments on commit 5b8ca9e

Please sign in to comment.