diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2013-11-06 19:49:01 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2013-11-06 19:49:01 +0000 |
commit | f038dae646bac2b31be98ab592c0e5206d2d96f5 (patch) | |
tree | 39530b071991b2326f881b2a30a2d82d6c133fd6 /libgo/go/regexp/syntax | |
parent | f20f261304993444741e0f0a14d3147e591bc660 (diff) | |
download | gcc-f038dae646bac2b31be98ab592c0e5206d2d96f5.zip gcc-f038dae646bac2b31be98ab592c0e5206d2d96f5.tar.gz gcc-f038dae646bac2b31be98ab592c0e5206d2d96f5.tar.bz2 |
libgo: Update to October 24 version of master library.
From-SVN: r204466
Diffstat (limited to 'libgo/go/regexp/syntax')
-rw-r--r-- | libgo/go/regexp/syntax/doc.go | 8 | ||||
-rw-r--r-- | libgo/go/regexp/syntax/parse.go | 2 | ||||
-rw-r--r-- | libgo/go/regexp/syntax/parse_test.go | 2 | ||||
-rw-r--r-- | libgo/go/regexp/syntax/prog.go | 29 | ||||
-rw-r--r-- | libgo/go/regexp/syntax/prog_test.go | 11 |
5 files changed, 33 insertions, 19 deletions
diff --git a/libgo/go/regexp/syntax/doc.go b/libgo/go/regexp/syntax/doc.go index bcb5d05..e52632e 100644 --- a/libgo/go/regexp/syntax/doc.go +++ b/libgo/go/regexp/syntax/doc.go @@ -64,8 +64,8 @@ Empty strings: ^ at beginning of text or line (flag m=true) $ at end of text (like \z not \Z) or line (flag m=true) \A at beginning of text - \b at word boundary (\w on one side and \W, \A, or \z on the other) - \B not a word boundary + \b at ASCII word boundary (\w on one side and \W, \A, or \z on the other) + \B not an ASCII word boundary \z at end of text Escape sequences: @@ -104,8 +104,8 @@ Perl character classes: \D not digits (== [^0-9]) \s whitespace (== [\t\n\f\r ]) \S not whitespace (== [^\t\n\f\r ]) - \w word characters (== [0-9A-Za-z_]) - \W not word characters (== [^0-9A-Za-z_]) + \w ASCII word characters (== [0-9A-Za-z_]) + \W not ASCII word characters (== [^0-9A-Za-z_]) ASCII character classes: [:alnum:] alphanumeric (== [0-9A-Za-z]) diff --git a/libgo/go/regexp/syntax/parse.go b/libgo/go/regexp/syntax/parse.go index 30e0e8b..42d0bf4 100644 --- a/libgo/go/regexp/syntax/parse.go +++ b/libgo/go/regexp/syntax/parse.go @@ -651,7 +651,7 @@ func literalRegexp(s string, flags Flags) *Regexp { // Parse parses a regular expression string s, controlled by the specified // Flags, and returns a regular expression parse tree. The syntax is -// described in the top-level comment for package regexp. +// described in the top-level comment. func Parse(s string, flags Flags) (*Regexp, error) { if flags&Literal != 0 { // Trivial parser for literal string. diff --git a/libgo/go/regexp/syntax/parse_test.go b/libgo/go/regexp/syntax/parse_test.go index 81fd9dc..269d6c3 100644 --- a/libgo/go/regexp/syntax/parse_test.go +++ b/libgo/go/regexp/syntax/parse_test.go @@ -542,7 +542,7 @@ func TestToStringEquivalentParse(t *testing.T) { // but "{" is a shorter equivalent in some contexts. nre, err := Parse(s, testFlags) if err != nil { - t.Errorf("Parse(%#q.String() = %#q): %v", tt.Regexp, t, err) + t.Errorf("Parse(%#q.String() = %#q): %v", tt.Regexp, s, err) continue } nd := dump(nre) diff --git a/libgo/go/regexp/syntax/prog.go b/libgo/go/regexp/syntax/prog.go index 902d3b3..a482a82 100644 --- a/libgo/go/regexp/syntax/prog.go +++ b/libgo/go/regexp/syntax/prog.go @@ -56,23 +56,26 @@ const ( // Passing r2 == -1 indicates that the position is // at the end of the text. func EmptyOpContext(r1, r2 rune) EmptyOp { - var op EmptyOp - if r1 < 0 { - op |= EmptyBeginText | EmptyBeginLine - } - if r1 == '\n' { + var op EmptyOp = EmptyNoWordBoundary + var boundary byte + switch { + case IsWordChar(r1): + boundary = 1 + case r1 == '\n': op |= EmptyBeginLine + case r1 < 0: + op |= EmptyBeginText | EmptyBeginLine } - if r2 < 0 { - op |= EmptyEndText | EmptyEndLine - } - if r2 == '\n' { + switch { + case IsWordChar(r2): + boundary ^= 1 + case r2 == '\n': op |= EmptyEndLine + case r2 < 0: + op |= EmptyEndText | EmptyEndLine } - if IsWordChar(r1) != IsWordChar(r2) { - op |= EmptyWordBoundary - } else { - op |= EmptyNoWordBoundary + if boundary != 0 { // IsWordChar(r1) != IsWordChar(r2) + op ^= (EmptyWordBoundary | EmptyNoWordBoundary) } return op } diff --git a/libgo/go/regexp/syntax/prog_test.go b/libgo/go/regexp/syntax/prog_test.go index 663d5a8..cd71abc 100644 --- a/libgo/go/regexp/syntax/prog_test.go +++ b/libgo/go/regexp/syntax/prog_test.go @@ -103,3 +103,14 @@ func TestCompile(t *testing.T) { } } } + +func BenchmarkEmptyOpContext(b *testing.B) { + for i := 0; i < b.N; i++ { + var r1 rune = -1 + for _, r2 := range "foo, bar, baz\nsome input text.\n" { + EmptyOpContext(r1, r2) + r1 = r2 + } + EmptyOpContext(r1, -1) + } +} |