From 16f65b97e4fa99b2f381a29c98ef997391a21360 Mon Sep 17 00:00:00 2001 From: Marcel Schneider Date: Tue, 28 Nov 2017 10:03:46 +0100 Subject: [PATCH] Properly remove all the whitespace --- .gitignore | 3 +++ server/server.go | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 97bd5ea..93f6f9d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,6 @@ yarn-debug.log* yarn-error.log* static/*mensa*.json static/*bistro*.json +server/*.json +server/server +.*.swp diff --git a/server/server.go b/server/server.go index 8ccd5bb..d2902c9 100644 --- a/server/server.go +++ b/server/server.go @@ -5,6 +5,7 @@ import ( "fmt" "io/ioutil" "os" + "regexp" "strings" "github.com/PuerkitoBio/goquery" @@ -34,6 +35,7 @@ var ( "Mensa+Italia": "mensaitalia", "Bistro+HAWK": "bistrohawk", } + trimRegex = regexp.MustCompile(`\s{2,}`) ) func main() { @@ -93,9 +95,7 @@ func parseDate(doc *goquery.Document) string { } func strip(old string) string { - new := strings.Replace(old, "\t", "", -1) - new = strings.Replace(new, "\n", "", -1) - return new + return strings.TrimSpace(trimRegex.ReplaceAllString(old, " ")) } func parseMeals(doc *goquery.Document) ([]Meal, error) {