diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-11-21 07:03:38 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-11-21 07:03:38 +0000 |
commit | fabcaa8df3d6eb852b87821ef090d31d222870b7 (patch) | |
tree | 72455aea0286937aa08cc141e5efc800e4626577 /libgo/go/regexp | |
parent | a51fb17f48428e7cfc96a72a9f9f87901363bb6b (diff) | |
download | gcc-fabcaa8df3d6eb852b87821ef090d31d222870b7.zip gcc-fabcaa8df3d6eb852b87821ef090d31d222870b7.tar.gz gcc-fabcaa8df3d6eb852b87821ef090d31d222870b7.tar.bz2 |
libgo: Update to current version of master library.
From-SVN: r193688
Diffstat (limited to 'libgo/go/regexp')
-rw-r--r-- | libgo/go/regexp/example_test.go | 22 | ||||
-rw-r--r-- | libgo/go/regexp/exec_test.go | 16 | ||||
-rw-r--r-- | libgo/go/regexp/regexp.go | 6 | ||||
-rw-r--r-- | libgo/go/regexp/syntax/compile.go | 4 | ||||
-rw-r--r-- | libgo/go/regexp/syntax/parse.go | 2 |
5 files changed, 36 insertions, 14 deletions
diff --git a/libgo/go/regexp/example_test.go b/libgo/go/regexp/example_test.go new file mode 100644 index 0000000..aa92e0b --- /dev/null +++ b/libgo/go/regexp/example_test.go @@ -0,0 +1,22 @@ +package regexp_test + +import ( + "fmt" + "regexp" +) + +func Example() { + // Compile the expression once, usually at init time. + // Use raw strings to avoid having to quote the backslashes. + var validID = regexp.MustCompile(`^[a-z]+\[[0-9]+\]$`) + + fmt.Println(validID.MatchString("adam[23]")) + fmt.Println(validID.MatchString("eve[7]")) + fmt.Println(validID.MatchString("Job[48]")) + fmt.Println(validID.MatchString("snakey")) + // Output: + // true + // true + // false + // false +} diff --git a/libgo/go/regexp/exec_test.go b/libgo/go/regexp/exec_test.go index a84bedc..f89027a 100644 --- a/libgo/go/regexp/exec_test.go +++ b/libgo/go/regexp/exec_test.go @@ -407,14 +407,14 @@ Reading: // implementation. If the first character is not [BEASKLP] then the // specification is a global control line. One or more of [BEASKLP] may be // specified; the test will be repeated for each mode. - // + // // B basic BRE (grep, ed, sed) // E REG_EXTENDED ERE (egrep) // A REG_AUGMENTED ARE (egrep with negation) // S REG_SHELL SRE (sh glob) // K REG_SHELL|REG_AUGMENTED KRE (ksh glob) // L REG_LITERAL LRE (fgrep) - // + // // a REG_LEFT|REG_RIGHT implicit ^...$ // b REG_NOTBOL lhs does not match ^ // c REG_COMMENT ignore space and #...\n @@ -444,23 +444,23 @@ Reading: // $ expand C \c escapes in fields 2 and 3 // / field 2 is a regsubcomp() expression // = field 3 is a regdecomp() expression - // + // // Field 1 control lines: - // + // // C set LC_COLLATE and LC_CTYPE to locale in field 2 - // + // // ?test ... output field 5 if passed and != EXPECTED, silent otherwise // &test ... output field 5 if current and previous passed // |test ... output field 5 if current passed and previous failed // ; ... output field 2 if previous failed // {test ... skip if failed until } // } end of skip - // + // // : comment comment copied as output NOTE // :comment:test :comment: ignored // N[OTE] comment comment copied as output NOTE // T[EST] comment comment - // + // // number use number for nmatch (20 by default) flag := field[0] switch flag[0] { @@ -503,7 +503,7 @@ Reading: // Field 2: the regular expression pattern; SAME uses the pattern from // the previous specification. - // + // if field[1] == "SAME" { field[1] = lastRegexp } diff --git a/libgo/go/regexp/regexp.go b/libgo/go/regexp/regexp.go index e4896a1..2a1ae56 100644 --- a/libgo/go/regexp/regexp.go +++ b/libgo/go/regexp/regexp.go @@ -720,7 +720,7 @@ func (re *Regexp) FindSubmatch(b []byte) [][]byte { // append, Expand replaces variables in the template with corresponding // matches drawn from src. The match slice should have been returned by // FindSubmatchIndex. -// +// // In the template, a variable is denoted by a substring of the form // $name or ${name}, where name is a non-empty sequence of letters, // digits, and underscores. A purely numeric name like $1 refers to @@ -728,10 +728,10 @@ func (re *Regexp) FindSubmatch(b []byte) [][]byte { // capturing parentheses named with the (?P<name>...) syntax. A // reference to an out of range or unmatched index or a name that is not // present in the regular expression is replaced with an empty slice. -// +// // In the $name form, name is taken to be as long as possible: $1x is // equivalent to ${1x}, not ${1}x, and, $10 is equivalent to ${10}, not ${1}0. -// +// // To insert a literal $ in the output, use $$ in the template. func (re *Regexp) Expand(dst []byte, template []byte, src []byte, match []int) []byte { return re.expand(dst, string(template), src, "", match) diff --git a/libgo/go/regexp/syntax/compile.go b/libgo/go/regexp/syntax/compile.go index 41955bf..95f6f15 100644 --- a/libgo/go/regexp/syntax/compile.go +++ b/libgo/go/regexp/syntax/compile.go @@ -10,10 +10,10 @@ import "unicode" // Because the pointers haven't been filled in yet, we can reuse their storage // to hold the list. It's kind of sleazy, but works well in practice. // See http://swtch.com/~rsc/regexp/regexp1.html for inspiration. -// +// // These aren't really pointers: they're integers, so we can reinterpret them // this way without using package unsafe. A value l denotes -// p.inst[l>>1].Out (l&1==0) or .Arg (l&1==1). +// p.inst[l>>1].Out (l&1==0) or .Arg (l&1==1). // l == 0 denotes the empty list, okay because we start every program // with a fail instruction, so we'll never want to point at its output link. type patchList uint32 diff --git a/libgo/go/regexp/syntax/parse.go b/libgo/go/regexp/syntax/parse.go index 4088dba..0bf5799 100644 --- a/libgo/go/regexp/syntax/parse.go +++ b/libgo/go/regexp/syntax/parse.go @@ -466,7 +466,7 @@ func (p *parser) factor(sub []*Regexp, flags Flags) []*Regexp { // Construct factored form: prefix(suffix1|suffix2|...) prefix := first for j := start; j < i; j++ { - reuse := j != start // prefix came from sub[start] + reuse := j != start // prefix came from sub[start] sub[j] = p.removeLeadingRegexp(sub[j], reuse) } suffix := p.collapse(sub[start:i], OpAlternate) // recurse |