doc: Add and use LicenseYear

This commit is contained in:
Hajime Hoshi 2016-10-21 00:12:31 +09:00
parent e2fd9b9e7e
commit 3264532004
2 changed files with 17 additions and 6 deletions

View File

@ -27,6 +27,8 @@ import (
"regexp"
"strconv"
"strings"
"github.com/hajimehoshi/ebiten/internal"
)
func execute(command string, args ...string) error {
@ -55,12 +57,7 @@ var (
)
func init() {
b, err := ioutil.ReadFile("../LICENSE")
if err != nil {
panic(err)
}
license := strings.TrimSpace(string(b))
year, err := strconv.Atoi(regexp.MustCompile(`^Copyright (\d+)`).FindStringSubmatch(license)[1])
year, err := internal.LicenseYear()
if err != nil {
panic(err)
}

View File

@ -17,7 +17,9 @@ package internal
import (
"io/ioutil"
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"
)
@ -33,3 +35,15 @@ func LicenseComment() (string, error) {
license := "// " + strings.Join(lines[:len(lines)-1], "\n// ")
return license, nil
}
func LicenseYear() (int, error) {
license, err := LicenseComment()
if err != nil {
return 0, err
}
year, err := strconv.Atoi(regexp.MustCompile(`^// Copyright (\d+)`).FindStringSubmatch(license)[1])
if err != nil {
return 0, err
}
return year, nil
}