Imported Upstream version 0.1
[debian/configureit.git] / pathlist.go
1 // string.go
2 //
3 // String Type
4
5 package configureit
6
7 import (
8         "os"
9         "strings"
10 )
11
12 var PathListSeparator = os.PathListSeparator
13
14 func init() {
15         if PathListSeparator == 0 {
16                 // Bloody Plan9.
17                 PathListSeparator = '!'
18         }
19 }
20
21 // PathList is a list of paths.  Paths are assuemd to be separated by
22 // os.PathListSeparator ('!' if undefined.)
23 //
24 // White spaces are valid within terms, but leading and trailing whitespace 
25 // are discarded from the whole input, not from terms!
26 type PathListOption struct {    
27         defaultvalue    []string
28         isset           bool
29         Values          []string
30 }
31
32 func NewPathListOption(defaultValue []string) ConfigNode {
33         opt := new(PathListOption)
34
35         opt.defaultvalue = defaultValue
36         opt.Reset()
37
38         return opt
39 }
40
41 func (opt *PathListOption) String() string {
42         return strings.Join(opt.Values, string(PathListSeparator))
43 }
44
45 func (opt *PathListOption) Parse(newValue string) os.Error {
46         newValue = strings.TrimSpace(newValue)
47
48         opt.Values = strings.Split(newValue, string(PathListSeparator))
49         opt.isset = true
50
51         return nil
52 }
53
54 func (opt *PathListOption) IsDefault() bool {
55         return !opt.isset
56 }
57
58 func (opt *PathListOption) Reset() {
59         opt.Values = opt.defaultvalue
60         opt.isset = false
61 }