Fix unescaping in matlab, miniMAL and rpython.
[jackhill/mal.git] / gst / util.st
CommitLineData
d38ab263 1SequenceableCollection extend [
34aa5ced
VS
2 asDictionary [
3 | dict assoc |
4 dict := Dictionary new.
5 1 to: self size by: 2 do:
6 [ :i | dict add: (self at: i) -> (self at: i + 1) ].
7 ^dict
8 ]
9]
10
11String extend [
12 parse [
13 |text|
14 text := self copyFrom: 2 to: self size - 1.
15 text := text copyReplaceAll: '\"' with: '"'.
16 text := text copyReplaceAll: '\n' with: '
17'.
18 text := text copyReplaceAll: '\\' with: '\'.
19 ^text
20 ]
21
22 repr [
23 |text|
24 text := self copyReplaceAll: '\' with: '\\'.
25 text := text copyReplaceAll: '
26' with: '\n'.
27 text := text copyReplaceAll: '"' with: '\"'.
28 ^'"', text, '"'
29 ]
30]
6da164bd
VS
31
32BlockClosure extend [
33 valueWithExit [
34 ^self value: [ ^nil ]
35 ]
65055aa2
VS
36]
37
c4a26e54
VS
38Object extend [
39 toMALValue [
40 self = true ifTrue: [ ^MALObject True ].
41 self = false ifTrue: [ ^MALObject False ].
42 self = nil ifTrue: [ ^MALObject Nil ].
43 self isNumber ifTrue: [ ^MALNumber new: self ].
44 self isString ifTrue: [ ^MALString new: self ].
45 self isSymbol ifTrue: [ ^MALSymbol new: self ].
46 self isArray ifTrue: [
47 ^MALVector new: (self asOrderedCollection collect:
48 [ :item | item toMALValue ])
49 ].
50 self isSequenceable ifTrue: [
51 ^MALList new: (self asOrderedCollection collect:
52 [ :item | item toMALValue ])
53 ].
54 self class = Dictionary ifTrue: [
55 | result |
56 result := Dictionary new.
57 self keysAndValuesDo: [ :key :value |
58 result at: key toMALValue put: value toMALValue
59 ].
60 ^MALMap new: result
61 ]
62 ]
63]
64
65055aa2
VS
65"NOTE: bugfix version from 3.2.91 for 3.2.4"
66Namespace current: Kernel [
67
68MatchingRegexResults extend [
69 at: anIndex [
70 <category: 'accessing'>
71 | reg text |
72 anIndex = 0 ifTrue: [^self match].
73 cache isNil ifTrue: [cache := Array new: registers size].
74 (cache at: anIndex) isNil
75 ifTrue:
76 [reg := registers at: anIndex.
77 text := reg isNil
78 ifTrue: [nil]
79 ifFalse: [
80 reg isEmpty
81 ifTrue: ['']
82 ifFalse: [self subject copyFrom: reg first to: reg last]].
83 cache at: anIndex put: text].
84 ^cache at: anIndex
85 ]
86]
58e44bbb 87
6da164bd 88]