This repository has been archived by the owner on Jul 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
string.go
59 lines (48 loc) · 1.4 KB
/
string.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
package types
import (
"fmt"
)
// String represents an EDN string: "abc"
type String string
// Equals compares the String to another Value for equality.
func (this String) Equals(other Value) bool {
return this == other
}
// String returns the EDN string representation of the String.
func (this String) String() string {
return fmt.Sprintf("%#v", string(this))
}
// Keyword represents an EDN keyword: :foo/bar or :baz
type Keyword string
// Equals compares the Keyword to another Value for equality.
func (this Keyword) Equals(other Value) bool {
// NOTE: this will allow a Keyword to == a String.
// TODO: Make Keyword a struct (namespace + word) that
// is a distinct type.
return this == other
}
// String returns the EDN string representation of the Keyword.
func (this Keyword) String() string {
return fmt.Sprintf(":%v", string(this))
}
// Character represents an EDN character: \a, \b, \c, \newline, etc...
type Character rune // TODO: possibly move out of string file
// Equals compares the Character to another Value for equality.
func (this Character) Equals(other Value) bool {
return this == other
}
// String returns the EDN string representation of the Character.
func (this Character) String() string {
var str string
switch rune(this) {
case '\t':
str = "tab"
case '\r':
str = "return"
case '\n':
str = "newline"
default:
str = string(this)
}
return fmt.Sprintf("\\%s", str)
}