Pharo-dev
By thread
pharo-dev@lists.pharo.org
By month
Messages by month
- ----- 2026 -----
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
November 2010
- 115 participants
- 1614 messages
Re: [Pharo-project] Issue 3348 in pharo: use #shouldBePrintedAsLiteral instead of #isLiteral when printing or storing characters and arrays
by pharo@googlecode.com
Comment #1 on issue 3348 by stephane.ducasse: use #shouldBePrintedAsLiteral
instead of #isLiteral when printing or storing characters and arrays
http://code.google.com/p/pharo/issues/detail?id=3348
- introduced Object >> #shouldBePrintedAsLiteral as a replacement for
#isLiteral during printing and storing
=============== Diff against Kernel-dtl.517 ===============
Item was added:
+ ----- Method: Object>>shouldBePrintedAsLiteral (in category 'testing')
-----
+ shouldBePrintedAsLiteral
+
+ ^self isLiteral!
Item was changed:
----- Method: ScaledDecimal>>storeOn: (in category 'printing') -----
storeOn: aStream
"SxaledDecimal sometimes have more digits than they print
(potentially an infinity).
In this case, do not use printOn: because it would loose some extra
digits"
+ self shouldBePrintedAsLiteral
- self isLiteral
ifTrue: [self printOn: aStream]
ifFalse: [aStream
nextPut: $(;
store: fraction numerator;
nextPut: $/;
store: fraction denominator;
nextPut: $s;
store: scale;
nextPut: $)]!
Nov. 27, 2010
[Pharo-project] Issue 3348 in pharo: use #shouldBePrintedAsLiteral instead of #isLiteral when printing or storing characters and arrays
by pharo@googlecode.com
Status: FixedWaitingToBePharoed
Owner: stephane.ducasse
Labels: Milestone-1.3 Difficulty-Easy
New issue 3348 by stephane.ducasse: use #shouldBePrintedAsLiteral instead
of #isLiteral when printing or storing characters and arrays
http://code.google.com/p/pharo/issues/detail?id=3348
A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-ul.411.mcz
==================== Summary ====================
Name: Collections-ul.411
Author: ul
Time: 23 November 2010, 1:56:22.424 pm
UUID: 42a0b87a-f525-6345-bd2c-e55186e17c9d
Ancestors: Collections-ul.410
- use #shouldBePrintedAsLiteral instead of #isLiteral when printing or
storing characters and arrays
=============== Diff against Collections-ul.410 ===============
Item was changed:
----- Method: Array>>printOn: (in category 'printing') -----
printOn: aStream
+ self shouldBePrintedAsLiteral ifTrue: [^self printAsLiteralFormOn:
aStream].
- self isLiteral ifTrue: [^self printAsLiteralFormOn: aStream].
self class = Array ifTrue: [^self printAsBraceFormOn: aStream].
^super printOn: aStream!
Item was added:
+ ----- Method: Array>>shouldBePrintedAsLiteral (in category 'testing')
-----
+ shouldBePrintedAsLiteral
+
+ ^self class == Array and: [ self allSatisfy: [ :each | each
shouldBePrintedAsLiteral ] ]!
Item was changed:
----- Method: Array>>storeOn: (in category 'printing') -----
storeOn: aStream
"Use the literal form if possible."
+ self shouldBePrintedAsLiteral
- self isLiteral
ifTrue:
[aStream nextPut: $#; nextPut: $(.
self do:
[:element |
element storeOn: aStream.
aStream space].
aStream nextPut: $)]
ifFalse: [super storeOn: aStream]!
Item was changed:
----- Method: Array>>storeOnStream: (in category 'filter streaming') -----
storeOnStream:aStream
+
+ self shouldBePrintedAsLiteral
+ ifTrue: [ super storeOnStream:aStream ]
+ ifFalse:[ aStream writeCollection:self ]
- self isLiteral ifTrue: [super storeOnStream:aStream]
ifFalse:[aStream writeCollection:self].
!
Item was changed:
+ ----- Method: Character>>isLiteral (in category 'testing') -----
- ----- Method: Character>>isLiteral (in category 'printing') -----
isLiteral
^true!
Item was added:
+ ----- Method: Character>>shouldBePrintedAsLiteral (in category 'testing')
-----
+ shouldBePrintedAsLiteral
+
+ ^value between: 33 and: 255!
Item was changed:
----- Method: Character>>storeOn: (in category 'printing') -----
storeOn: aStream
"Common character literals are preceded by '$', however special need
to be encoded differently: for some this might be done by using one of the
shortcut constructor methods for the rest we have to create them by
ascii-value."
| name |
+ self shouldBePrintedAsLiteral
- (value between: 33 and: 255)
ifTrue: [ aStream nextPut: $$; nextPut: self ]
ifFalse: [
name := self class constantNameFor: self.
name notNil
ifTrue: [ aStream nextPutAll: self class
name; space; nextPutAll: name ]
ifFalse: [
aStream
nextPut: $(; nextPutAll:
self class name;
nextPutAll: ' value: ';
print: value; nextPut: $) ] ].!
Nov. 27, 2010
Re: [Pharo-project] Issue 3347 in pharo: simplified and unified String's line-ending changing methods
by pharo@googlecode.com
Comment #1 on issue 3347 by stephane.ducasse: simplified and unified
String's line-ending changing methods
http://code.google.com/p/pharo/issues/detail?id=3347
Levente Uzonyi uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.410.mcz
==================== Summary ====================
Name: Collections-ul.410
Author: ul
Time: 23 November 2010, 8:24:12.434 am
UUID: a68748b5-3380-9645-8686-fc80a9710dc6
Ancestors: Collections-ul.409
- added a translation table to String for exchanging cr and lf characters
- simplified and enhanced String's #withSqueakLineEndings and
#withUnixLineEndings
=============== Diff against Collections-ul.409 ===============
Item was changed:
ArrayedCollection subclass: #String
instanceVariableNames: ''
+ classVariableNames: 'AsciiOrder CSLineEnders CSNonSeparators
CSSeparators CaseInsensitiveOrder CaseSensitiveOrder CrLfExchangeTable
HtmlEntities LowercasingTable Tokenish UppercasingTable'
- classVariableNames: 'AsciiOrder CSLineEnders CSNonSeparators
CSSeparators CaseInsensitiveOrder CaseSensitiveOrder HtmlEntities
LowercasingTable Tokenish UppercasingTable'
poolDictionaries: ''
category: 'Collections-Strings'!
!String commentStamp: '<historical>' prior: 0!
A String is an indexed collection of Characters. Class String provides the
abstract super class for ByteString (that represents an array of 8-bit
Characters) and WideString (that represents an array of 32-bit
characters). In the similar manner of LargeInteger and SmallInteger, those
subclasses are chosen accordingly for a string; namely as long as the
system can figure out so, the String is used to represent the given string.
Strings support a vast array of useful methods, which can best be learned
by browsing and trying out examples as you find them in the code.
Here are a few useful methods to look at...
String match:
String contractTo:
String also inherits many useful methods from its hierarchy, such as
SequenceableCollection ,
SequenceableCollection copyReplaceAll:with:
!
Item was added:
+ ----- Method: String class>>crLfExchangeTable (in category 'accessing')
-----
+ crLfExchangeTable
+
+ ^CrLfExchangeTable!
Item was changed:
----- Method: String class>>initialize (in category 'initialization') -----
initialize "self initialize"
| order |
AsciiOrder := (0 to: 255) as: ByteArray.
CaseInsensitiveOrder := AsciiOrder copy.
($a to: $z) do:
[:c | CaseInsensitiveOrder at: c asciiValue + 1
put: (CaseInsensitiveOrder at: c asUppercase
asciiValue +1)].
"Case-sensitive compare sorts space, digits, letters, all the
rest..."
CaseSensitiveOrder := ByteArray new: 256 withAll: 255.
order := -1.
' 0123456789' do: "0..10"
[:c | CaseSensitiveOrder at: c asciiValue + 1 put: (order :=
order+1)].
($a to: $z) do: "11-64"
[:c | CaseSensitiveOrder at: c asUppercase asciiValue + 1
put: (order := order+1).
CaseSensitiveOrder at: c asciiValue + 1 put: (order :=
order+1)].
1 to: CaseSensitiveOrder size do:
[:i | (CaseSensitiveOrder at: i) = 255 ifTrue:
[CaseSensitiveOrder at: i put: (order := order+1)]].
order = 255 ifFalse: [self error: 'order problem'].
"a table for translating to lower case"
LowercasingTable := String withAll: (Character allByteCharacters
collect: [:c | c asLowercase]).
"a table for translating to upper case"
UppercasingTable := String withAll: (Character allByteCharacters
collect: [:c | c asUppercase]).
"a table for testing tokenish (for fast numArgs)"
Tokenish := String withAll: (Character allByteCharacters collect:
[:c
| c tokenish ifTrue: [c] ifFalse: [$~]]).
"CR and LF--characters that terminate a line"
CSLineEnders := CharacterSet crlf.
"separators and non-separators"
CSSeparators := CharacterSet separators.
+ CSNonSeparators := CSSeparators complement.
+
+ "a table for exchanging cr with lf and vica versa"
+ CrLfExchangeTable := Character allByteCharacters collect: [ :each |
+ each
+ caseOf: {
+ [ Character cr ] -> [ Character lf ].
+ [ Character lf ] -> [ Character cr ] }
+ otherwise: [ each ] ]!
- CSNonSeparators := CSSeparators complement.!
Item was changed:
----- Method: String>>withSqueakLineEndings (in category 'internet') -----
withSqueakLineEndings
"Assume the string is textual, and that CR, LF, and CRLF are all
valid line endings.
Replace each occurence with a single CR."
- | cr lf indexLF indexCR |
- lf := Character linefeed.
- indexLF := self indexOf: lf startingAt: 1.
- indexLF = 0 ifTrue: [^self].
-
- cr := Character cr.
- indexCR := self indexOf: cr startingAt: 1.
- indexCR = 0 ifTrue: [^self copy replaceAll: lf with: cr].
+ (self includes: Character lf) ifFalse: [ ^self ].
+ (self includes: Character cr) ifFalse: [
+ ^self translateWith: String crLfExchangeTable ].
^self withLineEndings: String cr!
Item was changed:
----- Method: String>>withUnixLineEndings (in category 'internet') -----
withUnixLineEndings
"Assume the string is textual, and that CR, LF, and CRLF are all
valid line endings.
Replace each occurence with a single LF."
- | cr lf indexLF indexCR |
- cr := Character cr.
- indexCR := self indexOf: cr startingAt: 1.
- indexCR = 0 ifTrue: [^self].
-
- lf := Character linefeed.
- indexLF := self indexOf: lf startingAt: 1.
- indexLF = 0 ifTrue: [^self copy replaceAll: cr with: lf].
+ (self includes: Character cr) ifFalse: [ ^self ].
+ (self includes: Character lf) ifFalse: [
+ ^self translateWith: String crLfExchangeTable ].
^self withLineEndings: String lf!
Nov. 27, 2010
[Pharo-project] Issue 3347 in pharo: simplified and unified String's line-ending changing methods
by pharo@googlecode.com
Status: FixedWaitingToBePharoed
Owner: stephane.ducasse
Labels: Milestone-1.3 Type-Squeak
New issue 3347 by stephane.ducasse: simplified and unified String's
line-ending changing methods
http://code.google.com/p/pharo/issues/detail?id=3347
Levente Uzonyi uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.409.mcz
==================== Summary ====================
Name: Collections-ul.409
Author: ul
Time: 22 November 2010, 1:35:14.026 pm
UUID: 849eb41a-5717-9e44-ab23-eae36fb603bb
Ancestors: Collections-ul.408
- introduced String >> #withLineEndings:
- simplified and unified String's line-ending changing methods:
#withInternetLineEndings, #withSqueakLineEndings and #withUnixLineEndings
=============== Diff against Collections-ul.408 ===============
Item was changed:
----- Method: String>>withInternetLineEndings (in category 'internet')
-----
withInternetLineEndings
"change line endings from CR's and LF's to CRLF's. This is probably
in prepration for sending a string over the Internet"
+ ^self withLineEndings: String crlf!
- ^self class
- new: self size * 16 // 15 "provisions for CR-LF pairs"
- streamContents: [ :stream |
- self lineIndicesDo:
[:start :endWithoutDelimiters :end |
- stream next: 1 + endWithoutDelimiters -
start putAll: self startingAt: start.
- endWithoutDelimiters = end ifFalse: [
- stream crlf ] ] ]!
Item was added:
+ ----- Method: String>>withLineEndings: (in category 'internet') -----
+ withLineEndings: lineEndingString
+
+ | stream |
+ stream := nil.
+ self lineIndicesDo: [ :start :endWithoutDelimiters :end |
+ (stream isNil and: [ endWithoutDelimiters ~= end ]) ifTrue:
[
+ (self copyFrom: endWithoutDelimiters + 1 to: end) =
lineEndingString ifFalse: [
+ stream := WriteStream with: self copy.
+ stream position: start - 1 ] ].
+ stream ifNotNil: [
+ stream next: endWithoutDelimiters - start + 1
putAll: self startingAt: start.
+ endWithoutDelimiters = end ifFalse: [
+ stream nextPutAll: lineEndingString ] ] ].
+ ^stream
+ ifNil: [ self ]
+ ifNotNil: [
+ stream position = self size
+ ifTrue: [ stream originalContents ]
+ ifFalse: [ stream contents ] ]!
Item was changed:
----- Method: String>>withSqueakLineEndings (in category 'internet') -----
withSqueakLineEndings
"Assume the string is textual, and that CR, LF, and CRLF are all
valid line endings.
Replace each occurence with a single CR."
+ | cr lf indexLF indexCR |
- | cr lf inPos outPos outString newOutPos indexLF indexCR |
lf := Character linefeed.
indexLF := self indexOf: lf startingAt: 1.
indexLF = 0 ifTrue: [^self].
cr := Character cr.
indexCR := self indexOf: cr startingAt: 1.
indexCR = 0 ifTrue: [^self copy replaceAll: lf with: cr].
+ ^self withLineEndings: String cr!
- inPos := outPos := 1.
- outString := String new: self size.
-
- ["check if next CR (if any) is before next LF"
- (indexCR > 0 and: [indexCR < indexLF])
- ifTrue: [
- newOutPos := outPos + 1 + indexCR - inPos.
- outString replaceFrom: outPos to: newOutPos - 1
with: self startingAt: inPos.
- outPos := newOutPos.
- 1 + indexCR = indexLF
- ifTrue: ["Caught a CR-LF pair"
- inPos := 1 + indexLF.
- indexLF := self indexOf: lf
startingAt: inPos]
- ifFalse: [inPos := 1 + indexCR].
- indexCR := self indexOf: cr startingAt: inPos]
- ifFalse: [
- newOutPos := outPos + 1 + indexLF - inPos.
- outString replaceFrom: outPos to: newOutPos - 2
with: self startingAt: inPos.
- outString at: newOutPos - 1 put: cr.
- outPos := newOutPos.
- inPos := 1 + indexLF.
- indexLF := self indexOf: lf startingAt: inPos].
- indexLF = 0]
- whileFalse.
-
- "no more LF line endings. copy the rest"
- newOutPos := outPos + (self size - inPos + 1).
- outString replaceFrom: outPos to: newOutPos - 1 with: self
startingAt: inPos.
- ^outString copyFrom: 1 to: newOutPos - 1!
Item was changed:
----- Method: String>>withUnixLineEndings (in category 'internet') -----
withUnixLineEndings
"Assume the string is textual, and that CR, LF, and CRLF are all
valid line endings.
Replace each occurence with a single LF."
+ | cr lf indexLF indexCR |
- | cr lf inPos outPos outString newOutPos indexLF indexCR |
cr := Character cr.
indexCR := self indexOf: cr startingAt: 1.
indexCR = 0 ifTrue: [^self].
lf := Character linefeed.
indexLF := self indexOf: lf startingAt: 1.
indexLF = 0 ifTrue: [^self copy replaceAll: cr with: lf].
+ ^self withLineEndings: String lf!
- inPos := outPos := 1.
- outString := String new: self size.
-
- ["check if next CR is before next LF or if there are no more LF"
- (indexLF = 0 or: [indexCR < indexLF])
- ifTrue: [
- newOutPos := outPos + 1 + indexCR - inPos.
- outString replaceFrom: outPos to: newOutPos - 2
with: self startingAt: inPos.
- outString at: newOutPos - 1 put: lf.
- outPos := newOutPos.
- 1 + indexCR = indexLF
- ifTrue: ["Caught a CR-LF pair"
- inPos := 1 + indexLF.
- indexLF := self indexOf: lf
startingAt: inPos]
- ifFalse: [inPos := 1 + indexCR].
- indexCR := self indexOf: cr startingAt: inPos]
- ifFalse: [
- newOutPos := outPos + 1 + indexLF - inPos.
- outString replaceFrom: outPos to: newOutPos - 1
with: self startingAt: inPos.
- outPos := newOutPos.
- inPos := 1 + indexLF.
- indexLF := self indexOf: lf startingAt: inPos].
- indexCR = 0]
- whileFalse.
-
- "no more CR line endings. copy the rest"
- newOutPos := outPos + (self size - inPos + 1).
- outString replaceFrom: outPos to: newOutPos - 1 with: self
startingAt: inPos.
- ^outString copyFrom: 1 to: newOutPos - 1!
Nov. 27, 2010
[Pharo-project] Issue 3346 in pharo: Socket bug fixes
by pharo@googlecode.com
Status: FixedWaitingToBePharoed
Owner: stephane.ducasse
Labels: Milestone-1.3
New issue 3346 by stephane.ducasse: Socket bug fixes
http://code.google.com/p/pharo/issues/detail?id=3346
Andreas Raab uploaded a new version of Network to project The Trunk:
http://source.squeak.org/trunk/Network-ar.98.mcz
==================== Summary ====================
Name: Network-ar.98
Author: ar
Time: 23 November 2010, 12:12:58.498 am
UUID: 5f0637f3-9b53-ab42-a6fa-55077db31f63
Ancestors: Network-ul.97
Fixes for SocketStream:
1) SocketStream>>receiveData: and SocketStream>>upToEnd: had incorrect
conditions used to determine when to stop (#isConnected is wrong since
there can be data pending on an unconnected socket which is why using
#atEnd is the correct test).
2) The former was done to deal with non-signaling SocketStreams in cases
where ConnectionClose was used to deal with end conditions (#upToEnd,
#next:into:startingAt:, #readInto:startingAt:count:). This was fixed by
making these places (temporarily) signaling so that the exception can be
caught and handled properly.
3) SocketStream>>isDataAvailable should not attempt to shortcut
prematurely; using 'socket dataAvailable' is bad for subclasses such as
SecureSocketStream and unnecessary to boot (and has no performance impact).
=============== Diff against Network-ul.97 ===============
Item was added:
+ ----- Method: SocketStream>>beSignalingWhile: (in category 'private')
-----
+ beSignalingWhile: aBlock
+ "Temporarily turn a non-signaling SocketStream into a signaling one.
+ Required for some of operations that will catch ConnectionClosed in
+ order to find out that an operation completed"
+
+ | signaling |
+ signaling := shouldSignal.
+ shouldSignal := true.
+ ^aBlock ensure:[shouldSignal := signaling]
+ !
Item was changed:
----- Method: SocketStream>>isDataAvailable (in category 'testing') -----
isDataAvailable
+ "Answer if more data can be read. It the inbuffer is empty, we read
more data.
- "Answer if more data can be read. It the inbuffer is empty, we
check the socket for data. If it claims to have data available to read, we
try to read some once and recursively call this method again. If something
really was available it is now in the inBuffer. This is because there has
been spurious dataAvailable when there really is no data to get.
+ Note: It is important not to rely on 'socket dataAvailable' here
since this will
+ not work for subclasses such as SecureSocketStream (which can
contain
+ undecrypted contents that has been read from the socket)."
- Note: Some subclasses (such as SecureSocketStream) rely on the
behavior here since even though data may be available in the underlying
socket, it may not result in any output (yet)."
self isInBufferEmpty ifFalse: [^true].
+ ^self receiveAvailableData < inNextToWrite
+ !
- ^socket dataAvailable
- ifFalse: [false]
- ifTrue: [self receiveAvailableData; isDataAvailable]!
Item was changed:
----- Method: SocketStream>>next:into:startingAt: (in category 'stream
in') -----
next: anInteger into: aCollection startingAt: startIndex
"Read n objects into the given collection.
Return aCollection or a partial copy if less than
n elements have been read."
"Implementation note: This method DOES signal timeout if not
enough elements are received. It does NOT signal
ConnectionClosed as closing the connection is the only way by
which partial data can be read."
| start amount |
+ [self beSignalingWhile:[self receiveData: anInteger]]
+ on: ConnectionClosed do:[:ex| ex return].
- [self receiveData: anInteger] on: ConnectionClosed do:[:ex| ex
return].
"Inlined version of nextInBuffer: to avoid copying the contents"
amount := anInteger min: (inNextToWrite - lastRead - 1).
start := lastRead + 1.
lastRead := lastRead + amount.
aCollection
replaceFrom: startIndex
to: startIndex + amount-1
with: inBuffer
startingAt: start.
^amount < anInteger
ifTrue:[aCollection copyFrom: 1 to: startIndex + amount-1]
ifFalse:[aCollection]!
Item was changed:
----- Method: SocketStream>>readInto:startingAt:count: (in
category 'stream in') -----
readInto: aCollection startingAt: startIndex count: anInteger
"Read n objects into the given collection starting at startIndex.
Return number of elements that have been read."
"Implementation note: This method DOES signal timeout if not
enough elements are received. It does NOT signal
ConnectionClosed as closing the connection is the only way by
which partial data can be read."
| start amount |
+ [self beSignalingWhile:[self receiveData: anInteger]]
+ on: ConnectionClosed do:[:ex| ex return].
- [self receiveData: anInteger] on: ConnectionClosed do:[:ex| ex
return].
"Inlined version of nextInBuffer: to avoid copying the contents"
amount := anInteger min: (inNextToWrite - lastRead - 1).
start := lastRead + 1.
lastRead := lastRead + amount.
aCollection
replaceFrom: startIndex
to: startIndex + amount-1
with: inBuffer
startingAt: start.
^amount!
Item was changed:
----- Method: SocketStream>>receiveData: (in category 'control') -----
receiveData: nBytes
"Keep reading the socket until we have nBytes
in the inBuffer or we reach the end. This method
does not return data, but can be used to make sure
data has been read into the buffer from the Socket
before actually reading it from the FastSocketStream.
Mainly used internally. We could also adjust the buffer
to the expected amount of data and avoiding several
incremental grow operations.
NOTE: This method doesn't honor timeouts if shouldSignal
is false!! And frankly, I am not sure how to handle that
case or if I care - I think we should always signal."
+ [self atEnd not and: [nBytes > self inBufferSize]]
- [self isConnected and: [nBytes > self inBufferSize]]
whileTrue: [self receiveData]!
Item was changed:
----- Method: SocketStream>>upToEnd (in category 'stream in') -----
upToEnd
"Answer all data coming in on the socket until the socket
is closed by the other end, or we get a timeout.
+ This means this method catches ConnectionClosed by itself."
- This means this method catches ConnectionClosed by itself.
-
- NOTE: Does not honour timeouts if shouldSignal is false!!"
+ [[self atEnd] whileFalse: [self beSignalingWhile:[self
receiveData]]]
- [[self isConnected] whileTrue: [self receiveData]]
on: ConnectionClosed
do: [:ex | "swallow it"].
^self nextAllInBuffer!
Nov. 27, 2010
[Pharo-project] Issue 3345 in pharo: findBinary: from Cuis as integrated in Squeak
by pharo@googlecode.com
Status: FixedWaitingToBePharoed
Owner: stephane.ducasse
Labels: Milestone-1.3 Difficulty-Easy
New issue 3345 by stephane.ducasse: findBinary: from Cuis as integrated in
Squeak
http://code.google.com/p/pharo/issues/detail?id=3345
It would be nice to have a look at that and write some tests
Levente Uzonyi uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.408.mcz
==================== Summary ====================
Name: Collections-ul.408
Author: ul
Time: 17 November 2010, 12:25:59.364 pm
UUID: 1520a654-9c34-734d-ae16-a600d1a2b948
Ancestors: Collections-ul.407
- findBinary* enhancements from Cuis.
=============== Diff against Collections-ul.407 ===============
Item was changed:
----- Method: SequenceableCollection>>findBinary: (in
category 'enumerating') -----
findBinary: aBlock
"Search for an element in the receiver using binary search.
The argument aBlock is a one-element block returning
0 - if the element is the one searched for
<0 - if the search should continue in the first half
>0 - if the search should continue in the second half
If no matching element is found, raise an error.
Examples:
+ #(1 3 5 7 11 15 23) findBinary: [ :arg | 11 - arg ]
- #(1 3 5 7 11 15 23) findBinary:[:arg| 11 - arg]
"
+ ^self findBinary: aBlock do: [ :found | found ] ifNone: [ self
errorNotFound: aBlock ]!
- ^self findBinary: aBlock ifNone: [self errorNotFound: aBlock]!
Item was added:
+ ----- Method: SequenceableCollection>>findBinary:do:ifNone: (in
category 'enumerating') -----
+ findBinary: aBlock do: actionBlock ifNone: exceptionBlock
+ "Search for an element in the receiver using binary search.
+ The argument aBlock is a one-element block returning
+ 0 - if the element is the one searched for
+ <0 - if the search should continue in the first half
+ >0 - if the search should continue in the second half
+ If found, evaluate actionBlock with the found element as argument
+ If no matching element is found, evaluate exceptionBlock,
+ with the 'bounding' elements (or nil) as optional arguments.
+ Examples:
+ #(1 3 5 7 11 15 23)
+ findBinary: [ :arg | 11 - arg ]
+ do: [ :found | found ]
+ ifNone: [ :a :b | ('between: ', {a. b} printString)
]
+ #(1 3 5 7 11 15 23)
+ findBinary: [ :arg | 12 - arg ]
+ do: [ :found | found ]
+ ifNone: [ :a :b | ('between: ', {a. b} printString)
]
+ #(1 3 5 7 11 15 23)
+ findBinary: [ :arg | 0.5 - arg ]
+ do: [ :found | found ]
+ ifNone: [ :a :b | ('between: ', {a. b} printString)
]
+ #(1 3 5 7 11 15 23)
+ findBinary: [ :arg | 25 - arg ]
+ do: [ :found | found ]
+ ifNone: [ :a :b | ('between: ',{a. b} printString) ]
+ "
+ ^self
+ findBinaryIndex: aBlock
+ do: [ :foundIndex | actionBlock value: (self at:
foundIndex) ]
+ ifNone: [ :prevIndex :nextIndex |
+ exceptionBlock
+ cull: (prevIndex > 0 ifTrue: [ self at:
prevIndex ])
+ cull: (nextIndex <= self size ifTrue: [
self at: nextIndex ]) ]!
Item was changed:
----- Method: SequenceableCollection>>findBinary:ifNone: (in
category 'enumerating') -----
findBinary: aBlock ifNone: exceptionBlock
"Search for an element in the receiver using binary search.
The argument aBlock is a one-element block returning
0 - if the element is the one searched for
<0 - if the search should continue in the first half
>0 - if the search should continue in the second half
+ If no matching element is found, evaluate exceptionBlock,
+ with the 'bounding' elements (or nil) as optional arguments."
+
+ ^self findBinary: aBlock do: [ :found | found ] ifNone:
exceptionBlock!
- If no matching element is found, evaluate exceptionBlock."
- | index low high test item |
- low := 1.
- high := self size.
- [index := high + low // 2.
- low > high] whileFalse:[
- test := aBlock value: (item := self at: index).
- test = 0
- ifTrue:[^item]
- ifFalse:[test > 0
- ifTrue: [low := index + 1]
- ifFalse: [high := index - 1]]].
- ^exceptionBlock value!
Item was changed:
----- Method: SequenceableCollection>>findBinaryIndex: (in
category 'enumerating') -----
findBinaryIndex: aBlock
"Search for an element in the receiver using binary search.
The argument aBlock is a one-element block returning
0 - if the element is the one searched for
<0 - if the search should continue in the first half
>0 - if the search should continue in the second half
If no matching element is found, raise an error.
Examples:
+ #(1 3 5 7 11 15 23) findBinaryIndex: [ :arg | 11 - arg ]
- #(1 3 5 7 11 15 23) findBinaryIndex:[:arg| 11 - arg]
"
+ ^self findBinaryIndex: aBlock do: [ :found | found ] ifNone: [ self
errorNotFound: aBlock]!
- ^self findBinaryIndex: aBlock ifNone: [self errorNotFound: aBlock]!
Item was added:
+ ----- Method: SequenceableCollection>>findBinaryIndex:do:ifNone: (in
category 'enumerating') -----
+ findBinaryIndex: aBlock do: actionBlock ifNone: exceptionBlock
+ "Search for an element in the receiver using binary search.
+ The argument aBlock is a one-element block returning
+ 0 - if the element is the one searched for
+ <0 - if the search should continue in the first half
+ >0 - if the search should continue in the second half
+ If found, evaluate actionBlock with the index as argument
+ If no matching element is found, evaluate exceptionBlock,
+ with the indexes of the 'bounding' elements as optional
+ arguments. Warning: Might give invalid indexes, see
+ examples below.
+ Examples:
+ #(1 3 5 7 11 15 23)
+ findBinaryIndex: [ :arg | 11 - arg ]
+ do: [ :found | found ]
+ ifNone: [ :a :b | ('between: ', {a. b} printString)]
+ #(1 3 5 7 11 15 23)
+ findBinaryIndex: [ :arg | 12 - arg ]
+ do: [ :found | found ]
+ ifNone: [ :a :b | ('between: ', {a. b} printString)
]
+ #(1 3 5 7 11 15 23) d
+ findBinaryIndex: [ :arg | 0.5 - arg ]
+ do: [ :found | found ]
+ ifNone: [ :a :b | ('between: ', {a. b} printString)
]
+ #(1 3 5 7 11 15 23)
+ findBinaryIndex: [ :arg | 25 - arg ]
+ do: [ :found | found ]
+ ifNone: [ :a :b | ('between: ',{a. b} printString) ]
+ "
+ | index low high |
+ low := 1.
+ high := self size.
+ [
+ index := high + low // 2.
+ low > high ] whileFalse: [
+ | test |
+ test := aBlock value: (self at: index).
+ test = 0
+ ifTrue: [ ^actionBlock value: index ]
+ ifFalse: [ test > 0
+ ifTrue: [ low := index + 1 ]
+ ifFalse: [ high := index - 1 ] ] ].
+ ^exceptionBlock cull: high cull: low!
Item was changed:
----- Method: SequenceableCollection>>findBinaryIndex:ifNone: (in
category 'enumerating') -----
findBinaryIndex: aBlock ifNone: exceptionBlock
"Search for an element in the receiver using binary search.
The argument aBlock is a one-element block returning
0 - if the element is the one searched for
<0 - if the search should continue in the first half
>0 - if the search should continue in the second half
+ If no matching element is found, evaluate exceptionBlock,
+ with the indexes of the 'bounding' elements as optional
+ arguments. Warning: Might give invalid indexes."
+
+ ^self findBinaryIndex: aBlock do: [ :found | found ] ifNone:
exceptionBlock!
- If no matching element is found, evaluate exceptionBlock."
- | index low high test |
- low := 1.
- high := self size.
- [index := high + low // 2.
- low > high] whileFalse:[
- test := aBlock value: (self at: index).
- test = 0
- ifTrue:[^index]
- ifFalse:[test > 0
- ifTrue: [low := index + 1]
- ifFalse: [high := index - 1]]].
- ^exceptionBlock value!
Nov. 27, 2010
[Pharo-project] Issue 3344 in pharo: No brainer fix for hasBindingThatBeginWith:
by pharo@googlecode.com
Status: Fixed
Owner: stephane.ducasse
Labels: Milestone-1.2
New issue 3344 by stephane.ducasse: No brainer fix for
hasBindingThatBeginWith:
http://code.google.com/p/pharo/issues/detail?id=3344
SystemDictionary>>hasBindingThatBeginsWith: aString
"Use the cached class and non-class names for better performance."
| name searchBlock |
searchBlock := [ :element |
(element beginsWith: aString)
ifTrue: [ 0 ]
ifFalse: [
aString < element
ifTrue: [ -1 ]
ifFalse: [ 1 ] ] ].
name := self classNames
findBinary: searchBlock
+ ifNone: [ nil ].
- ifNone: nil.
name ifNotNil: [ ^true ].
name := self nonClassNames
findBinary: searchBlock
+ ifNone: [ nil ].
- ifNone: nil.
^name notNil!
Nov. 27, 2010
Re: [Pharo-project] Issue 3343 in pharo: StringTest>>testWithoutQuoting and fixes for match: and withoutQuoting
by pharo@googlecode.com
Updates:
Summary: StringTest>>testWithoutQuoting and fixes for match: and
withoutQuoting
Comment #2 on issue 3343 by stephane.ducasse:
StringTest>>testWithoutQuoting and fixes for match: and withoutQuoting
http://code.google.com/p/pharo/issues/detail?id=3343
==================== Summary ====================
Name: Collections-ul.407
Author: ul
Time: 16 November 2010, 6:40:10.433 am
UUID: c66d6765-ca57-cc4c-b08b-0582949ce71a
Ancestors: Collections-ul.406
- fix: http://bugs.squeak.org/view.php?id=6841
- fix: http://bugs.squeak.org/view.php?id=6665
=============== Diff against Collections-ul.406 ===============
Item was changed:
----- Method: String>>startingAt:match:startingAt: (in
category 'comparing') -----
startingAt: keyStart match: text startingAt: textStart
"Answer whether text matches the pattern in this string.
Matching ignores upper/lower case differences.
Where this string contains #, text may contain any character.
Where this string contains *, text may contain any sequence of
characters."
| anyMatch matchStart matchEnd i matchStr j ii jj |
i := keyStart.
j := textStart.
"Check for any #'s"
[i > self size ifTrue: [^ j > text size "Empty key matches only
empty string"].
(self at: i) = $#] whileTrue:
["# consumes one char of key and one char of text"
j > text size ifTrue: [^ false "no more text"].
i := i+1. j := j+1].
"Then check for *"
(self at: i) = $*
ifTrue: [i = self size ifTrue:
[^ true "Terminal * matches all"].
"* means next match string can occur
anywhere"
anyMatch := true.
matchStart := i + 1]
ifFalse: ["Otherwise match string must occur immediately"
anyMatch := false.
matchStart := i].
"Now determine the match string"
matchEnd := self size.
(ii := self indexOf: $* startingAt: matchStart) > 0 ifTrue:
+ [ii = matchStart ifTrue: [self error: '** not valid -- use
* instead'].
- [ii = 1 ifTrue: [self error: '** not valid -- use *
instead'].
matchEnd := ii-1].
(ii := self indexOf: $# startingAt: matchStart) > 0 ifTrue:
+ [ii = matchStart ifTrue: [self error: '*# not valid -- use
#* instead'].
- [ii = 1 ifTrue: [self error: '*# not valid -- use #*
instead'].
matchEnd := matchEnd min: ii-1].
matchStr := self copyFrom: matchStart to: matchEnd.
"Now look for the match string"
[jj := text findString: matchStr startingAt: j caseSensitive: false.
anyMatch ifTrue: [jj > 0] ifFalse: [jj = j]]
whileTrue:
["Found matchStr at jj. See if the rest matches..."
(self startingAt: matchEnd+1 match: text startingAt: jj +
matchStr size) ifTrue:
[^ true "the rest matches -- success"].
"The rest did not match."
anyMatch ifFalse: [^ false].
"Preceded by * -- try for a later match"
j := j+1].
^ false "Failed to find the match string"!
Item was changed:
----- Method: String>>withoutQuoting (in category 'internet') -----
withoutQuoting
"remove the initial and final quote marks, if present"
"'''h''' withoutQuoting"
| quote |
self size < 2 ifTrue: [ ^self ].
quote := self first.
+ (quote = self last and: [ quote = $' or: [ quote = $" ] ])
- (quote = $' or: [ quote = $" ])
ifTrue: [ ^self copyFrom: 2 to: self size - 1 ]
ifFalse: [ ^self ].!
Nov. 27, 2010
Re: [Pharo-project] Issue 3343 in pharo: tringTest>>testWithoutQuoting
by pharo@googlecode.com
Comment #1 on issue 3343 by stephane.ducasse: tringTest>>testWithoutQuoting
http://code.google.com/p/pharo/issues/detail?id=3343
would be nice to discuss it a bit too.
Nov. 27, 2010
[Pharo-project] Issue 3343 in pharo: tringTest>>testWithoutQuoting
by pharo@googlecode.com
Status: FixedWaitingToBePharoed
Owner: stephane.ducasse
Labels: Milestone-1.3
New issue 3343 by stephane.ducasse: tringTest>>testWithoutQuoting
http://code.google.com/p/pharo/issues/detail?id=3343
==================== Summary ====================
Name: CollectionsTests-ul.177
Author: ul
Time: 16 November 2010, 6:40:51.04 am
UUID: 4222e03a-483e-ff4f-96dc-ac7e60470cec
Ancestors: CollectionsTests-ul.176
- added tests for String >> #match: and String >> #withoutQuoting
=============== Diff against CollectionsTests-ul.176 ===============
Item was added:
+ ----- Method: StringTest>>testMatch (in category 'test-comparing') -----
+ testMatch
+
+ #('**' '*#' 'f**' 'f*#' 'f**o' 'f*#o') do: [ :each |
+ self should: [ each match: 'foo' ] raise: Error ].
+
#('f*' '*f*' 'f#*' 'f##' '*oo' '#oo' '*o*' '#o#' '#o*' '*o#' 'fo*' 'fo#' '*foo*' '###')
+ do: [ :each | self assert: (each match: 'foo') ].
+ #('bar' 'foo#' '#foo' '*foo#' '#foo*' '*bar*') do: [ :each |
+ self deny: (each match: 'foo') ]!
Item was added:
+ ----- Method: StringTest>>testWithoutQuoting (in category 'testing -
internet') -----
+ testWithoutQuoting
+
+ #(
+ '"foo"' 'foo'
+ '''foo''' 'foo'
+ '"foo''' '"foo'''
+ '''foo"' '''foo"'
+ '"foo' '"foo'
+ 'foo"' 'foo"'
+ 'foo' 'foo') pairsDo: [ :before :after |
+ self assert: before withoutQuoting = after ]!
Nov. 27, 2010