Refactor some things around a little
This commit is contained in:
@@ -2,8 +2,6 @@ package processor
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/antchfx/xmlquery"
|
||||
@@ -13,34 +11,6 @@ import (
|
||||
// XMLProcessor implements the Processor interface for XML documents
|
||||
type XMLProcessor struct{}
|
||||
|
||||
// Process implements the Processor interface for XMLProcessor
|
||||
func (p *XMLProcessor) Process(filename string, pattern string, luaExpr string) (int, int, error) {
|
||||
// Read file content
|
||||
fullPath := filepath.Join(".", filename)
|
||||
content, err := os.ReadFile(fullPath)
|
||||
if err != nil {
|
||||
return 0, 0, fmt.Errorf("error reading file: %v", err)
|
||||
}
|
||||
|
||||
fileContent := string(content)
|
||||
|
||||
// Process the content
|
||||
modifiedContent, modCount, matchCount, err := p.ProcessContent(fileContent, pattern, luaExpr)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
|
||||
// If we made modifications, save the file
|
||||
if modCount > 0 {
|
||||
err = os.WriteFile(fullPath, []byte(modifiedContent), 0644)
|
||||
if err != nil {
|
||||
return 0, 0, fmt.Errorf("error writing file: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return modCount, matchCount, nil
|
||||
}
|
||||
|
||||
// ProcessContent implements the Processor interface for XMLProcessor
|
||||
func (p *XMLProcessor) ProcessContent(content string, pattern string, luaExpr string) (string, int, int, error) {
|
||||
// Parse XML document
|
||||
|
Reference in New Issue
Block a user