27 lines
487 B
Go
27 lines
487 B
Go
package megauploader
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
type fileIncrement struct {
|
|
pre string
|
|
post string
|
|
}
|
|
|
|
func (fi fileIncrement) Increment(i int) string {
|
|
if i == 0 {
|
|
return fmt.Sprintf("%s%s", fi.pre, fi.post)
|
|
}
|
|
return fmt.Sprintf("%s-%d%s", fi.pre, i, fi.post)
|
|
}
|
|
|
|
func newFileIncrement(fn string) fileIncrement {
|
|
idx := strings.Index(fn, ".")
|
|
if idx != -1 {
|
|
return fileIncrement{pre: fn[0:idx], post: fn[idx:]}
|
|
} else {
|
|
return fileIncrement{pre: fn[0:], post: ""}
|
|
}
|
|
}
|