diff options
| author | ayyansea <ayyansea@gmail.com> | 2024-11-27 23:28:05 +0300 |
|---|---|---|
| committer | ayyansea <ayyansea@gmail.com> | 2024-11-27 23:28:05 +0300 |
| commit | d0b5612d38595e8147aa9c75cbb5bb2c3fc81bbe (patch) | |
| tree | f8d7dc049559b52ba33adb929a8b83f3740b082f /cmd/uptfs/main.go | |
| parent | 1a1411acb16b53d08ed8088d7fd3fabbb253a4e8 (diff) | |
feat: revamped program logic and removed unnecessary methods and modules
Diffstat (limited to 'cmd/uptfs/main.go')
| -rw-r--r-- | cmd/uptfs/main.go | 55 |
1 files changed, 37 insertions, 18 deletions
diff --git a/cmd/uptfs/main.go b/cmd/uptfs/main.go index db7312c..7c18054 100644 --- a/cmd/uptfs/main.go +++ b/cmd/uptfs/main.go @@ -6,12 +6,11 @@ import ( "fmt" "os" "path/filepath" - "strings" + "slices" "github.com/alexflint/go-arg" "github.com/ayyansea/uptfs/internal/config" "github.com/ayyansea/uptfs/internal/filter" - "github.com/ayyansea/uptfs/internal/split" "github.com/ayyansea/uptfs/internal/token" ) @@ -39,7 +38,6 @@ func main() { var config config.Config config.LoadConfig(configFilePath) - fmt.Printf("Config: %v\n", config) scanner := bufio.NewScanner(os.Stdin) scanner.Scan() @@ -51,24 +49,45 @@ func main() { os.Exit(1) } - additionalDelimeters := []string{",", "."} - tokens := strings.Split(inputString, " ") - tokens = split.FormatInput(tokens, additionalDelimeters) + additionalDelimeters := []string{",", ".", " "} + tempword := "" + var tokenlist token.LinkedTokenList - if len(tokens) == 0 { - err := errors.New("the slice is empty") - fmt.Printf("%v\n", err) - os.Exit(1) - } + 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 = "" - var linkedTokens token.LinkedTokenList - token.SliceToLinkedTokenSlice(tokens, &linkedTokens) + continue + } + tokenlist.AddToken(string(character)) + tempword = "" + + continue + } - for current := linkedTokens.GetHead(); current != nil; current = current.GetNextToken() { - for _, filterName := range config.Filters { - filter := filter.FilterList[filterName]() - current.SetContent(filter.Filter(current.GetContent())) + 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 = "" } - fmt.Println(current.GetContent()) } + + result := "" + + for current := tokenlist.GetHead(); current != nil; current = current.GetNextToken() { + result = result + current.GetContent() + } + + fmt.Println(result) } |
