Make study a negatable option instead

This commit is contained in:
Flaviu Tamas
2015-01-18 12:49:22 -05:00
parent a80617fd4c
commit ca299504d1
3 changed files with 7 additions and 8 deletions

View File

@@ -109,7 +109,7 @@ as a key.
Represents the pattern that things are matched against, constructed with
`initRegex(string)` or `re(string)`. Examples: `re"foo"`, `re(r"foo # comment",
"Sx<anycrlf>")`.
"x<anycrlf>")`.
`pattern: string` :: the string that was used to create the pattern.
`captureCount: int` :: the number of captures that the pattern has.
@@ -127,8 +127,6 @@ Represents the pattern that things are matched against, constructed with
subject string
- `N` - turn off auto-capture, `(?foo)` is necessary to capture.
- `s` - `.` matches newline
- `S` - study the pattern to hopefully improve performance. JIT is unspported at
the moment.
- `U` - expressions are not greedy by default. `?` can be added to a qualifier
to make it greedy.
- `u` - same as `8`
@@ -152,3 +150,4 @@ ____
- `<bsr_anycrlf>` - `\R` matches CR, LF, or CRLF
- `<bsr_unicode>` - `\R` matches any unicode newline
- `<js>` - Javascript compatibility
- `<no_study>` - turn off studying; study is enabled by deafault

View File

@@ -4,12 +4,12 @@ include nre
suite "find":
test "find text":
check("3213a".find(initRegex(r"[a-z]")).match == "a")
check("1 2 3 4 5 6 7 8 ".findAll(initRegex(r" ", "S")).map(
check("1 2 3 4 5 6 7 8 ".findAll(re" ").map(
proc (a: RegexMatch): string = a.match
) == @[" ", " ", " ", " ", " ", " ", " ", " "])
test "find bounds":
check("1 2 3 4 5 ".findAll(initRegex(r" ", "S")).map(
check("1 2 3 4 5 ".findAll(re" ")).map(
proc (a: RegexMatch): Slice[int] = a.matchBounds
) == @[1..2, 3..4, 5..6, 7..8, 9..10])

View File

@@ -4,9 +4,9 @@ include nre
suite "string splitting":
test "splitting strings":
check("12345".split(initRegex("")) == @["1", "2", "3", "4", "5"])
check("1 2 3 4 5 6 ".split(initRegex(" ", "S")) == @["1", "2", "3", "4", "5", "6", ""])
check("1 2 ".split(initRegex(" ", "S")) == @["1", "", "2", "", ""])
check("1 2".split(initRegex(" ", "S")) == @["1", "2"])
check("1 2 3 4 5 6 ".split(re" ") == @["1", "2", "3", "4", "5", "6", ""])
check("1 2 ".split(initRegex(" ")) == @["1", "", "2", "", ""])
check("1 2".split(initRegex(" ")) == @["1", "2"])
check("foo".split(initRegex("foo")) == @["", ""])
test "captured patterns":