<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META content="MSHTML 5.00.2614.3500" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV>
<DIV>Daniel Vainsencher <<A
href="mailto:danielv@netvision.net.il">danielv@netvision.net.il</A>>
wrote:</DIV>
<DIV>(in response to a contribution about Text protocol)</DIV>
<DIV> </DIV>
<DIV>> [everything else about Text operations]<BR>> Sorry, but I've run
out of steam. All that ugly code is depressing me.</DIV>
<DIV>When I received this message, I agreed half-way. This evening,</DIV>
<DIV>after half a day of fighting against a Text problem, I agree fully.</DIV>
<DIV> </DIV>
<DIV>To tell you the story:</DIV>
<DIV> </DIV>
<DIV>Text>></DIV>
<DIV><STRONG>replaceFrom: start to: stop with: replacement startingAt: repStart
<BR> </STRONG><EM>"This destructively replaces elements from start to stop
in the</EM></DIV>
<DIV><EM> receiver starting at index, repStart, in
replacementCollection.</EM></DIV>
<DIV><EM> Do it to both the string and the runs."</EM></DIV>
<DIV> </DIV>
<DIV> | rep newRepRuns |<BR> rep _ replacement
asText. "might be a string"<BR> string replaceFrom: start to:
stop with: rep string startingAt: repStart.<BR> repStart = 1
<BR> ifTrue: [runs _ runs copyReplaceFrom: start to:
stop with: rep runs]<BR> ifFalse:</DIV>
<DIV> [newRepRuns _ rep runs copyFrom: repStart
to: rep size.<BR> runs _ runs
copyReplaceFrom: start to: stop with: newRepRuns].<BR></DIV>
<DIV>is wrong, but it works for an important special case.</DIV>
<DIV>Have a look at newRepRuns :</DIV>
<DIV>It is assigned a collection that contains the text attributes of the</DIV>
<DIV>replacement text from the first character to be copied into the
receiver</DIV>
<DIV>up to the end of the replacement string. This works when </DIV>
<DIV>rep size - repStart + 1 (the number of characters to be copied from</DIV>
<DIV>rep into the receiver) is equal to stop - start + 1 (the number
of</DIV>
<DIV>charcters that are replaced in the receiver.)</DIV>
<DIV> </DIV>
<DIV>I think the method should read: </DIV>
<DIV> </DIV>
<DIV><STRONG>replaceFrom: start to: stop with: replacement startingAt: repStart
<BR><EM> </EM></STRONG><EM>"This destructively replaces elements from start
to stop</EM></DIV>
<DIV><EM> in the receiver starting at index, repStart, in
replacement</EM></DIV>
<DIV><EM>Collection. Do it to both the string and the runs."</EM></DIV>
<DIV> </DIV>
<DIV> | rep newRepRuns |<BR> rep _ replacement
asText. "might be a string"<BR> string replaceFrom: start to:
stop with: rep string startingAt: repStart.<BR> repStart = 1
<BR> ifTrue: [runs _ runs copyReplaceFrom: start</DIV>
<DIV>
to: stop</DIV>
<DIV>
with: <STRONG>(rep runs copyFrom: 1 to: stop - start +
1)</STRONG>]<BR><STRONG> </STRONG>ifFalse: </DIV>
<DIV> [newRepRuns _ rep runs <STRONG>copyFrom: repStart
to: repStart + stop - start</STRONG>.<BR> runs _
runs copyReplaceFrom: start to: stop with: newRepRuns].<BR></DIV>
<DIV>Here, I assign to newRepRuns a collection that contains
the</DIV>
<DIV>text attributes of the replacement text for the characters that are </DIV>
<DIV>copied into the receiver.</DIV>
<DIV>My proposal is still not perfect, one should verify that </DIV>
<DIV> </DIV>
<DIV>rep size >= repStart + stop - start</DIV>
<DIV> </DIV>
<DIV> (repStart + stop - start is the index of the last character
that is</DIV>
<DIV>copied from rep into the receiver. )</DIV>
<DIV><BR>> How would you feel about doing some groundwork on those classes
and<BR>> their clients, and then writing some tests that check the<BR>>
Text/TextStream API? this would be a good prelude to the kind of deep<BR>>
cleanup these classes are begging for (IMHO).</DIV>
<DIV>I cannot deny that we should have tests. We should also have some</DIV>
<DIV>half-formal description of the classes RunArray and Text. Both</DIV>
<DIV>classes are based on really excellent ideas, but we do not care to
explain</DIV>
<DIV>these ideas.</DIV>
<DIV>I will try to write some tests, but this will take a bit more time.
Perhaps</DIV>
<DIV>I can also discuss this stuff at CampSmalltalk - a serious
CampSmalltalk</DIV>
<DIV>should have a Squeak bug fixing party. I will try to publish a first
set</DIV>
<DIV>of tests before CampSmalltalk.<BR>> <BR>>
Daniel<BR>Boris</DIV></DIV></BODY></HTML>