refactor: Update ARR body parsing logic

This commit is contained in:
windyboy
2024-07-22 14:43:35 +08:00
parent 25bb5aa404
commit 3115162454
4 changed files with 77 additions and 16 deletions
+9 -9
View File
@@ -18,7 +18,7 @@ const (
var (
categoryRegex = regexp.MustCompile(`\((?P<category>[A-Z]+)-`)
emptyLineRemove = regexp.MustCompile(`(?m)^\s*$`)
bodyOnly = regexp.MustCompile(`(.|\n)?((ZCZC(.|\n)*))NNNN$`)
bodyOnly = regexp.MustCompile(`(.|\n)?(ZCZC(.|\n)*)NNNN(.|\n)?$`)
)
type BodyParser struct {
@@ -169,16 +169,16 @@ func Parse(rawText string) (*domain.ParsedMessage, error) {
func clean(text string) string {
cleanedText := emptyLineRemove.ReplaceAllString(text, "")
cleanText := strings.ReplaceAll(cleanedText, "\n\n", "\n")
if bodyOnly != nil {
match := bodyOnly.FindStringSubmatch(cleanText)
if len(match) > 1 {
bodyOnly := match[2]
if bodyOnly[len(bodyOnly)-1] == '\n' {
return bodyOnly[:len(bodyOnly)-1]
}
return bodyOnly
// if bodyOnly != nil {
match := bodyOnly.FindStringSubmatch(cleanText)
if len(match) > 1 {
bodyOnly := match[2]
if bodyOnly[len(bodyOnly)-1] == '\n' {
return bodyOnly[:len(bodyOnly)-1]
}
return bodyOnly
}
// }
return ""
}