-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasicDataType.go
83 lines (63 loc) · 1.59 KB
/
basicDataType.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Basic datatypes of wikibase
// They are: String, integer, nonNegativeInteger, decimal, IRI, GlobalSiteIdentifier, UserLanguageCode
// Described here: https://www.mediawiki.org/wiki/Wikibase/DataModel#Defining_data_structures_in_UML
// and there exported name are captialized, for example decimal is exported as Decimal
package gowd
import (
"math/big"
)
// basic data type "string" is simply same as string in go
// Interger corresponds to the basic data type "integer"
type Integer struct {
big.Int
}
func NewInteger(i int64) (x *Integer) {
x = new(Integer)
x.Int.SetInt64(i)
return
}
func (x *Integer) SetString(s string) bool {
i := big.NewInt(0)
_, ok := i.SetString(s,10)
return ok
}
// Unsigned corresponds to the basic data type "nonNegativeInteger"
type Unsigned Integer
func NewUnsigned(i uint64) (x *Unsigned) {
x = new(Unsigned)
x.SetUint64(i)
return
}
func (x *Unsigned) SetUint64(i uint64) {
x.Int.SetUint64(i)
}
func (x *Unsigned) Set(i *big.Int) bool {
if i.Sign()<0 {
return false
}
x.Int.Set(i)
return true
}
func (x *Unsigned) SetString(s string) bool {
i := big.NewInt(0)
_, ok := i.SetString(s,10)
if ok && i.Sign()>=0 {
x.Int.Set(i)
return true
}else {
return false
}
}
// Decimal corresponds to the basic data type "decimal"
type Decimal struct {
big.Float
}
func NewDecimal(f float64) (x *Decimal) {
x = new(Decimal)
x.Float.SetFloat64(f)
return
}
// TODO: enable format check
type IRI string
type GlobalSiteIdentifier string
type UserLanguageCode string