Refactoring - remove duplicate code
This commit is contained in:
@@ -493,20 +493,14 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) {
|
||||
}
|
||||
} else if re_postfix[i] == 'p' || re_postfix[i] == 'P' {
|
||||
charClassInverted := (re_postfix[i] == 'P')
|
||||
charsInClass := []rune{}
|
||||
i++
|
||||
if isUnicodeCharClassLetter(re_postfix[i]) {
|
||||
chars, err := unicodeCharClassToRange(string(re_postfix[i]))
|
||||
var err error
|
||||
charsInClass, err = unicodeCharClassToRange(string(re_postfix[i]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var toAppend postfixNode
|
||||
if !charClassInverted {
|
||||
toAppend = newPostfixNode(chars...)
|
||||
} else {
|
||||
toAppend = newPostfixDotNode()
|
||||
toAppend.except = append([]postfixNode{}, newPostfixNode(chars...))
|
||||
}
|
||||
outQueue = append(outQueue, toAppend)
|
||||
} else if re_postfix[i] == '{' {
|
||||
i++ // Skip opening bracket
|
||||
unicodeCharClassStr := ""
|
||||
@@ -514,21 +508,22 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) {
|
||||
unicodeCharClassStr += string(re_postfix[i])
|
||||
i++
|
||||
}
|
||||
chars, err := unicodeCharClassToRange(unicodeCharClassStr)
|
||||
var err error
|
||||
charsInClass, err = unicodeCharClassToRange(unicodeCharClassStr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var toAppend postfixNode
|
||||
if !charClassInverted { // \p
|
||||
toAppend = newPostfixNode(chars...)
|
||||
} else { // \P
|
||||
toAppend = newPostfixDotNode()
|
||||
toAppend.except = append([]postfixNode{}, newPostfixNode(chars...))
|
||||
}
|
||||
outQueue = append(outQueue, toAppend)
|
||||
} else {
|
||||
return nil, fmt.Errorf("error parsing unicode character class in expression")
|
||||
}
|
||||
var toAppend postfixNode
|
||||
if !charClassInverted { // \p
|
||||
toAppend = newPostfixNode(charsInClass...)
|
||||
} else { // \P
|
||||
toAppend = newPostfixDotNode()
|
||||
toAppend.except = append([]postfixNode{}, newPostfixNode(charsInClass...))
|
||||
}
|
||||
outQueue = append(outQueue, toAppend)
|
||||
} else if re_postfix[i] == '0' { // Octal value
|
||||
var octVal int64
|
||||
var octValStr string
|
||||
@@ -713,19 +708,14 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) {
|
||||
}
|
||||
} else if re_postfix[i] == 'p' || re_postfix[i] == 'P' {
|
||||
charClassInverted := (re_postfix[i] == 'P')
|
||||
charsInList := []rune{}
|
||||
i++
|
||||
if isUnicodeCharClassLetter(re_postfix[i]) {
|
||||
charsInList, err := unicodeCharClassToRange(string(re_postfix[i]))
|
||||
var err error
|
||||
charsInList, err = unicodeCharClassToRange(string(re_postfix[i]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !charClassInverted {
|
||||
chars = append(chars, newPostfixNode(charsInList...))
|
||||
} else {
|
||||
toAppend := newPostfixDotNode()
|
||||
toAppend.except = append([]postfixNode{}, newPostfixNode(charsInList...))
|
||||
chars = append(chars, toAppend)
|
||||
}
|
||||
} else if re_postfix[i] == '{' {
|
||||
i++ // Skip opening bracket
|
||||
unicodeCharClassStr := ""
|
||||
@@ -733,21 +723,21 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) {
|
||||
unicodeCharClassStr += string(re_postfix[i])
|
||||
i++
|
||||
}
|
||||
charsInList, err := unicodeCharClassToRange(unicodeCharClassStr)
|
||||
var err error
|
||||
charsInList, err = unicodeCharClassToRange(unicodeCharClassStr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !charClassInverted {
|
||||
chars = append(chars, newPostfixNode(charsInList...))
|
||||
} else {
|
||||
toAppend := newPostfixDotNode()
|
||||
toAppend.except = append([]postfixNode{}, newPostfixNode(charsInList...))
|
||||
chars = append(chars, toAppend)
|
||||
}
|
||||
} else {
|
||||
return nil, fmt.Errorf("error parsing unicode character class in expression")
|
||||
}
|
||||
|
||||
if !charClassInverted {
|
||||
chars = append(chars, newPostfixNode(charsInList...))
|
||||
} else {
|
||||
toAppend := newPostfixDotNode()
|
||||
toAppend.except = append([]postfixNode{}, newPostfixNode(charsInList...))
|
||||
chars = append(chars, toAppend)
|
||||
}
|
||||
} else if re_postfix[i] == '0' { // Octal value
|
||||
|
||||
var octVal int64
|
||||
|
Reference in New Issue
Block a user