-
Notifications
You must be signed in to change notification settings - Fork 0
/
string.sj
89 lines (74 loc) · 1.96 KB
/
string.sj
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
82
83
84
85
86
87
88
emptyStringData := nullptr
--c--
g_emptystringdata = "";
--c--
string(
count := 0
data := array!char(
data : emptyStringData
dataSize : 0
count : 0
isGlobal : true
)
_isNullTerminated := false
add(item : 'string) {
if item.count == 0 {
string(count : count, data : data)
} else {
newData : if count + item.count > data.dataSize {
data.grow(((count + item.count - 1) / 256 + 1) * 256)
} else {
data
}
newCount := count
for i : 0 to item.count {
newData.initAt(newCount, item.getAt(i))
newCount++
}
string(count : newCount, data : newData)
}
}
getAt(index : 'i32)'char {
data.getAt(index)
}
setAt(index : 'i32, item : 'char)'void {
data.setAt(index, item)
}
isEqual(test : 'stack string) {
data.isEqual(test.data)
}
isGreater(test : 'stack string)'bool {
data.isGreater(test.data)
}
isGreaterOrEqual(test : 'stack string)'bool {
data.isGreaterOrEqual(test.data)
}
isLess(test : 'stack string)'bool {
data.isLess(test.data)
}
isLessOrEqual(test : 'stack string)'bool {
data.isLessOrEqual(test.data)
}
toUpperCase()'string {
a : array!char(datasize : ((count - 1) / 256 + 1) * 256)
for i : 0 to count {
a.initAt(i, data[i].toUpperCase())
}
string(count : count, data : a)
}
nullTerminate() {
if !data.isGlobal || !_isNullTerminated {
if count + 1 > data.dataSize {
data = data.grow(count + 1)
}
data.initAt(count, '\0')
_isNullTerminated = true
}
void
}
hash()'u32 {
--c--
#return(u32, kh_str_hash_func((char*)_parent->data.data));
--c--
}
) { this }