--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Text.st Sat May 11 14:35:51 1996 +0200
@@ -0,0 +1,302 @@
+"
+ COPYRIGHT (c) 1996 by Claus Gittinger
+ All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice. This software may not
+ be provided or otherwise made available to, or used by, any
+ other person. No title to or ownership of the software is
+ hereby transferred.
+"
+
+
+CharacterArray subclass:#Text
+ instanceVariableNames:'string runs'
+ classVariableNames:''
+ poolDictionaries:''
+ category:'Collections-Text'
+!
+
+!Text class methodsFor:'documentation'!
+
+copyright
+"
+ COPYRIGHT (c) 1996 by Claus Gittinger
+ All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice. This software may not
+ be provided or otherwise made available to, or used by, any
+ other person. No title to or ownership of the software is
+ hereby transferred.
+"
+
+!
+
+documentation
+"
+ Texts add emphasis information to a string.
+
+ This class is not yet fully implemented - being constructed.
+
+ [author:]
+ Claus Gittinger
+
+ [see also:]
+ CharacterArray String RunArray
+"
+! !
+
+!Text class methodsFor:'instance creation'!
+
+fromString:aString
+ ^ self new string:aString emphasis:nil
+
+ "
+ Text fromString:'hello'
+ "
+
+ "Modified: 11.5.1996 / 14:20:35 / cg"
+!
+
+string:aString
+ ^ self new string:aString emphasis:nil
+
+ "
+ Text string:'hello'
+ "
+
+ "Modified: 11.5.1996 / 14:20:48 / cg"
+!
+
+string:aString emphasis:attribute
+ ^ self new string:aString emphasis:attribute
+
+ "
+ Text string:'hello' emphasis:#bold
+ "
+
+ "Modified: 11.5.1996 / 14:21:01 / cg"
+! !
+
+!Text methodsFor:'comparing'!
+
+= aStringOrText
+ "compare the receiver and the argument, ignoring emphasis"
+
+ ^ string = aStringOrText string
+
+
+ "
+ 'hello' asText = 'hello'
+ 'hello' asText = 'hello' asText
+ 'hello' asText allBold = 'hello'
+ "
+
+ "Modified: 11.5.1996 / 14:33:00 / cg"
+! !
+
+!Text methodsFor:'converting'!
+
+asString
+ ^ string
+
+ "
+ (Text string:'hello' emphasis:#bold) asString
+ "
+
+ "Modified: 11.5.1996 / 14:21:19 / cg"
+!
+
+asText
+ ^ self
+
+ "Created: 11.5.1996 / 14:08:36 / cg"
+!
+
+at:characterIndex
+ ^ string at:characterIndex
+
+ "Created: 11.5.1996 / 14:25:41 / cg"
+!
+
+at:characterIndex put:aCharacter
+ ^ string at:characterIndex put:aCharacter
+
+ "Created: 11.5.1996 / 14:25:49 / cg"
+! !
+
+!Text methodsFor:'copying'!
+
+, aStringOrText
+ "for now, return a string ..."
+
+ ^ self species new
+ string:(string , aStringOrText)
+ runs:(runs , aStringOrText runs)
+
+ "Created: 11.5.1996 / 13:59:54 / cg"
+!
+
+copyFrom:start to:stop
+ |e s|
+
+ s := TextStream on:String new.
+ self from:start to:stop doWithEmphasis:[:char :e |
+ s emphasis:e.
+ s nextPut:char
+ ].
+ ^ s contents
+
+ "Created: 11.5.1996 / 14:00:20 / cg"
+! !
+
+!Text methodsFor:'emphasis'!
+
+allBold
+ "make all characters bold"
+
+ runs := RunArray new:(string size) withAll:#bold
+
+ "
+ (Text string:'hello') allBold
+ "
+
+ "Modified: 11.5.1996 / 14:22:12 / cg"
+!
+
+emphasisAt:characterIndex
+ "return the emphasis at some index"
+
+ ^ runs at:characterIndex
+
+ "
+ (Text string:'hello') allBold emphasisAt:2
+ "
+
+ "Modified: 11.5.1996 / 14:22:31 / cg"
+!
+
+emphasizeAllWith:emphasis
+ "change the emphasis of all characters"
+
+ runs := RunArray new:(string size) withAll:emphasis
+
+ "
+ (Text string:'hello') allBold emphasizeAllWith:#italic
+ "
+
+ "Modified: 11.5.1996 / 14:22:52 / cg"
+!
+
+emphasizeFrom:start to:stop with:emphasis
+ "change the emphasis of a range of characters"
+
+ |newRuns|
+
+ newRuns := RunArray new.
+
+ "/ for now - a q&d hack
+ 1 to:start-1 do:[:i |
+ newRuns add:(runs at:i).
+ ].
+ newRuns add:emphasis withOccurrences:(stop - start + 1).
+ stop+1 to:string size do:[:i |
+ newRuns add:(runs at:i)
+ ].
+ runs := newRuns
+
+ "
+ (Text string:'hello world')
+ emphasizeFrom:1 to:5 with:#bold;
+ emphasizeFrom:7 to:11 with:#italic
+ "
+
+ "Modified: 11.5.1996 / 14:30:02 / cg"
+! !
+
+!Text methodsFor:'printing & storing'!
+
+displayString
+ ^ self storeString
+
+ "Created: 11.5.1996 / 14:24:48 / cg"
+!
+
+printOn:aStream
+ string printOn:aStream
+
+ "Created: 11.5.1996 / 14:27:25 / cg"
+!
+
+storeOn:aStream
+ aStream nextPutAll:'(Text string:'.
+ string storeOn:aStream.
+ aStream nextPutAll:'runs:'.
+ runs storeOn:aStream.
+ aStream nextPutAll:')'.
+
+ "Created: 11.5.1996 / 14:27:09 / cg"
+! !
+
+!Text methodsFor:'private accessing'!
+
+string:aString emphasis:emphasis
+ string := aString.
+ runs := RunArray new:string size withAll:emphasis
+
+ "
+ |t|
+
+ t := Text new string:'hello' emphasis:#bold.
+ t emphasisAt:2.
+ "
+
+ "Modified: 11.5.1996 / 14:19:38 / cg"
+! !
+
+!Text methodsFor:'queries'!
+
+endsWith:aString
+ ^ string endsWith:aString
+
+ "Created: 11.5.1996 / 13:58:52 / cg"
+!
+
+hasChangeOfEmphasis
+ ^ runs notNil
+
+ "Created: 11.5.1996 / 14:03:19 / cg"
+!
+
+indexOf:aCharacter startingAt:index
+ ^ string indexOf:aCharacter startingAt:index
+
+ "Created: 11.5.1996 / 13:58:56 / cg"
+!
+
+occurrencesOf:aCharacter
+ ^ string occurrencesOf:aCharacter
+
+ "Created: 11.5.1996 / 13:58:46 / cg"
+!
+
+size
+ ^ string size
+
+ "Created: 11.5.1996 / 14:25:15 / cg"
+!
+
+string
+ ^ string
+
+ "Created: 11.5.1996 / 13:58:38 / cg"
+! !
+
+!Text class methodsFor:'documentation'!
+
+version
+ ^ '$Header: /cvs/stx/stx/libbasic2/Text.st,v 1.1 1996-05-11 12:35:51 cg Exp $'
+! !