mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
regexp: add HasMeta and regexp.Expr().
The former is a boolean function to test whether a string contains a regular expression metacharacter; the second returns the string used to compile the regexp. R=gri, rsc CC=golang-dev https://golang.org/cl/3728041
This commit is contained in:
parent
be45ba712b
commit
5bd4094d2e
3 changed files with 34 additions and 1 deletions
|
|
@ -269,6 +269,18 @@ func TestQuoteMeta(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestHasMeta(t *testing.T) {
|
||||
for _, tc := range quoteMetaTests {
|
||||
// HasMeta should be false if QuoteMeta returns the original string;
|
||||
// true otherwise.
|
||||
quoted := QuoteMeta(tc.pattern)
|
||||
if HasMeta(tc.pattern) != (quoted != tc.pattern) {
|
||||
t.Errorf("HasMeta(`%s`) = %t; want %t",
|
||||
tc.pattern, HasMeta(tc.pattern), quoted != tc.pattern)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type numSubexpCase struct {
|
||||
input string
|
||||
expected int
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue