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: syntax.wordRune() is a duplicate of syntax.IsWordChar() #21742

Closed
sylvinus opened this issue Sep 2, 2017 · 3 comments
Closed

regexp: syntax.wordRune() is a duplicate of syntax.IsWordChar() #21742

sylvinus opened this issue Sep 2, 2017 · 3 comments

Comments

@sylvinus
Copy link
Contributor

sylvinus commented Sep 2, 2017

Is there a valid reason for keeping both functions?

@gopherbot
Copy link

Change https://golang.org/cl/61034 mentions this issue: regexp: Remove duplicated function wordRune()

@odeke-em
Copy link
Member

odeke-em commented Sep 3, 2017

Hmm, there seems to be a difference, being that IsWordChar recognizes _ but wordRune doesn't, as per the code pasted below:

IsWordChar

// IsWordChar reports whether r is consider a ``word character''
// during the evaluation of the \b and \B zero-width assertions.
// These assertions are ASCII-only: the word characters are [A-Za-z0-9_].
func IsWordChar(r rune) bool {
return 'A' <= r && r <= 'Z' || 'a' <= r && r <= 'z' || '0' <= r && r <= '9' || r == '_'
}

WordRune

// As per re2's Prog::IsWordChar. Determines whether rune is an ASCII word char.
// Since we act on runes, it would be easy to support Unicode here.
func wordRune(r rune) bool {
return r == '_' ||
('A' <= r && r <= 'Z') ||
('a' <= r && r <= 'z') ||
('0' <= r && r <= '9')
}

I haven't examined the entire context of the functions but it seems like perhaps we shouldn't be removing wordRune before figuring out what cases it handles.

@odeke-em
Copy link
Member

odeke-em commented Sep 3, 2017

Oops, my biggest apologies, it is 5:25AM and I hadn't noticed that wordRune recognizes _ too, so they are the same. You have my vote now :)

@golang golang locked and limited conversation to collaborators Sep 8, 2018
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

3 participants