-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixes.st
218 lines (181 loc) · 4.65 KB
/
fixes.st
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
Symbol extend [
beginsWithSubCollection: aSymbol [
^(self startsWith: aSymbol).
]
]
Object subclass: FileDirectory [
| dir |
FileDirectory class >> default [
^self on: Directory home.
]
FileDirectory class >> on: aDirectory [
| fd |
fd := FileDirectory new.
fd setDir: aDirectory.
^fd.
]
setDir: aDirectory [
dir := aDirectory.
]
directoryNamed: aDirectory [
dir := dir / aDirectory.
]
assureExistence [
dir exists ifFalse: [
dir := Directory create: dir name.
]
]
fileExists: aFile [
(aFile first = $/) ifTrue: [
^(File name: aFile) exists.
] ifFalse: [
^(dir / aFile) exists.
]
]
exists [
^dir exists.
]
recursiveDelete [
dir recursiveDelete.
]
forceNewFileNamed: aFile [
| file |
file := File name: aFile.
file exists ifTrue: [
file remove.
].
file touch.
^file.
]
containingDirectory [
| path |
path := dir asString tokenize: '/'.
path := path copyFrom: 1 to: path size - 1.
path := File name: (path join: '/').
^FileDirectory on: path.
]
entries [
| array dirContent |
dirContent := dir filesMatching: '*'.
array := Array new: dirContent size.
dirContent doWithIndex: [ :file :i |
| description |
description := Array new: 5.
description at: 1 put: file name.
description at: 2 put: file creationTime.
description at: 3 put: file lastModifyTime.
description at: 4 put: file mode.
description at: 5 put: file size.
array at: i put: description.
]
]
isEmpty [
^(dir filesMatching: '*') size > 2.
]
]
File extend [
binary []
nextPutAll: aString [
| stream |
stream := self writeStream.
aString do: [ :character |
stream nextPut: (Character codePoint: character).
].
stream close.
]
close []
recursiveDelete [
self isDirectory ifTrue: [
(self filesMatching: '*') do: [ :file |
"to exclude /. and /.."
(file = self or: [file = self parent]) ifFalse: [
file recursiveDelete.
].
].
self remove.
] ifFalse: [
self remove.
].
]
]
DateTime subclass: DateAndTime [
]
String extend [
includesSubString: aString [
^(self indexOfRegex: aString) size > 0.
]
includesSubstring: aString caseSensitive: caseSensitive [
caseSensitive ifTrue: [
^self includesSubString: aString.
] ifFalse: [
^self asLowercase includesSubString: aString asLowercase.
].
]
caseInsensitiveLessOrEqual: aString [
^((self caseInsensitiveCompareTo: aString) <= 0)
]
]
DateTime subclass: TimeStamp [
date [
^self asDate
]
time [
^self asTime
]
]
Collection extend [
intersection: aCollection [
"Code coppied from Squeak"
^self select: [:each | aCollection includes: each]
]
]
String extend [
padLeft: aCharacter size: size [
| result |
result := self copy.
(self size < size) ifTrue: [
1 to: (size - self size) do: [ :i |
result := (aCharacter asString, result).
].
].
^result.
]
]
Time extend [
print24: print24 showSeconds: showSeconds on: aStream[
| result hour |
print24 ifTrue: [
result := (self hours asString padLeft: $0 size: 2)
] ifFalse: [
hour := self hours.
(hour > 12) ifTrue: [ hour := hour - 12 ].
result := (hour asString padLeft: $0 size: 2).
].
result := result, ':',(self minutes asString padLeft: $0 size: 2).
showSeconds ifTrue: [
result := (result, ':',(self seconds asString padLeft: $0 size: 2)).
].
result print: self on: aStream.
]
]
Collection extend [
reduce: aBlock [
| result |
result := self first.
(self size > 1) ifTrue: [
2 to: (self size) do: [ :i |
result := aBlock value: result value: (self at: i).
]
].
^result
]
]
Behavior extend [
"Code taken from StartCompiler.st"
evaluatorClass [
^STInST.GSTFileInParser
]
parserClass [
^STInST.RBBracketedMethodParser
]
]