2023-09-28 08:39:16 +00:00
|
|
|
/*
|
|
|
|
Copyright © 2023 Seednode <seednode@seedno.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
type splitPath struct {
|
|
|
|
base string
|
|
|
|
number string
|
|
|
|
extension string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (splitPath *splitPath) increment() {
|
|
|
|
asInt, err := strconv.Atoi(splitPath.number)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-10-04 20:47:43 +00:00
|
|
|
splitPath.number = fmt.Sprintf("%0*d", len(splitPath.number), asInt+1)
|
2023-09-28 08:39:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (splitPath *splitPath) decrement() {
|
|
|
|
asInt, err := strconv.Atoi(splitPath.number)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-10-04 20:47:43 +00:00
|
|
|
splitPath.number = fmt.Sprintf("%0*d", len(splitPath.number), asInt-1)
|
2023-09-28 08:39:16 +00:00
|
|
|
}
|
|
|
|
|
2023-10-04 20:47:43 +00:00
|
|
|
func split(path string, regexes *regexes) (*splitPath, error) {
|
2023-09-28 08:39:16 +00:00
|
|
|
split := regexes.filename.FindAllStringSubmatch(path, -1)
|
|
|
|
|
|
|
|
if len(split) < 1 || len(split[0]) < 3 {
|
2023-10-04 20:47:43 +00:00
|
|
|
return &splitPath{}, nil
|
2023-09-28 08:39:16 +00:00
|
|
|
}
|
|
|
|
|
2023-10-04 20:47:43 +00:00
|
|
|
p := &splitPath{
|
|
|
|
base: split[0][1],
|
|
|
|
number: split[0][2],
|
|
|
|
extension: split[0][3],
|
|
|
|
}
|
2023-09-28 08:39:16 +00:00
|
|
|
|
2023-10-04 20:47:43 +00:00
|
|
|
return p, nil
|
2023-09-28 08:39:16 +00:00
|
|
|
}
|