Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regexp: ReplaceAllFunc ReplaceAllStringFunc bad specification #6687

Closed
gopherbot opened this issue Oct 30, 2013 · 2 comments
Closed

regexp: ReplaceAllFunc ReplaceAllStringFunc bad specification #6687

gopherbot opened this issue Oct 30, 2013 · 2 comments

Comments

@gopherbot
Copy link

by itcraft.letter:

Package regexp: http://golang.org/pkg/regexp/

bad specification of functions:
--
func (re *Regexp) ReplaceAllFunc(src []byte, repl func([]byte) []byte) []byte
func (re *Regexp) ReplaceAllStringFunc(src string, repl func(string) string) string
--

correct specification of functions:
--
func (re *Regexp) ReplaceAllFunc(src []byte, repl func([][]byte) []byte) []byte
func (re *Regexp) ReplaceAllStringFunc(src string, repl func([]string) string) string
--

It is necessary to transfer in the function of the parts of regexp.
Example
reg := regexp.MustCompile(`#{(\w*)}#`)

replacer := func(partRegExp []string) string {
  //{$0} - partRegExp[0]
  //{$1} - partRegExp[1]
  // ...
}

fileSource = reg.ReplaceAllStringFunc(fileSource, replacer)
@adg
Copy link
Contributor

adg commented Oct 30, 2013

Comment 1:

What's bad about the current versions? The replacer functions are called once for each
replacement. That seems the easiest way to write it, to me.

Status changed to WorkingAsIntended.

@gopherbot
Copy link
Author

Comment 2 by itcraft.letter:

#{\w*}#
if the expression RegExp missing part the great, 
otherwis
#{(\w*)}#
because isolated parts for processing logic,
Logic replacer functions depends on part RegExp.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants