[BUG] [ENH] [FIX] Misc small features and bugfixes
Scott A Crosby
crosby at qwes.math.cmu.edu
Sat Sep 29 10:11:10 UTC 2001
A variety of small changes to the system.
- Small documentation fixes,
- Fixing a buglet in creating ReadWriteStreams with on:.
- Giving Writestream an understanding of lf/crlf messages.
- Giving Socket a lowlevel try-to-send-data function
- Giving SharedQueue the ability to safetly check its size with critical
sections.
- More flexible CharacterSet generation, and more predefined
charactersets.
- Giving String a 'indexOf:startingAt:endingAt:' function. [*]
[*] The corresponding indexOf:startingAt function is automatically built
as a plugin. This should be added into the string utilities plugin.
Scott
--
No DVD movie will ever enter the public domain, nor will any CD. The last CD
and the last DVD will have moldered away decades before they leave copyright.
This is not encouraging the creation of knowledge in the public domain.
-------------- next part --------------
'From Squeak3.1alpha of 7 March 2001 [latest update: #4343] on 29 September 2001 at 5:51:12 am'!
!CharacterSet class methodsFor: 'instance creation' stamp: 'sac 9/22/2001 02:25'!
allAlphabetic
"return a set containing only alphabetic characters"
^self allMatching: [ :char | char isLetter].
! !
!CharacterSet class methodsFor: 'instance creation' stamp: 'sac 9/22/2001 02:23'!
allCharacters
"return a set containing all characters"
^self allMatching: [ :unused | true ]! !
!CharacterSet class methodsFor: 'instance creation' stamp: 'sac 9/22/2001 02:25'!
allMatching: aBlock
"return a set containing all characters matching some predicate."
| set character |
set _ self empty.
0
to: 255
do: [:ascii |
character _ Character value: ascii.
(aBlock value: character)
ifTrue: [set add: character]].
^ set! !
!CharacterSet class methodsFor: 'instance creation' stamp: 'sac 9/22/2001 02:30'!
allNumerical
"return a set containing only alphabetic characters"
^ self
allMatching: [:char | char isDigit]! !
!SharedQueue methodsFor: 'testing' stamp: 'sac 8/9/2001 13:22'!
critical: aBlock
"Evaluate aBlock with the accessProtect semaphore held. Do NOT mutate the queue during aBlock."
"This is to allow variable operation based on the sharedqueue length, for example,
disabling writers when the queue gets too long
queue critical: [queue size > 10. ifTrue: self writerDisable wait]
And the writer runs
self wait.
self signal."
accessProtect critical: aBlock.
! !
!Socket methodsFor: 'sending-receiving' stamp: 'sac 9/24/2001 01:41'!
getData
"Get some data"
| buf bytesRead |
(self waitForDataUntil: Socket standardDeadline)
ifFalse: [self error: 'getData timeout'].
buf _ String new: 4096.
bytesRead _ self
primSocket: socketHandle
receiveDataInto: buf
startingAt: 1
count: buf size.
^ buf copyFrom: 1 to: bytesRead! !
!Socket methodsFor: 'sending-receiving' stamp: 'sac 9/24/2001 03:17'!
receiveDataInto: aStringOrByteArray at: starting
"Receive data into the given buffer and return the number of bytes
received. Note the given buffer may be only partially filled by the
received data."
^ self
primSocket: socketHandle
receiveDataInto: aStringOrByteArray
startingAt: starting
count: (aStringOrByteArray size - starting) + 1! !
!Socket methodsFor: 'sending-receiving' stamp: 'sac 9/29/2001 05:31'!
trySendSomeData: aStringOrByteArray startIndex: startIndex count: count
"Send up to count bytes of the given data starting at the given index.
Answer the number of bytes actually sent. Do not do any timeouts for data not sent."
"Note: This operation may have to be repeated multiple times to send a
large amount of data."
^ self
primSocket: socketHandle
sendData: aStringOrByteArray
startIndex: startIndex
count: count! !
!String methodsFor: 'accessing' stamp: 'sac 9/24/2001 05:31'!
indexOf: aCharacter startingAt: start endingAt: end
aCharacter class == Character
ifFalse: [^ 0].
^ String
indexOfAscii: aCharacter asciiValue
inString: self
startingAt: start
endingAt: (end min: self size)! !
!String class methodsFor: 'primitives' stamp: 'sac 9/24/2001 05:32'!
indexOfAscii: anInteger inString: aString startingAt: start endingAt: end
| stringSize |
self var: #aCharacter declareC: 'int anInteger'.
self var: #aString declareC: 'unsigned char *aString'.
stringSize _ aString size min: end.
start
to: stringSize
do: [:pos | (aString at: pos) asciiValue = anInteger
ifTrue: [^ pos]].
^ 0! !
!UndefinedObject methodsFor: 'testing' stamp: 'sac 9/24/2001 07:12'!
isNil
"Refer to the comment in ProtoObject|isNil."
^ true! !
!WriteStream methodsFor: 'character writing' stamp: 'sac 8/10/2001 15:01'!
crlf
"Append a return character to the receiver."
self nextPut: Character cr.
self nextPut: Character lf.! !
!WriteStream methodsFor: 'character writing' stamp: 'sac 8/10/2001 15:00'!
lf
"Append a return character to the receiver."
self nextPut: Character lf! !
!ReadWriteStream methodsFor: 'accessing' stamp: 'sac 9/24/2001 03:47'!
on: aCollection
super on: aCollection.
readLimit _ aCollection size.
! !
More information about the Squeak-dev
mailing list
|