Squeak Class Documentation category index | class index  
 
Text
  category: Collections-Text
  superclass: ArrayedCollection
  subclasses:

I represent a character string that has been marked with abstract changes in character appearance. Actual display is performed in the presence of a TextStyle which indicates, for each abstract code, an actual font to be used. A Text associates a set of TextAttributes with each character in its character string. These attributes may be font numbers, emphases such as bold or italic, or hyperling actions. Font numbers are interpreted relative to whatever textStyle appears, along with the text, in a Paragraph. Since most characters have the same attributes as their neighbors, the attributes are stored in a RunArray for efficiency. Each of my instances has
string a String
runs a RunArray

instance methods
  accessing
  append:
at:
at:put:
embeddedMorphs
findString:startingAt:
findString:startingAt:caseSensitive:
lineCount
rangeOf:startingAt:forStyle:
replaceFrom:to:with:
size
string

  attributes
  askIfAddStyle:req:
basicType
couldDeriveFromPrettyPrinting
unembellished

  comparing
  =
hash
howManyMatch:
isText

  converting
  asDisplayText
asNumber
asParagraph
asString
asStringOrText
asText
asUrl
asUrlRelativeTo:
isoToSqueak
squeakToIso

  copying
  copy
copyFrom:to:
copyReplaceFrom:to:with:
copyReplaceTokens:with:
deepCopy

  emphasis
  addAttribute:
addAttribute:from:to:
allBold
attributesAt:
attributesAt:forStyle:
emphasisAt:
find:
fontAt:withStyle:
fontNumberAt:
makeBoldFrom:to:
makeSelectorBoldIn:
removeAttribute:from:to:
runLengthFor:

  printing
  printOn:
storeOn:

  private
  runs
setString:setRuns:
setString:setRunsChecking:

class methods
  class initialization
  initTextConstants
initialize

  instance creation
  fromString:
fromUser
new:
streamContents:
string:attribute:
string:attributes:
string:emphasis:

  private
  addAttribute:toArray:
string:runs:

instance methods
  accessing top  
 

append:


 

at:

Primitive. Assumes receiver is indexable. Answer the value of an
indexable element in the receiver. Fail if the argument index is not an
Integer or is out of bounds. Essential. See Object documentation
whatIsAPrimitive.


 

at:put:

Primitive. Assumes receiver is indexable. Store the argument value in
the indexable element of the receiver indicated by index. Fail if the
index is not an Integer or is out of bounds. Or fail if the value is not of
the right type for this kind of collection. Answer the value that was
stored. Essential. See Object documentation whatIsAPrimitive.


 

embeddedMorphs

return the list of morphs embedded in me


 

findString:startingAt:

Answer the index of subString within the receiver, starting at index
start. If the receiver does not contain subString, answer 0.


 

findString:startingAt:caseSensitive:

Answer the index of subString within the receiver, starting at index
start. If the receiver does not contain subString, answer 0.


 

lineCount


 

rangeOf:startingAt:forStyle:

This is stupid, slow code, but it works


 

replaceFrom:to:with:

This destructively replaces elements from start to stop in the receiver.
Answer the receiver itself. Use copyReplaceFrom:to:with: for
insertion/deletion which may alter the size of the result.


 

size

Answer how many elements the receiver contains.


 

string

Answer the string representation of the receiver.


  attributes top  
 

askIfAddStyle:req:

Ask the user if we have a complex style (i.e. bold) for the first time


 

basicType

Answer a symbol representing the inherent type I hold


 

couldDeriveFromPrettyPrinting

Return true if the receiver has any TextAttributes that are functional rather than simply appearance-related


 

unembellished

Return true if the only emphases are the default font and bold


  comparing top  
 

=

Am I equal to the other Text or String?
***** Warning ***** Two Texts are considered equal if they have the same characters in them. They might have completely different emphasis, fonts, sizes, text actions, or embedded morphs. If you need to find out if one is a true copy of the other, you must do (text1 = text2 and: [text1 runs = text2 runs]).


 

hash

#hash is implemented, because #= is implemented. We are now equal to a string with the same characters. Hash must reflect that.


 

howManyMatch:


 

isText


  converting top  
 

asDisplayText

Answer a DisplayText whose text is the receiver.


 

asNumber

Answer the number created by interpreting the receiver as the textual
representation of a number.


 

asParagraph

Answer a Paragraph whose text is the receiver.


 

asString

Answer a String representation of the textual receiver.


 

asStringOrText

Answer the receiver itself.


 

asText

Answer the receiver itself.


 

asUrl


 

asUrlRelativeTo:


 

isoToSqueak


 

squeakToIso


  copying top  
 

copy

Answer another instance just like the receiver. Subclasses typically
override this method; they typically do not override shallowCopy.


 

copyFrom:to:

Answer a copied subrange of the receiver.


 

copyReplaceFrom:to:with:

Answer a copy of the receiver satisfying the following conditions: If
stop is less than start, then this is an insertion; stop should be exactly
start-1, start = 1 means insert before the first character, start = size+1
means append after last character. Otherwise, this is a replacement; start
and stop have to be within the receiver's bounds.


 

copyReplaceTokens:with:

Replace all occurrences of oldSubstring that are surrounded
by non-alphanumeric characters


 

deepCopy

Answer a copy of the receiver with its own copy of each instance
variable.


  emphasis top  
 

addAttribute:


 

addAttribute:from:to:

Set the attribute for characters in the interval start to stop.


 

allBold

Force this whole text to be bold.


 

attributesAt:

Answer the code for characters in the run beginning at characterIndex.


 

attributesAt:forStyle:

Answer the code for characters in the run beginning at characterIndex.


 

emphasisAt:

Answer the fontfor characters in the run beginning at characterIndex.


 

find:

Return the first interval over which this attribute applies


 

fontAt:withStyle:

Answer the fontfor characters in the run beginning at characterIndex.


 

fontNumberAt:

Answer the fontNumber for characters in the run beginning at characterIndex.


 

makeBoldFrom:to:


 

makeSelectorBoldIn:

For formatting Smalltalk source code, set the emphasis of that portion of
the receiver's string that parses as a message selector to be bold.


 

removeAttribute:from:to:

Remove the attribute over the interval start to stop.


 

runLengthFor:

Answer the count of characters remaining in run beginning with
characterIndex.


  printing top  
 

printOn:

Append a sequence of characters that identify the receiver to aStream.


 

storeOn:

Refer to the comment in Object|storeOn:.


  private top  
 

runs


 

setString:setRuns:


 

setString:setRunsChecking:

Check runs and do the best you can to make them fit...


class methods
  class initialization top  
 

initTextConstants

Initialize constants shared by classes associated with text display, e.g.,
Space, Tab, Cr, Bs, ESC.


 

initialize

Text initialize


  instance creation top  
 

fromString:

Answer an instance of me whose characters are those of the argument, aString.


 

fromUser

Answer an instance of me obtained by requesting the user to type a string.


 

new:

Answer an instance of this class with the number of indexable
variables specified by the argument, sizeRequested.


 

streamContents:


 

string:attribute:

Answer an instance of me whose characters are aString.
att is a TextAttribute.


 

string:attributes:

Answer an instance of me whose characters are those of aString.
atts is an array of TextAttributes.


 

string:emphasis:

This is an old method that is mainly used by old applications


  private top  
 

addAttribute:toArray:

Add a new text attribute to an existing set


 

string:runs: