'From Cuis 1.0 of 6 August 2009 [latest update: #258] on 18 August 2009 at 8:51:37 am'!

!PositionableStream methodsFor: 'fileIn/Out' stamp: 'jmv 8/17/2009 22:17'!
copyMethodChunkFrom: aStream
	"Copy the next chunk from aStream (must be different from the receiver)."
	| chunk |
	chunk _ aStream nextChunkText.
	(chunk class == String or: [
	chunk runs values size = 1]) "Optimize for unembellished text"
		ifTrue: [self nextChunkPut: chunk asString]
		ifFalse: [self nextChunkPutWithStyle: chunk]! !

!PositionableStream methodsFor: 'fileIn/Out' stamp: 'jmv 8/17/2009 22:28'!
nextChunkText
	"Deliver the next chunk as a Text.  Decode the following ]style[ chunk if present.  Position at start of next real chunk."
	| string runsRaw strm runs peek |
	"Read the plain text"
	string _ self nextChunk.
	
	"Test for ]style[ tag"
	peek _ self skipSeparatorsAndPeekNext.
	peek = $] ifFalse: [^ string "asText"].  "no tag"
	(self upTo: $[) = ']style' ifFalse: [^ string "asText"].  "different tag"

	"Read and decode the style chunk"
	runsRaw _ self nextChunk.	"style encoding"
	strm _ ReadStream on: runsRaw from: 1 to: runsRaw size.
	runs _ RunArray scanFrom: strm.

	^ Text basicNew setString: string setRunsChecking: runs.
! !


!SystemDictionary methodsFor: 'housekeeping' stamp: 'jmv 8/18/2009 08:31'!
removeTextCode    "Smalltalk removeTextCode"
	"Scan all methods for source code that is Text (i.e. with attributes)
	Replace it with simpleStrings"
	 | oldCodeString n newCodeString oldStamp oldCategory m classComment c o stamp |
	Smalltalk forgetDoIts.
	'Scanning sources for Text.
This will take a few minutes...'
		displayProgressAt: Sensor cursorPoint
		from: 0 
		to: CompiledMethod instanceCount
		during: [:bar | 
			n _ 0.
			m _ 0.
			c _ 0.
			Smalltalk allBehaviorsDo: [ :cls | 
				cls selectors do: [ :selector  | 
					(n _ n+1) \\ 100 = 0 ifTrue: [bar value: n].
					oldCodeString _ cls sourceCodeAt: selector.
					oldCodeString class = String ifFalse: [
						newCodeString _ oldCodeString asString.
						oldStamp _ Utilities timeStampForMethod: (cls compiledMethodAt: selector).
						oldCategory _ cls whichCategoryIncludesSelector: selector.
						cls compile: newCodeString classified: oldCategory withStamp: oldStamp notifying: nil.
						m _ m + 1]].
				cls isMeta ifFalse: [
					o _ cls organization.
					classComment _ o classComment.
					stamp _ o commentStamp.
					classComment class == String ifFalse: [
						classComment hasAnyAttribute ifTrue: [
							self halt "review" ].
						cls classComment: classComment asString stamp: stamp.
						c _ c + 1 ]].
			].
		].
		Transcript cr; show: m printString , ' text methods converted to strings.'.
		Transcript cr; show: c printString , ' text class comments converted to strings.'.! !


!Text methodsFor: 'attributes' stamp: 'jmv 8/18/2009 07:22'!
hasAnyAttribute
	"Return false if there are no emphasis (i.e., a String would not make a difference)"

	^runs values anySatisfy: [ :emphArray | emphArray notEmpty ]! !

"Postscript:
Leave the line above, and replace the rest of this comment by a useful one.
Executable statements should follow this comment, and should
be separated by periods, with no exclamation points (!!).
Be sure to put any further comments in double-quotes, like this one."

Smalltalk removeKey: #J.
Smalltalk removeKey: #ScheduledControllers.
Smalltalk removeKey: #ImageImports.
Smalltalk removeKey: #References.
Smalltalk removeTextCode.
!

