Avoid API break

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
This commit is contained in:
Cyril Tovena 2021-10-07 14:00:16 +02:00
parent f7f80a3abf
commit 2d879c65fc
No known key found for this signature in database
GPG key ID: FD8F768F9D633FB6
2 changed files with 12 additions and 1 deletions

View file

@ -111,6 +111,13 @@ func (m *Matcher) Inverse() (*Matcher, error) {
panic("labels.Matcher.Matches: invalid match type")
}
func (m *Matcher) GetRegexString() string {
if m.re == nil {
return ""
}
return m.re.GetRegexString()
}
// SetMatches returns a set of equality matchers for the current regex matchers if possible.
// For examples the regexp `a(b|f)` will returns "ab" and "af".
// Returns nil if we can't replace the regexp by only equality matchers.

View file

@ -61,6 +61,7 @@ func findSetMatches(re *syntax.Regexp, base string) []string {
if isCaseInsensitive(re) {
return nil
}
clearBeginEndText(re)
switch re.Op {
case syntax.OpLiteral:
return []string{base + string(re.Rune)}
@ -108,7 +109,6 @@ func findSetMatchesFromConcat(re *syntax.Regexp, base string) []string {
if len(re.Sub) == 0 {
return nil
}
clearBeginEndText(re)
clearCapture(re.Sub...)
matches := []string{base}
@ -209,6 +209,10 @@ func (m *FastRegexMatcher) SetMatches() []string {
return m.setMatches
}
func (m *FastRegexMatcher) GetRegexString() string {
return m.re.String()
}
// optimizeConcatRegex returns literal prefix/suffix text that can be safely
// checked against the label value before running the regexp matcher.
func optimizeConcatRegex(r *syntax.Regexp) (prefix, suffix, contains string) {