blob: 7c180546422dfe91708e380ecae34ac512ff9366 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
package main
import (
"bufio"
"errors"
"fmt"
"os"
"path/filepath"
"slices"
"github.com/alexflint/go-arg"
"github.com/ayyansea/uptfs/internal/config"
"github.com/ayyansea/uptfs/internal/filter"
"github.com/ayyansea/uptfs/internal/token"
)
var args struct {
ConfigFile string `arg:"-c" help:"path to config file" default:""`
}
func errExit(err error) {
fmt.Println(err)
os.Exit(1)
}
func main() {
arg.MustParse(&args)
var configFilePath string
var err error
if args.ConfigFile != "" {
configFilePath, err = filepath.Abs(args.ConfigFile)
}
if err != nil {
errExit(err)
}
var config config.Config
config.LoadConfig(configFilePath)
scanner := bufio.NewScanner(os.Stdin)
scanner.Scan()
inputString := scanner.Text()
if inputString == "" {
err := errors.New("the input string is empty")
fmt.Printf("%v\n", err)
os.Exit(1)
}
additionalDelimeters := []string{",", ".", " "}
tempword := ""
var tokenlist token.LinkedTokenList
for index, character := range inputString {
if slices.Contains(additionalDelimeters, string(character)) {
if len(tempword) != 0 {
for _, filterName := range config.Filters {
currentfilter := filter.FilterList[filterName]()
tempword = currentfilter.Filter(tempword)
}
tokenlist.AddToken(tempword)
tokenlist.AddToken(string(character))
tempword = ""
continue
}
tokenlist.AddToken(string(character))
tempword = ""
continue
}
tempword = tempword + string(character)
if index == len(inputString)-1 {
for _, filterName := range config.Filters {
currentfilter := filter.FilterList[filterName]()
tempword = currentfilter.Filter(tempword)
}
tokenlist.AddToken(tempword)
tempword = ""
}
}
result := ""
for current := tokenlist.GetHead(); current != nil; current = current.GetNextToken() {
result = result + current.GetContent()
}
fmt.Println(result)
}
|