package tequat import ( "strings" ) // Normalised is pure. func (tqa TQA) Normalised() TQA { atoms := []Atom(tqa) // search for a signature block and move it to the end if true { var signatureblock *SignatureBlock // [2023-02-15, jfrech] TODO Think about recognising the non-space terminated mark. (Maybe only when it is the very last non-quote non-attachment atom?) for _, mark := range []string{"-- ", "--"} { for j := len(atoms)-1; signatureblock == nil && j >= 0; j-- { if text, ok := atoms[j].(Text); ok { if strings.HasPrefix(text.Raw, mark + "\n") { atoms = append(atoms[:j], atoms[j+1:]...) signatureblock = &SignatureBlock{text.Raw[len(mark + "\n"):]} } else if k := strings.Index(text.Raw, "\n" + mark + "\n"); k != -1 { atoms[j] = Text{text.Raw[:k+1]} signatureblock = &SignatureBlock{text.Raw[k+1+len(mark + "\n"):]} } } } } if signatureblock != nil { atoms = append(atoms, *signatureblock) } } // TODO combine text atoms return TQA(atoms) }