diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-11-02 19:57:01 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-11-02 19:57:01 -0400 |
commit | 85db279e33804c118b019c5f1e7666798df3e1f5 (patch) | |
tree | dfccd3ba1710fbfc68942f61690b24ca6a3fb364 /src/edit/util.go | |
parent | b51a2c03985f09845e498ece625f5e8a309b6086 (diff) |
better text-type detection
Diffstat (limited to 'src/edit/util.go')
-rw-r--r-- | src/edit/util.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/edit/util.go b/src/edit/util.go index b6dfde1..5835b10 100644 --- a/src/edit/util.go +++ b/src/edit/util.go @@ -5,6 +5,7 @@ import ( "net/http" "os/exec" "path" + "strings" ) type exitError exec.ExitError @@ -34,3 +35,13 @@ func getctype(name string, content []byte) string { } return ctype } + +func istext(ctype string) bool { + i := strings.Index(ctype, ";") + if i == -1 { + i = len(ctype) + } + ctype = strings.TrimSpace(strings.ToLower(ctype[0:i])) + + return strings.HasPrefix(ctype, "text/") || strings.HasSuffix(ctype, "+xml") +} |