You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// HasAnyOfSuffixes returns an indication if the given string has any of the given suffixes.
func HasAnyOfSuffixes(input string, suffixes ...string) bool {
for _, suffix := range suffixes {
if HasSuffix(input, suffix) {
return true
}
}
return false
}
// HasAnyOfPrefixes returns an indication if the given string has any of the given prefixes.
func HasAnyOfPrefixes(input string, prefixes ...string) bool {
for _, prefix := range prefixes {
if HasPrefix(input, prefix) {
return true
}
}
return false
}
The text was updated successfully, but these errors were encountered:
I could imagine having this in the standard library if it were capable of matching all of the prefixes together in a single pass, but that sort of thing tends to require precomputing a data structure such as a state machine, and the standard library already has regexp for doing that.
It might be interesting to extend that package to have a different frontend that accepts a set of static strings instead of a regexp pattern and compiles it in the same way as a foo|bar|baz-style pattern without having to build the regexp pattern string first, but in most cases where I've needed something like that it's not been a big deal to construct a regexp string and parse it during init, since I'm typically more concerned about the matching performance at runtime than the one-time init cost. 🤔
Proposal Details
The text was updated successfully, but these errors were encountered: