2011-02-19 19:37:35 +00:00
|
|
|
Collection extend [
|
2011-02-18 11:31:26 +00:00
|
|
|
beginsWith: aString [
|
|
|
|
<category: '*soapopera-core'>
|
|
|
|
|
|
|
|
"This comes from Pharo 1.1 and is on SequencableCollection"
|
|
|
|
"Answer true if the receiver starts with the argument collection"
|
|
|
|
(aString isEmpty or: [self size < aString size]) ifTrue: [^false].
|
|
|
|
aString withIndexDo: [:each :index | (self at: index) ~= each ifTrue: [^false]].
|
|
|
|
^true
|
|
|
|
]
|
|
|
|
|
|
|
|
withIndexDo: elementAndIndexBlock [
|
|
|
|
<category: '*soapopera-core'>
|
|
|
|
"This comes from Pharo 1.1 and is on SequencableCollection"
|
|
|
|
"Just like with:do: except that the iteration index supplies the second argument to the block."
|
|
|
|
1 to: self size do:
|
|
|
|
[:index |
|
|
|
|
elementAndIndexBlock
|
|
|
|
value: (self at: index)
|
|
|
|
value: index]
|
|
|
|
]
|
2011-02-19 19:37:35 +00:00
|
|
|
|
|
|
|
ifEmpty: aBlock [
|
|
|
|
<category: '*soapopera-core'>
|
|
|
|
self isEmpty ifTrue: [^ aBlock value]
|
|
|
|
]
|
|
|
|
|
|
|
|
isEmptyOrNil [
|
|
|
|
<category: '*soapopera-core'>
|
|
|
|
^ self isEmpty
|
|
|
|
]
|
2011-02-20 17:56:49 +00:00
|
|
|
|
|
|
|
ifNotEmptyDo: aBlock [
|
|
|
|
<category: '*soapopera-core'>
|
|
|
|
"Evaluate the given block with the receiver as its argument."
|
|
|
|
|
|
|
|
self isEmpty ifFalse: [^ aBlock value: self].
|
|
|
|
]
|
2011-02-26 23:51:22 +00:00
|
|
|
|
|
|
|
copyWithoutAll: aCollection [
|
|
|
|
"Answer a copy of the receiver that does not contain any elements
|
|
|
|
equal to those in aCollection."
|
|
|
|
|
|
|
|
^ self reject: [:each | aCollection includes: each]
|
|
|
|
]
|
2011-02-19 19:37:35 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
String extend [
|
|
|
|
findString: subString startingAt: aStart [
|
|
|
|
| res start |
|
|
|
|
<category: '*soapopera-core'>
|
|
|
|
"This comes from Pharo 1.1 and is on String"
|
|
|
|
"Answer the index of subString within the receiver, starting at start. If
|
|
|
|
the receiver does not contain subString, answer 0."
|
|
|
|
|
|
|
|
start := aStart = 0 ifTrue: [1] ifFalse: [aStart].
|
|
|
|
res := self indexOf: subString matchCase: true startingAt: start.
|
|
|
|
|
|
|
|
res ifNil: [^ 0]
|
|
|
|
ifNotNil: [^ res first]
|
|
|
|
]
|
2011-02-20 08:46:34 +00:00
|
|
|
|
|
|
|
base64Encoded [
|
|
|
|
<category: '*network-mime'>
|
|
|
|
"Encode the receiver as base64"
|
|
|
|
"'Hello World' base64Encoded"
|
|
|
|
^(Base64MimeConverter mimeEncode: self readStream) contents
|
|
|
|
]
|
|
|
|
|
|
|
|
base64Decoded [
|
|
|
|
<category: '*network-mime'>
|
|
|
|
"Decode the receiver from base 64"
|
|
|
|
"'SGVsbG8gV29ybGQ=' base64Decoded"
|
|
|
|
^(Base64MimeConverter mimeDecode: self as: self class)
|
|
|
|
]
|
2011-02-26 23:51:22 +00:00
|
|
|
|
|
|
|
withFirstCharacterDownshifted [
|
|
|
|
"Return a copy with the first letter downShifted"
|
|
|
|
| answer |
|
|
|
|
|
|
|
|
self ifEmpty: [^ self copy].
|
|
|
|
answer := self copy.
|
|
|
|
answer at: 1 put: (answer at: 1) asLowercase.
|
|
|
|
^ answer.
|
|
|
|
]
|
2011-02-20 08:46:34 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
ByteArray extend [
|
|
|
|
base64Encoded [
|
|
|
|
<category: '*network-mime'>
|
|
|
|
"Encode the receiver as base64"
|
|
|
|
"'Hello World' base64Encoded"
|
|
|
|
^(Base64MimeConverter mimeEncode: self readStream) contents
|
|
|
|
]
|
|
|
|
|
2011-02-19 19:37:35 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
UndefinedObject extend [
|
|
|
|
isEmptyOrNil [
|
|
|
|
<category: '*soapopera-core'>
|
|
|
|
^ true
|
|
|
|
]
|
2011-02-18 11:31:26 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
Character extend [
|
|
|
|
charCode [
|
|
|
|
<category: '*soapopera-core'>
|
|
|
|
^ codePoint
|
|
|
|
]
|
|
|
|
]
|
2011-02-26 23:51:22 +00:00
|
|
|
|
|
|
|
DateTime extend [
|
|
|
|
DateTime class >> fromString: aString [
|
|
|
|
^ self readFrom: aString readStream.
|
|
|
|
]
|
|
|
|
|
|
|
|
asString [
|
|
|
|
^ String streamContents: [:stream | self printOn: stream]
|
|
|
|
]
|
|
|
|
]
|