From ace8309f647db74da46f50f054b44539d3da6d1a Mon Sep 17 00:00:00 2001 From: zu1k Date: Tue, 21 Jul 2020 17:54:57 +0800 Subject: [PATCH] add trim for result --- cmd/root.go | 2 +- internal/tools/replace.go | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index b05f078..a898244 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -66,7 +66,7 @@ Find document on: https://github.com/zu1k/nali if line == "quit" || line == "exit" { return } - fmt.Println(app.ReplaceIPInString(app.ReplaceCDNInString(line))) + fmt.Printf("%s\n", app.ReplaceIPInString(app.ReplaceCDNInString(line))) } } else { app.ParseIPs(args) diff --git a/internal/tools/replace.go b/internal/tools/replace.go index c30a58f..3930d12 100644 --- a/internal/tools/replace.go +++ b/internal/tools/replace.go @@ -1,12 +1,15 @@ package tools -import "strings" +import ( + "strings" +) -func ReplaceAdd(origin string, old string, new string) string { +func ReplaceAdd(origin string, old string, new string) (result string) { subLen := len(new) - len(old) wanted := old + strings.Repeat(" ", subLen) if strings.Contains(origin, wanted) { - return strings.ReplaceAll(origin, wanted, new) + result = strings.ReplaceAll(origin, wanted, new) } - return strings.ReplaceAll(origin, old, new) + result = strings.ReplaceAll(origin, old, new) + return strings.TrimRight(result, " \t") }