From 057e4ac21bd16068e12148134478219e8c607077 Mon Sep 17 00:00:00 2001 From: Seednode Date: Thu, 8 Sep 2022 16:01:16 -0500 Subject: [PATCH] Removed unused utils.go --- cmd/utils.go | 102 --------------------------------------------------- 1 file changed, 102 deletions(-) delete mode 100644 cmd/utils.go diff --git a/cmd/utils.go b/cmd/utils.go deleted file mode 100644 index 8c2bb29..0000000 --- a/cmd/utils.go +++ /dev/null @@ -1,102 +0,0 @@ -/* -Copyright © 2022 Seednode -*/ - -package cmd - -import ( - "bufio" - "os" - "strings" -) - -type Exit struct{ Code int } - -func Chunks(s string, chunkSize int) []string { - if len(s) == 0 { - return nil - } - - if chunkSize >= len(s) { - return []string{s} - } - - var chunks []string = make([]string, 0, (len(s)-1)/chunkSize+1) - - currentLen := 0 - currentStart := 0 - - for i := range s { - if currentLen == chunkSize { - chunks = append(chunks, s[currentStart:i]) - currentLen = 0 - currentStart = i - } - - currentLen++ - } - - chunks = append(chunks, s[currentStart:]) - - return chunks -} - -func CollectOutputs(output chan string, outputs chan<- []string) { - o := []string{} - - for r := range output { - o = append(o, r) - } - - outputs <- o - - close(outputs) -} - -func FirstN(s string, n int) string { - i := 0 - for j := range s { - if i == n { - return s[:j] - } - i++ - } - return s -} - -func HandleExit() { - if e := recover(); e != nil { - if exit, ok := e.(Exit); ok == true { - os.Exit(exit.Code) - } - panic(e) - } -} - -func ScanFile(dbfile string) (func(), *bufio.Scanner, error) { - readFile, err := os.Open(dbfile) - if err != nil { - return func() {}, nil, err - } - - fileScanner := bufio.NewScanner(readFile) - buffer := make([]byte, 0, 64*1024) - fileScanner.Buffer(buffer, 1024*1024) - - return func() { _ = readFile.Close() }, fileScanner, nil -} - -func Strip(s string) string { - var result strings.Builder - for i := 0; i < len(s); i++ { - b := s[i] - - if ('a' <= b && b <= 'z') || - ('A' <= b && b <= 'Z') || - ('0' <= b && b <= '9') { - result.WriteByte(b) - } - } - - return result.String() -}