forked from viant/dsunit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
datafile.go
44 lines (41 loc) · 872 Bytes
/
datafile.go
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
package dsunit
import (
"path"
"strings"
)
//DatafileInfo represent data file
type DatafileInfo struct {
Filename string
Name string
Ext string
Prefix string
Postfix string
}
//NewDatafileInfo returns new datafile info if supplied filedinfo matches prefix, postfix
func NewDatafileInfo(filename, prefix, postfix string) *DatafileInfo {
var result = &DatafileInfo{
Filename: filename,
Prefix: prefix,
Postfix: postfix,
}
name := filename
if prefix != "" {
if !strings.HasPrefix(name, prefix) {
return nil
}
name = string(name[len(prefix):])
}
ext := path.Ext(name)
if len(ext) > 0 {
name = string(name[:len(name)-len(ext)])
result.Ext = string(ext[1:])
}
if postfix != "" {
if !strings.HasSuffix(name, postfix) {
return nil
}
name = string(name[:len(name)-len(postfix)])
}
result.Name = name
return result
}