-
Notifications
You must be signed in to change notification settings - Fork 1
/
constant.go
45 lines (36 loc) · 1.02 KB
/
constant.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
package cuckle
import (
"encoding/hex"
"fmt"
)
// Constant is a scalar literal.
type Constant string
// ConstantBoolean returns a Constant for b.
func ConstantBoolean(b bool) Constant {
return Constant(fmt.Sprint(b))
}
// ConstantInteger returns a Constant for i.
func ConstantInteger(i int64) Constant {
return Constant(fmt.Sprint(i))
}
// ConstantFloat returns a Constant for f.
func ConstantFloat(f float64) Constant {
return Constant(fmt.Sprint(f))
}
// ConstantHex returns a Constant for b prefixed by 0x. Two characters represent
// each byte.
func ConstantHex(b []byte) Constant {
return Constant(fmt.Sprintf("0x%v", hex.EncodeToString(b)))
}
// ConstantString returns a Constant for s.
func ConstantString(s string) Constant {
return Constant(fmt.Sprintf("'%v'", s))
}
// ConstantStringEscaped returns a Constant for s.
func ConstantStringEscaped(s string) Constant {
return Constant(fmt.Sprintf("$$%v$$", s))
}
// ConstantUUID returns a Constant for uuid.
func ConstantUUID(uuid string) Constant {
return Constant(uuid)
}