<!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 &lt;<A 
href="mailto:danielv@netvision.net.il">danielv@netvision.net.il</A>&gt; 
wrote:</DIV>
<DIV>(in response to a contribution about Text protocol)</DIV>
<DIV>&nbsp;</DIV>
<DIV>&gt; [everything else about Text operations]<BR>&gt; 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>&nbsp;</DIV>
<DIV>To tell you the story:</DIV>
<DIV>&nbsp;</DIV>
<DIV>Text&gt;&gt;</DIV>
<DIV><STRONG>replaceFrom: start to: stop with: replacement startingAt: repStart 
<BR>&nbsp;</STRONG><EM>"This destructively replaces elements from start to stop 
in the</EM></DIV>
<DIV><EM>&nbsp;&nbsp; receiver starting at index, repStart, in 
replacementCollection.</EM></DIV>
<DIV><EM>&nbsp;&nbsp; Do it to both the string and the runs."</EM></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;| rep newRepRuns |<BR>&nbsp; &nbsp; rep _ replacement 
asText.&nbsp;"might be a string"<BR>&nbsp;&nbsp; string replaceFrom: start to: 
stop with: rep string startingAt: repStart.<BR>&nbsp;&nbsp; repStart = 1 
<BR>&nbsp;&nbsp;&nbsp; &nbsp;ifTrue: [runs _ runs copyReplaceFrom: start to: 
stop with: rep runs]<BR>&nbsp;&nbsp;&nbsp; &nbsp;ifFalse:</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;[newRepRuns _ rep runs copyFrom: repStart 
to: rep size.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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&nbsp; into the receiver) is equal to&nbsp; stop - start + 1 (the number 
of</DIV>
<DIV>charcters that are replaced in the receiver.)</DIV>
<DIV>&nbsp;</DIV>
<DIV>I think the method should read: </DIV>
<DIV>&nbsp;</DIV>
<DIV><STRONG>replaceFrom: start to: stop with: replacement startingAt: repStart 
<BR><EM>&nbsp;</EM></STRONG><EM>"This destructively replaces elements from start 
to stop</EM></DIV>
<DIV><EM>&nbsp;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>&nbsp;</DIV>
<DIV>&nbsp;| rep newRepRuns |<BR>&nbsp;&nbsp; &nbsp;rep _ replacement 
asText.&nbsp;"might be a string"<BR>&nbsp; &nbsp;string replaceFrom: start to: 
stop with: rep string startingAt: repStart.<BR>&nbsp; &nbsp;repStart = 1 
<BR>&nbsp;&nbsp;&nbsp;&nbsp; ifTrue: [runs _ runs copyReplaceFrom: start</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;to: stop</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;with: <STRONG>(rep runs copyFrom: 1 to: stop - start + 
1)</STRONG>]<BR><STRONG>&nbsp;&nbsp;&nbsp;&nbsp;</STRONG>ifFalse: </DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp; [newRepRuns _ rep runs <STRONG>copyFrom: repStart 
to: repStart + stop - start</STRONG>.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; runs _ 
runs copyReplaceFrom: start to: stop with: newRepRuns].<BR></DIV>
<DIV>Here,&nbsp;I assign to newRepRuns&nbsp; 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>&nbsp;</DIV>
<DIV>rep size &gt;= repStart + stop - start</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;(repStart + stop - start&nbsp; is the index of the last character 
that is</DIV>
<DIV>copied from&nbsp; rep into the receiver. )</DIV>
<DIV><BR>&gt; How would you feel about doing some groundwork on those classes 
and<BR>&gt; their clients, and then writing some tests that check the<BR>&gt; 
Text/TextStream API? this would be a good prelude to the kind of deep<BR>&gt; 
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>&gt; <BR>&gt; 
Daniel<BR>Boris</DIV></DIV></BODY></HTML>