diff options
author | Christopher Speller <crspeller@gmail.com> | 2017-05-17 16:51:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-17 16:51:25 -0400 |
commit | d103ed6ca97ca5a2669f6cf5fe4b3d2a9c945f26 (patch) | |
tree | dbde13123c6add150448f7b75753ac022d862475 /vendor/github.com/nicksnyder/go-i18n/i18n/bundle | |
parent | cd23b8139a9463b67e3096744321f6f4eb0ca40a (diff) | |
download | chat-d103ed6ca97ca5a2669f6cf5fe4b3d2a9c945f26.tar.gz chat-d103ed6ca97ca5a2669f6cf5fe4b3d2a9c945f26.tar.bz2 chat-d103ed6ca97ca5a2669f6cf5fe4b3d2a9c945f26.zip |
Upgrading server dependancies (#6431)
Diffstat (limited to 'vendor/github.com/nicksnyder/go-i18n/i18n/bundle')
-rw-r--r-- | vendor/github.com/nicksnyder/go-i18n/i18n/bundle/bundle.go | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/vendor/github.com/nicksnyder/go-i18n/i18n/bundle/bundle.go b/vendor/github.com/nicksnyder/go-i18n/i18n/bundle/bundle.go index 2ad1d7cc3..a2291362f 100644 --- a/vendor/github.com/nicksnyder/go-i18n/i18n/bundle/bundle.go +++ b/vendor/github.com/nicksnyder/go-i18n/i18n/bundle/bundle.go @@ -9,6 +9,7 @@ import ( "path/filepath" "reflect" "sync" + "unicode" "github.com/nicksnyder/go-i18n/i18n/language" "github.com/nicksnyder/go-i18n/i18n/translation" @@ -86,8 +87,8 @@ func parseTranslations(filename string, buf []byte) ([]translation.Translation, ext := filepath.Ext(filename) - // `github.com/pelletier/go-toml` has an Unmarshal function, - // that can't unmarshal to maps, so we should parse TOML format separately. + // `github.com/pelletier/go-toml` lacks an Unmarshal function, + // so we should parse TOML separately. if ext == ".toml" { tree, err := toml.LoadReader(bytes.NewReader(buf)) if err != nil { @@ -119,11 +120,39 @@ func parseTranslations(filename string, buf []byte) ([]translation.Translation, } func isStandardFormat(ext string, buf []byte) bool { + buf = deleteLeadingComments(ext, buf) firstRune := rune(buf[0]) - if (ext == ".json" && firstRune == '[') || (ext == ".yaml" && firstRune == '-') { - return true + return (ext == ".json" && firstRune == '[') || (ext == ".yaml" && firstRune == '-') +} + +// deleteLeadingComments deletes leading newlines and comments in buf. +// It only works for ext == ".yaml". +func deleteLeadingComments(ext string, buf []byte) []byte { + if ext != ".yaml" { + return buf } - return false + + for { + buf = bytes.TrimLeftFunc(buf, unicode.IsSpace) + if buf[0] == '#' { + buf = deleteLine(buf) + } else { + break + } + } + + return buf +} + +func deleteLine(buf []byte) []byte { + index := bytes.IndexRune(buf, '\n') + if index == -1 { // If there is only one line without newline ... + return nil // ... delete it and return nothing. + } + if index == len(buf)-1 { // If there is only one line with newline ... + return nil // ... do the same as above. + } + return buf[index+1:] } // unmarshal finds an appropriate unmarshal function for ext |