Skip to content

Commit

Permalink
Merge pull request #29 from prl900/master
Browse files Browse the repository at this point in the history
Removing spaces using regexp package
  • Loading branch information
mpgerlek authored Jun 18, 2018
2 parents 6ae9eb3 + 5095839 commit e9f34d2
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions support/ProjString.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"encoding/json"
"strconv"
"strings"
"regexp"

"github.com/go-spatial/proj/merror"
)
Expand Down Expand Up @@ -85,22 +86,14 @@ func NewProjString(source string) (*ProjString, error) {
}

// handle extra whitespace in lines like " +proj = merc x = 1.2 "
//
// repeat a bunch of simple replacements until nothing changes anymore
// TODO: this is a bad hack
func collapse(s string) string {
re_leadclose_whtsp := regexp.MustCompile(`^[\s\p{Zs}]+|[\s\p{Zs}]+$`)
re_inside_whtsp := regexp.MustCompile(`[\s\p{Zs}]{2,}`)
re_equal_whtsp := regexp.MustCompile(`\s?[=]\s?`)
s = re_leadclose_whtsp.ReplaceAllString(s, "")
s = re_inside_whtsp.ReplaceAllString(s, " ")
s = re_equal_whtsp.ReplaceAllString(s, "=")

for {
t := strings.Replace(s, "\t", " ", -1)
t = strings.Replace(t, " ", " ", -1)
t = strings.Replace(t, " =", "=", -1)
t = strings.Replace(t, "= ", "=", -1)

if s == t {
break
}
s = t
}
return s
}

Expand Down

0 comments on commit e9f34d2

Please sign in to comment.