eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'ImmutableString':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: ImmutableString


Inheritance:

   Object
   |
   +--Collection
      |
      +--SequenceableCollection
         |
         +--ArrayedCollection
            |
            +--UninterpretedBytes
               |
               +--CharacterArray
                  |
                  +--String
                     |
                     +--ImmutableString
                        |
                        +--MIMETypes::MIMEType

Package:
stx:libbasic
Category:
System-Compiler-Support
Version:
rev: 1.20 date: 2016/10/04 10:43:45
user: stefan
file: ImmutableString.st directory: libbasic
module: stx stc-classLibrary: libbasic
Author:
Claus Gittinger

Description:


By default, string literals in smalltalk are mutable objects. That
may lead to some subtle (and hard to find errors), if some method passes
a string constant as argument to someone else, who changes the
string using at:put: like messages. Since the string object is kept in
the first methods literals, the string constant has now been changed without
having the method's sourcecode reflect this. Thus, the method will
behave differently from what its source may make you think.

To help finding this kind of 'feature/bug', the compiler can be
configured to create instances of this ImmutableString instead of Strings
for literals. Instances of ImmutableString catch storing accesses and
enter the debugger. Although useful, this feature is disabled by default
for compatibility to other smalltalk implementations.
(Also, if turned on, this makes inspecting string literals entered in
 a workspace somewhat strange: you cannot modify it any longer).

Turn the ImmutableString feature on by setting the Parsers class variable
'StringsAreImmutable' to true or use the new launchers settings menu.

This class should be used only by the compiler.

ATTENTION:
    there may be still code around which checks for explicit class being String
    (both in Smalltalk and in primitive code). All code like foo 'class == String'
    or '__isString()' will not work with ImmutableStrings. Use '__isStringLike()' instead.
    A somewhat better approach would be to either add a flag to the object (mutability)
    and check this dynamically (expensive) or to place immutable objects into a readonly
    memory segment (the good solution). We will eventually implement the second in the future...


Related information:

    ImmutableArray
    Parser
    Scanner

Class protocol:

queries
o  mutableClass
answer an equivalent mustable class

testing
o  hasImmutableInstances


Instance protocol:

accessing
o  at: index put: value
Trigger an error if an immutable string is stored into.
The store will be performed (for compatibility reasons) if you continue
in the debugger.

o  basicAt: index put: value
Trigger an error if an immutable string is stored into.
The store will be performed (for compatibility reasons) if you continue
in the debugger.

converting
o  asImmutableString

o  asMutableCollection
return a writable copy of myself

o  beImmutable
that's what I am

o  beMutable
you never go back

copying
o  copy
return a copy of the receiver
usage example(s):
        'abcd' asImmutableString copy

o  deepCopy
when copying, return a real (mutable) String
usage example(s):
     'hello world' asImmutableString deepCopy

o  deepCopyUsing: aDictionary postCopySelector: postCopySelector
return a deep copy of the receiver - reimplemented to be a bit faster
usage example(s):
     'hello world' asImmutableString deepCopyUsing:nil postCopySelector:nil

o  postCopy
when copied, make me a real (mutable) String

o  postDeepCopy
when copied, make it me a real (mutable) String

o  shallowCopy
when copying, return a real (mutable) String
usage example(s):
     'hello world' asImmutableString shallowCopy

o  simpleDeepCopy
when copying, return a real (mutable) String
usage example(s):
     'hello world' asImmutableString simpleDeepCopy

private
o  species
Copies should be mutable

o  speciesForCopy
Copies should be mutable

queries
o  isImmutable

specials
o  become: anotherObject
trigger an error if I should become something else
(this would be an even more tricky manipulation)

o  becomeNil
trigger an error if I should become nil
(this would be an even more tricky manipulation)

o  becomeSameAs: anotherObject
trigger an error if I should become something else
(this would be an even more tricky manipulation)



ST/X 7.1.0.0; WebServer 1.663 at exept.de:8081; Tue, 20 Nov 2018 16:15:09 GMT