73 lines
2.8 KiB
Smalltalk
73 lines
2.8 KiB
Smalltalk
|
"This is from Pharo 1.4. It is MIT licensed"
|
||
|
|
||
|
String extend [
|
||
|
|
||
|
expandMacros [
|
||
|
<category: '*OsmoCore-FromPharo'>
|
||
|
^self expandMacrosWithArguments: #()
|
||
|
]
|
||
|
|
||
|
expandMacrosWith: anObject [
|
||
|
<category: '*OsmoCore-FromPharo'>
|
||
|
^self expandMacrosWithArguments: (Array with: anObject)
|
||
|
]
|
||
|
|
||
|
expandMacrosWith: anObject with: anotherObject [
|
||
|
<category: '*OsmoCore-FromPharo'>
|
||
|
^self
|
||
|
expandMacrosWithArguments: (Array with: anObject with: anotherObject)
|
||
|
]
|
||
|
|
||
|
expandMacrosWith: anObject with: anotherObject with: thirdObject [
|
||
|
<category: '*OsmoCore-FromPharo'>
|
||
|
^self expandMacrosWithArguments: (Array
|
||
|
with: anObject
|
||
|
with: anotherObject
|
||
|
with: thirdObject)
|
||
|
]
|
||
|
|
||
|
expandMacrosWith: anObject with: anotherObject with: thirdObject with: fourthObject [
|
||
|
<category: '*OsmoCore-FromPharo'>
|
||
|
^self expandMacrosWithArguments: (Array
|
||
|
with: anObject
|
||
|
with: anotherObject
|
||
|
with: thirdObject
|
||
|
with: fourthObject)
|
||
|
]
|
||
|
|
||
|
expandMacrosWithArguments: anArray [
|
||
|
<category: '*OsmoCore-FromPharo'>
|
||
|
| newStream readStream char index |
|
||
|
newStream := (String new: self size) writeStream.
|
||
|
readStream := self readStream.
|
||
|
[ readStream atEnd ] whileFalse:
|
||
|
[ char := readStream next.
|
||
|
char == $<
|
||
|
ifTrue:
|
||
|
[ | nextChar |
|
||
|
nextChar := readStream next asUppercase.
|
||
|
nextChar == $N ifTrue: [ newStream nl ].
|
||
|
nextChar == $T ifTrue: [ newStream tab ].
|
||
|
nextChar isDigit ifTrue:
|
||
|
[ index := nextChar digitValue.
|
||
|
|
||
|
[ readStream atEnd or: [ (nextChar := readStream next asUppercase) isDigit not ] ] whileFalse: [ index := index * 10 + nextChar digitValue ] ].
|
||
|
nextChar == $? ifTrue:
|
||
|
[ | trueString falseString |
|
||
|
trueString := readStream upTo: $:.
|
||
|
falseString := readStream upTo: $>.
|
||
|
readStream position: readStream position - 1.
|
||
|
newStream nextPutAll: ((anArray at: index)
|
||
|
ifTrue: [ trueString ]
|
||
|
ifFalse: [ falseString ]) ].
|
||
|
nextChar == $P ifTrue: [ newStream nextPutAll: (anArray at: index) printString ].
|
||
|
nextChar == $S ifTrue: [ newStream nextPutAll: (anArray at: index) ].
|
||
|
readStream skipTo: $> ]
|
||
|
ifFalse:
|
||
|
[ newStream nextPut: (char == $%
|
||
|
ifTrue: [ readStream next ]
|
||
|
ifFalse: [ char ]) ] ].
|
||
|
^ newStream contents
|
||
|
]
|
||
|
]
|