Use arrays properly when known the lenght
This commit is contained in:
parent
f35947c644
commit
e209901fef
1 changed files with 5 additions and 5 deletions
10
upload.go
10
upload.go
|
@ -149,17 +149,17 @@ func getCover(e *epub.Epub, title string) (string, string) {
|
||||||
func parseAuthr(creator []string) []string {
|
func parseAuthr(creator []string) []string {
|
||||||
exp1, _ := regexp.Compile("^(.*\\( *([^\\)]*) *\\))*$")
|
exp1, _ := regexp.Compile("^(.*\\( *([^\\)]*) *\\))*$")
|
||||||
exp2, _ := regexp.Compile("^[^:]*: *(.*)$")
|
exp2, _ := regexp.Compile("^[^:]*: *(.*)$")
|
||||||
var res []string //TODO: can be predicted the lenght
|
res := make([]string, len(creator))
|
||||||
for _, s := range creator {
|
for i, s := range creator {
|
||||||
auth := exp1.FindStringSubmatch(s)
|
auth := exp1.FindStringSubmatch(s)
|
||||||
if auth != nil {
|
if auth != nil {
|
||||||
res = append(res, cleanStr(strings.Join(auth[2:], ", ")))
|
res[i] = cleanStr(strings.Join(auth[2:], ", "))
|
||||||
} else {
|
} else {
|
||||||
auth := exp2.FindStringSubmatch(s)
|
auth := exp2.FindStringSubmatch(s)
|
||||||
if auth != nil {
|
if auth != nil {
|
||||||
res = append(res, cleanStr(auth[1]))
|
res[i] = cleanStr(auth[1])
|
||||||
} else {
|
} else {
|
||||||
res = append(res, cleanStr(s))
|
res[i] = cleanStr(s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue