-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.go
More file actions
60 lines (55 loc) · 1.3 KB
/
parse.go
File metadata and controls
60 lines (55 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package goadiflog
import (
"errors"
"path"
"strings"
"github.com/Eminlin/GoADIFLog/format"
"github.com/Eminlin/GoADIFLog/tools"
)
// Parse 解析入口
// fileDir:./testFile/xxx.adi or ./testFile/xxx.log
func Parse(fileDir string) ([]format.CQLog, error) {
var rtn []format.CQLog
filename := path.Base(fileDir)
fileSuffix := path.Ext(filename)
mode := getFileMode(fileSuffix)
if mode == format.UnknowMode {
return rtn, errors.New("unkown file format file:" + filename)
}
if mode == format.ADIFMode {
line, err := tools.ReadADIFFileLine(fileDir)
if err != nil {
return rtn, err
}
return newAdfi(filename).parse(line), nil
}
if mode == format.CabrilloMode {
line, err := tools.ReadCabrFileLine(fileDir)
if err != nil {
return rtn, err
}
return newCabrillo(filename).parse(line), nil
}
return rtn, nil
}
func ParseAdifFromString(adif string) ([]format.CQLog, error) {
var rtn []format.CQLog
line, err := tools.ReadAdifString(adif)
if err != nil {
return rtn, err
}
return newAdfi("").parse(line), nil
}
// getFileMode 检查文件后缀格式
func getFileMode(suffix string) int {
switch strings.ToLower(suffix) {
case ".adi":
return format.ADIFMode
case ".adif":
return format.ADIFMode
case ".log":
return format.CabrilloMode
default:
return format.UnknowMode
}
}