Skip to content

Commit

Permalink
New methods in builder pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
MaestroError committed Dec 28, 2024
1 parent f4cf947 commit ed11ecb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Patterns/BuilderPattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ public function count(): int {
public function toRegex(): string {
return $this->builder->toRegex();
}

public function replace(callable $replaceFunction): string {
return $this->builder->replace($replaceFunction);
}

public function search(string|callable $keywordOrPattern): mixed {
return $this->builder->search($keywordOrPattern);
}

public function searchReverse(string|callable $keywordOrPattern): mixed {
return $this->builder->searchReverse($keywordOrPattern);
}

public function swap(string|callable $stringOrCallback): mixed {
return $this->builder->swap($stringOrCallback);
}

// Builder class implementation methods END

Expand Down
11 changes: 11 additions & 0 deletions tests/Feature/EloquentRegexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,17 @@
expect($replaced)->toBe("Send to EXAMPLE-1@EMAIL.COM or replay to EXAMPLE-2@EMAIL.COM");
});


it('Replaces hashtags with anchors', function () {
$replaced = EloquentRegex::start("This is a #test to wrap hashtags in #anchor tag")
->hash()->text()
->replace(function($foundItem) {
return "<a href='$foundItem'>" . $foundItem . "</a>";
});

expect($replaced)->toBe("This is a <a href='#test'>#test</a> to wrap hashtags in <a href='#anchor'>#anchor</a> tag");
});

// Search feature tests:

it('searches multiline string using keyword', function () {
Expand Down

0 comments on commit ed11ecb

Please sign in to comment.