Fix function and package names if the user supplied versions start with a digit.

pull/4/head
jim teeuwen 2011-06-27 18:45:39 +02:00
parent 55b35257df
commit 2985202b2b
1 changed files with 11 additions and 1 deletions

12
main.go
View File

@ -11,11 +11,12 @@ import (
"path" "path"
"strings" "strings"
"runtime" "runtime"
"unicode"
) )
const ( const (
APP_NAME = "bindata" APP_NAME = "bindata"
APP_VERSION = "0.3" APP_VERSION = "0.4"
) )
func main() { func main() {
@ -61,6 +62,11 @@ func main() {
if len(*pkgname) == 0 { if len(*pkgname) == 0 {
fmt.Fprintln(os.Stderr, "[w] No package name specified. Using 'main'.") fmt.Fprintln(os.Stderr, "[w] No package name specified. Using 'main'.")
*pkgname = "main" *pkgname = "main"
} else {
if unicode.IsDigit(int((*pkgname)[0])) {
// Identifier can't start with a digit.
*pkgname = "_" + *pkgname
}
} }
if len(*funcname) == 0 { if len(*funcname) == 0 {
@ -74,6 +80,10 @@ func main() {
file = strings.Replace(file, " ", "_", -1) file = strings.Replace(file, " ", "_", -1)
file = strings.Replace(file, ".", "_", -1) file = strings.Replace(file, ".", "_", -1)
file = strings.Replace(file, "-", "_", -1) file = strings.Replace(file, "-", "_", -1)
if unicode.IsDigit(int(file[0])) {
// Identifier can't start with a digit.
file = "_" + file
}
fmt.Fprintf(os.Stderr, "[w] No function name specified. Using '%s'.\n", file) fmt.Fprintf(os.Stderr, "[w] No function name specified. Using '%s'.\n", file)
*funcname = file *funcname = file
} }