summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/uptfs/main.go55
-rw-r--r--internal/split/split.go55
-rw-r--r--internal/token/linked_token_list.go6
3 files changed, 37 insertions, 79 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)
}
diff --git a/internal/split/split.go b/internal/split/split.go
deleted file mode 100644
index e03335c..0000000
--- a/internal/split/split.go
+++ /dev/null
@@ -1,55 +0,0 @@
-package split
-
-import (
- "strings"
-)
-
-func FormatInput(tokenArray []string, delimeterArray []string) []string {
- for _, delimeter := range delimeterArray {
- for index, element := range tokenArray {
- tokenArray = NewArrayWithSplit(tokenArray, index, element, delimeter)
- }
- }
-
- return tokenArray
-}
-
-func checkArrayElementsEmpty(array []string) bool {
- for _, str := range array {
- if str != "" {
- return false
- }
- }
- return true
-}
-
-func NewArrayWithSplit(initialArray []string, index int, token string, delimeter string) (result []string) {
- split := strings.Split(token, delimeter)
- splitLength := len(split)
-
- /*
- When a token only consists of delimeter * N (N >= 0),
- the resulting split consists of N empty elements.
- Here we check if it is so and essentialy remove that token
- from resulting array.
- */
-
- splitIsEmpty := checkArrayElementsEmpty(split)
- if splitIsEmpty {
- result = append(initialArray[:index], initialArray[index+1:]...)
- return result
- }
-
- if splitLength > 1 {
- if split[splitLength-1] == "" {
- split = split[:splitLength-1]
- }
-
- result = append(initialArray[:index], append(split, initialArray[index+1:]...)...)
- }
- if splitLength == 1 {
- result = initialArray
- }
-
- return result
-}
diff --git a/internal/token/linked_token_list.go b/internal/token/linked_token_list.go
index 5fe42a9..5115f75 100644
--- a/internal/token/linked_token_list.go
+++ b/internal/token/linked_token_list.go
@@ -28,9 +28,3 @@ func (lts *LinkedTokenList) AddToken(content string) {
lts.tail = newToken
}
}
-
-func SliceToLinkedTokenSlice(slice []string, tokenSlice *LinkedTokenList) {
- for _, item := range slice {
- tokenSlice.AddToken(item)
- }
-}