z_mirror/fmm

git clone https://git.raiguard.me/z_mirror/fmm

Caleb HeuerMove log file parsing into the library27d8943

updating
832 B36 linesraw
1package fmm
2
3import (
4	"strings"
5)
6
7// A small representation of a mod, with an optional version.
8type ModIdent struct {
9	Name    string
10	Version *Version
11}
12
13// Returns a ModIdent parsed from an input string with the format of 'name',
14// 'name_version', or 'name_version.zip'.
15func NewModIdent(input string) ModIdent {
16	input = strings.TrimSuffix(input, ".zip")
17	parts := strings.Split(input, "_")
18	if len(parts) == 1 {
19		return ModIdent{input, nil}
20	}
21
22	name := strings.Join(parts[:len(parts)-1], "_")
23	version, err := NewVersion(parts[len(parts)-1])
24	if err != nil {
25		return ModIdent{input, nil}
26	}
27	return ModIdent{name, version}
28}
29
30// Returns a string in the format of 'name' or 'name_version'.
31func (i *ModIdent) ToString() string {
32	if i.Version != nil {
33		return i.Name + " " + i.Version.ToString(false)
34	}
35	return i.Name
36}