Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4)

Side by Side Diff: src/regexp/regexp.go

Issue 152570049: [dev.power64] code review 152570049: all: merge default into dev.power64 (Closed)
Patch Set: diff -r 36f7fc9495481ed67a159eea0eb2fac35b7c46a5 https://code.google.com/p/go Created 10 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/regexp/all_test.go ('k') | src/regexp/syntax/doc.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // Package regexp implements regular expression search. 5 // Package regexp implements regular expression search.
6 // 6 //
7 // The syntax of the regular expressions accepted is the same 7 // The syntax of the regular expressions accepted is the same
8 // general syntax used by Perl, Python, and other languages. 8 // general syntax used by Perl, Python, and other languages.
9 // More precisely, it is the syntax accepted by RE2 and described at 9 // More precisely, it is the syntax accepted by RE2 and described at
10 // http://code.google.com/p/re2/wiki/Syntax, except for \C. 10 // http://code.google.com/p/re2/wiki/Syntax, except for \C.
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 n := 2 445 n := 2
446 if strings.Index(repl, "$") >= 0 { 446 if strings.Index(repl, "$") >= 0 {
447 n = 2 * (re.numSubexp + 1) 447 n = 2 * (re.numSubexp + 1)
448 } 448 }
449 b := re.replaceAll(nil, src, n, func(dst []byte, match []int) []byte { 449 b := re.replaceAll(nil, src, n, func(dst []byte, match []int) []byte {
450 return re.expand(dst, repl, nil, src, match) 450 return re.expand(dst, repl, nil, src, match)
451 }) 451 })
452 return string(b) 452 return string(b)
453 } 453 }
454 454
455 // ReplaceAllStringLiteral returns a copy of src, replacing matches of the Regex p 455 // ReplaceAllLiteralString returns a copy of src, replacing matches of the Regex p
456 // with the replacement string repl. The replacement repl is substituted direct ly, 456 // with the replacement string repl. The replacement repl is substituted direct ly,
457 // without using Expand. 457 // without using Expand.
458 func (re *Regexp) ReplaceAllLiteralString(src, repl string) string { 458 func (re *Regexp) ReplaceAllLiteralString(src, repl string) string {
459 return string(re.replaceAll(nil, src, 2, func(dst []byte, match []int) [ ]byte { 459 return string(re.replaceAll(nil, src, 2, func(dst []byte, match []int) [ ]byte {
460 return append(dst, repl...) 460 return append(dst, repl...)
461 })) 461 }))
462 } 462 }
463 463
464 // ReplaceAllStringFunc returns a copy of src in which all matches of the 464 // ReplaceAllStringFunc returns a copy of src in which all matches of the
465 // Regexp have been replaced by the return value of function repl applied 465 // Regexp have been replaced by the return value of function repl applied
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 } 1111 }
1112 beg = match[1] 1112 beg = match[1]
1113 } 1113 }
1114 1114
1115 if end != len(s) { 1115 if end != len(s) {
1116 strings = append(strings, s[beg:]) 1116 strings = append(strings, s[beg:])
1117 } 1117 }
1118 1118
1119 return strings 1119 return strings
1120 } 1120 }
OLDNEW
« no previous file with comments | « src/regexp/all_test.go ('k') | src/regexp/syntax/doc.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b