ImmutableString.st
author Claus Gittinger <cg@exept.de>
Mon, 27 May 2019 15:01:44 +0200
changeset 24172 ddd5ab5bc403
parent 23922 24e48e381aa1
child 24309 54640603c048
permissions -rw-r--r--
#OTHER by cg category of: #postCopy #postDeepCopy #postDeepCopyFrom:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3714
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 1998 by eXept Software AG
12538
e6bf8c42e1d4 Moved to libbasic from libcomp - change package name
Stefan Vogel <sv@exept.de>
parents: 12491
diff changeset
     3
	      All Rights Reserved
3714
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
12538
e6bf8c42e1d4 Moved to libbasic from libcomp - change package name
Stefan Vogel <sv@exept.de>
parents: 12491
diff changeset
    12
"{ Package: 'stx:libbasic' }"
8807
606a4ec5b693 #notifyStoreError raise error proceedable.
Stefan Vogel <sv@exept.de>
parents: 3714
diff changeset
    13
17373
2dcc19464bd0 class: ImmutableString
Stefan Vogel <sv@exept.de>
parents: 16824
diff changeset
    14
"{ NameSpace: Smalltalk }"
2dcc19464bd0 class: ImmutableString
Stefan Vogel <sv@exept.de>
parents: 16824
diff changeset
    15
8807
606a4ec5b693 #notifyStoreError raise error proceedable.
Stefan Vogel <sv@exept.de>
parents: 3714
diff changeset
    16
String variableByteSubclass:#ImmutableString
3714
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	instanceVariableNames:''
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	classVariableNames:''
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	poolDictionaries:''
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	category:'System-Compiler-Support'
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!ImmutableString class methodsFor:'documentation'!
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
copyright
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
"
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
 COPYRIGHT (c) 1998 by eXept Software AG
12538
e6bf8c42e1d4 Moved to libbasic from libcomp - change package name
Stefan Vogel <sv@exept.de>
parents: 12491
diff changeset
    28
	      All Rights Reserved
3714
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 This software is furnished under a license and may be used
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 only in accordance with the terms of that license and with the
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 be provided or otherwise made available to, or used by, any
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 other person.  No title to or ownership of the software is
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 hereby transferred.
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
"
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
!
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
documentation
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
"
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
    By default, string literals in smalltalk are mutable objects. That
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
    may lead to some subtle (and hard to find errors), if some method passes
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
    a string constant as argument to someone else, who changes the
12538
e6bf8c42e1d4 Moved to libbasic from libcomp - change package name
Stefan Vogel <sv@exept.de>
parents: 12491
diff changeset
    45
    string using at:put: like messages. Since the string object is kept in
3714
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
    the first methods literals, the string constant has now been changed without
12464
c0a970ba9175 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12457
diff changeset
    47
    having the method's sourcecode reflect this. Thus, the method will
3714
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
    behave differently from what its source may make you think.
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
    To help finding this kind of 'feature/bug', the compiler can be
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
    configured to create instances of this ImmutableString instead of Strings
12464
c0a970ba9175 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12457
diff changeset
    52
    for literals. Instances of ImmutableString catch storing accesses and
3714
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
    enter the debugger. Although useful, this feature is disabled by default
12538
e6bf8c42e1d4 Moved to libbasic from libcomp - change package name
Stefan Vogel <sv@exept.de>
parents: 12491
diff changeset
    54
    for compatibility to other smalltalk implementations.
3714
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
    (Also, if turned on, this makes inspecting string literals entered in
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
     a workspace somewhat strange: you cannot modify it any longer).
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
    Turn the ImmutableString feature on by setting the Parsers class variable
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
    'StringsAreImmutable' to true or use the new launchers settings menu.
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
18546
23c33cdd1f43 class: ImmutableString
Stefan Vogel <sv@exept.de>
parents: 17373
diff changeset
    61
    This class should be used only by the compiler.
12471
c6260f85e725 added: #copyright
Claus Gittinger <cg@exept.de>
parents: 12464
diff changeset
    62
c6260f85e725 added: #copyright
Claus Gittinger <cg@exept.de>
parents: 12464
diff changeset
    63
    ATTENTION:
14222
876ba773f5d2 changed: #documentation
Stefan Vogel <sv@exept.de>
parents: 14115
diff changeset
    64
        there may be still code around which checks for explicit class being String
876ba773f5d2 changed: #documentation
Stefan Vogel <sv@exept.de>
parents: 14115
diff changeset
    65
        (both in Smalltalk and in primitive code). All code like foo 'class == String'
876ba773f5d2 changed: #documentation
Stefan Vogel <sv@exept.de>
parents: 14115
diff changeset
    66
        or '__isString()' will not work with ImmutableStrings. Use '__isStringLike()' instead.
876ba773f5d2 changed: #documentation
Stefan Vogel <sv@exept.de>
parents: 14115
diff changeset
    67
        A somewhat better approach would be to either add a flag to the object (mutability)
876ba773f5d2 changed: #documentation
Stefan Vogel <sv@exept.de>
parents: 14115
diff changeset
    68
        and check this dynamically (expensive) or to place immutable objects into a readonly
876ba773f5d2 changed: #documentation
Stefan Vogel <sv@exept.de>
parents: 14115
diff changeset
    69
        memory segment (the good solution). We will eventually implement the second in the future...
12471
c6260f85e725 added: #copyright
Claus Gittinger <cg@exept.de>
parents: 12464
diff changeset
    70
3714
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
    [see also:]
14222
876ba773f5d2 changed: #documentation
Stefan Vogel <sv@exept.de>
parents: 14115
diff changeset
    72
        ImmutableArray
876ba773f5d2 changed: #documentation
Stefan Vogel <sv@exept.de>
parents: 14115
diff changeset
    73
        Parser Scanner
3714
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
    [author:]
14222
876ba773f5d2 changed: #documentation
Stefan Vogel <sv@exept.de>
parents: 14115
diff changeset
    76
        Claus Gittinger
3714
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
"
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
! !
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
17373
2dcc19464bd0 class: ImmutableString
Stefan Vogel <sv@exept.de>
parents: 16824
diff changeset
    80
!ImmutableString class methodsFor:'queries'!
2dcc19464bd0 class: ImmutableString
Stefan Vogel <sv@exept.de>
parents: 16824
diff changeset
    81
2dcc19464bd0 class: ImmutableString
Stefan Vogel <sv@exept.de>
parents: 16824
diff changeset
    82
mutableClass
2dcc19464bd0 class: ImmutableString
Stefan Vogel <sv@exept.de>
parents: 16824
diff changeset
    83
    "answer an equivalent mustable class"
2dcc19464bd0 class: ImmutableString
Stefan Vogel <sv@exept.de>
parents: 16824
diff changeset
    84
2dcc19464bd0 class: ImmutableString
Stefan Vogel <sv@exept.de>
parents: 16824
diff changeset
    85
    ^ String
2dcc19464bd0 class: ImmutableString
Stefan Vogel <sv@exept.de>
parents: 16824
diff changeset
    86
! !
2dcc19464bd0 class: ImmutableString
Stefan Vogel <sv@exept.de>
parents: 16824
diff changeset
    87
2dcc19464bd0 class: ImmutableString
Stefan Vogel <sv@exept.de>
parents: 16824
diff changeset
    88
!ImmutableString class methodsFor:'testing'!
2dcc19464bd0 class: ImmutableString
Stefan Vogel <sv@exept.de>
parents: 16824
diff changeset
    89
2dcc19464bd0 class: ImmutableString
Stefan Vogel <sv@exept.de>
parents: 16824
diff changeset
    90
hasImmutableInstances
2dcc19464bd0 class: ImmutableString
Stefan Vogel <sv@exept.de>
parents: 16824
diff changeset
    91
    ^ true
2dcc19464bd0 class: ImmutableString
Stefan Vogel <sv@exept.de>
parents: 16824
diff changeset
    92
! !
2dcc19464bd0 class: ImmutableString
Stefan Vogel <sv@exept.de>
parents: 16824
diff changeset
    93
3714
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
!ImmutableString methodsFor:'accessing'!
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
12538
e6bf8c42e1d4 Moved to libbasic from libcomp - change package name
Stefan Vogel <sv@exept.de>
parents: 12491
diff changeset
    96
at:index put:value
3714
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
    "Trigger an error if an immutable string is stored into.
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
     The store will be performed (for compatibility reasons) if you continue
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
     in the debugger."
12538
e6bf8c42e1d4 Moved to libbasic from libcomp - change package name
Stefan Vogel <sv@exept.de>
parents: 12491
diff changeset
   100
12491
d74b78dd478a Raise NoModificationError
Stefan Vogel <sv@exept.de>
parents: 12471
diff changeset
   101
    self noModificationError.
3714
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
    ^ super at:index put:value
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
    "Created: / 3.8.1998 / 14:45:14 / cg"
12457
7094a6561516 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9412
diff changeset
   105
!
7094a6561516 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9412
diff changeset
   106
12538
e6bf8c42e1d4 Moved to libbasic from libcomp - change package name
Stefan Vogel <sv@exept.de>
parents: 12491
diff changeset
   107
basicAt:index put:value
12457
7094a6561516 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9412
diff changeset
   108
    "Trigger an error if an immutable string is stored into.
7094a6561516 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9412
diff changeset
   109
     The store will be performed (for compatibility reasons) if you continue
7094a6561516 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9412
diff changeset
   110
     in the debugger."
12538
e6bf8c42e1d4 Moved to libbasic from libcomp - change package name
Stefan Vogel <sv@exept.de>
parents: 12491
diff changeset
   111
12491
d74b78dd478a Raise NoModificationError
Stefan Vogel <sv@exept.de>
parents: 12471
diff changeset
   112
    self noModificationError.
12457
7094a6561516 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9412
diff changeset
   113
    ^ super basicAt:index put:value
7094a6561516 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9412
diff changeset
   114
! !
7094a6561516 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9412
diff changeset
   115
7094a6561516 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9412
diff changeset
   116
!ImmutableString methodsFor:'converting'!
7094a6561516 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9412
diff changeset
   117
23922
24e48e381aa1 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23917
diff changeset
   118
asImmutableCollection
24e48e381aa1 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23917
diff changeset
   119
    ^ self
24e48e381aa1 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23917
diff changeset
   120
24e48e381aa1 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23917
diff changeset
   121
    "Created: / 15-03-2019 / 13:53:13 / Stefan Vogel"
24e48e381aa1 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23917
diff changeset
   122
!
24e48e381aa1 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23917
diff changeset
   123
12457
7094a6561516 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9412
diff changeset
   124
asImmutableString
7094a6561516 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9412
diff changeset
   125
    ^ self
16824
d609e592fd2f added asMutableCollection
Claus Gittinger <cg@exept.de>
parents: 16400
diff changeset
   126
!
d609e592fd2f added asMutableCollection
Claus Gittinger <cg@exept.de>
parents: 16400
diff changeset
   127
d609e592fd2f added asMutableCollection
Claus Gittinger <cg@exept.de>
parents: 16400
diff changeset
   128
asMutableCollection
d609e592fd2f added asMutableCollection
Claus Gittinger <cg@exept.de>
parents: 16400
diff changeset
   129
    "return a writable copy of myself"
d609e592fd2f added asMutableCollection
Claus Gittinger <cg@exept.de>
parents: 16400
diff changeset
   130
23917
d98b4d786122 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20525
diff changeset
   131
    ^ self copyFrom:1.  "/ #copyFrom: always raturns a String
d98b4d786122 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20525
diff changeset
   132
d98b4d786122 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20525
diff changeset
   133
    "Modified (comment): / 15-03-2019 / 13:26:43 / Stefan Vogel"
20525
d7da56a61fc0 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20034
diff changeset
   134
!
d7da56a61fc0 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20034
diff changeset
   135
d7da56a61fc0 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20034
diff changeset
   136
beImmutable
d7da56a61fc0 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20034
diff changeset
   137
    "that's what I am"
d7da56a61fc0 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20034
diff changeset
   138
d7da56a61fc0 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20034
diff changeset
   139
    ^ self
d7da56a61fc0 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20034
diff changeset
   140
!
d7da56a61fc0 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20034
diff changeset
   141
d7da56a61fc0 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20034
diff changeset
   142
beMutable
d7da56a61fc0 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20034
diff changeset
   143
    "you never go back"
d7da56a61fc0 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20034
diff changeset
   144
d7da56a61fc0 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20034
diff changeset
   145
    ^ self shouldNotImplement
3714
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
! !
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
!ImmutableString methodsFor:'copying'!
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
20034
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   150
copy
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   151
    "return a copy of the receiver"
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   152
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   153
    ^ self copyFrom:1
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   154
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   155
    "
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   156
        'abcd' asImmutableString copy
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   157
    "
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   158
!
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   159
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   160
deepCopy
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   161
    "when copying, return a real (mutable) String"
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   162
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   163
    (self class == ImmutableString) ifTrue:[
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   164
        ^ self copyFrom:1
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   165
    ].
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   166
    ^ super deepCopy
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   167
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   168
    "
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   169
     'hello world' asImmutableString deepCopy
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   170
    "
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   171
!
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   172
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   173
deepCopyUsing:aDictionary postCopySelector:postCopySelector
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   174
    "return a deep copy of the receiver - reimplemented to be a bit faster"
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   175
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   176
    "
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   177
     could be an instance of a subclass which needs deepCopy
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   178
     of its named instvars ...
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   179
    "
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   180
    (self class == ImmutableString) ifTrue:[
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   181
        ^ self copyFrom:1
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   182
    ].
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   183
    ^ super deepCopyUsing:aDictionary postCopySelector:postCopySelector
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   184
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   185
    "
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   186
     'hello world' asImmutableString deepCopyUsing:nil postCopySelector:nil
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   187
    "
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   188
!
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   189
3714
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   190
shallowCopy
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
    "when copying, return a real (mutable) String"
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
20034
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   193
    (self class == ImmutableString) ifTrue:[
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   194
        ^ self copyFrom:1
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   195
    ].
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   196
    ^ super shallowCopy
3714
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
14115
8599762e8a45 comment/format in: #shallowCopy
Stefan Vogel <sv@exept.de>
parents: 14025
diff changeset
   198
    "
8599762e8a45 comment/format in: #shallowCopy
Stefan Vogel <sv@exept.de>
parents: 14025
diff changeset
   199
     'hello world' asImmutableString shallowCopy
8599762e8a45 comment/format in: #shallowCopy
Stefan Vogel <sv@exept.de>
parents: 14025
diff changeset
   200
    "
8599762e8a45 comment/format in: #shallowCopy
Stefan Vogel <sv@exept.de>
parents: 14025
diff changeset
   201
3714
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   202
    "Created: / 3.8.1998 / 14:47:00 / cg"
20034
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   203
!
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   204
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   205
simpleDeepCopy
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   206
    "when copying, return a real (mutable) String"
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   207
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   208
    (self class == ImmutableString) ifTrue:[
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   209
        ^ self copyFrom:1
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   210
    ].
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   211
    ^ super simpleDeepCopy
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   212
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   213
    "
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   214
     'hello world' asImmutableString simpleDeepCopy
2ba574fda7ab #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 18704
diff changeset
   215
    "
3714
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
! !
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
24172
ddd5ab5bc403 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 23922
diff changeset
   218
!ImmutableString methodsFor:'copying-private'!
ddd5ab5bc403 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 23922
diff changeset
   219
ddd5ab5bc403 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 23922
diff changeset
   220
postCopy
ddd5ab5bc403 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 23922
diff changeset
   221
    "when copied, make me a real (mutable) String"
ddd5ab5bc403 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 23922
diff changeset
   222
ddd5ab5bc403 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 23922
diff changeset
   223
    self changeClassTo:String.
ddd5ab5bc403 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 23922
diff changeset
   224
ddd5ab5bc403 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 23922
diff changeset
   225
    "Created: / 3.8.1998 / 14:46:45 / cg"
ddd5ab5bc403 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 23922
diff changeset
   226
!
ddd5ab5bc403 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 23922
diff changeset
   227
ddd5ab5bc403 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 23922
diff changeset
   228
postDeepCopy
ddd5ab5bc403 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 23922
diff changeset
   229
    "when copied, make it me a real (mutable) String"
ddd5ab5bc403 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 23922
diff changeset
   230
ddd5ab5bc403 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 23922
diff changeset
   231
    self changeClassTo:String.
ddd5ab5bc403 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 23922
diff changeset
   232
ddd5ab5bc403 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 23922
diff changeset
   233
    "
ddd5ab5bc403 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 23922
diff changeset
   234
     'foobar' asImmutableString copy          class
ddd5ab5bc403 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 23922
diff changeset
   235
     'foobar' asImmutableString shallowCopy   class
ddd5ab5bc403 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 23922
diff changeset
   236
     'foobar' asImmutableString deepCopy      class
ddd5ab5bc403 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 23922
diff changeset
   237
    "
ddd5ab5bc403 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 23922
diff changeset
   238
! !
ddd5ab5bc403 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 23922
diff changeset
   239
3714
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
!ImmutableString methodsFor:'private'!
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
species
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
    "Copies should be mutable"
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
    ^ String
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
    "Created: / 3.8.1998 / 14:47:58 / cg"
16400
6c38fd2957bc class: ImmutableString
Claus Gittinger <cg@exept.de>
parents: 14386
diff changeset
   248
!
6c38fd2957bc class: ImmutableString
Claus Gittinger <cg@exept.de>
parents: 14386
diff changeset
   249
6c38fd2957bc class: ImmutableString
Claus Gittinger <cg@exept.de>
parents: 14386
diff changeset
   250
speciesForCopy
6c38fd2957bc class: ImmutableString
Claus Gittinger <cg@exept.de>
parents: 14386
diff changeset
   251
    "Copies should be mutable"
6c38fd2957bc class: ImmutableString
Claus Gittinger <cg@exept.de>
parents: 14386
diff changeset
   252
6c38fd2957bc class: ImmutableString
Claus Gittinger <cg@exept.de>
parents: 14386
diff changeset
   253
    ^ String
6c38fd2957bc class: ImmutableString
Claus Gittinger <cg@exept.de>
parents: 14386
diff changeset
   254
6c38fd2957bc class: ImmutableString
Claus Gittinger <cg@exept.de>
parents: 14386
diff changeset
   255
    "Created: / 3.8.1998 / 14:47:58 / cg"
3714
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
! !
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
14386
27b494f48340 isImmutable
Claus Gittinger <cg@exept.de>
parents: 14222
diff changeset
   258
!ImmutableString methodsFor:'queries'!
27b494f48340 isImmutable
Claus Gittinger <cg@exept.de>
parents: 14222
diff changeset
   259
27b494f48340 isImmutable
Claus Gittinger <cg@exept.de>
parents: 14222
diff changeset
   260
isImmutable
27b494f48340 isImmutable
Claus Gittinger <cg@exept.de>
parents: 14222
diff changeset
   261
    ^ true
27b494f48340 isImmutable
Claus Gittinger <cg@exept.de>
parents: 14222
diff changeset
   262
! !
27b494f48340 isImmutable
Claus Gittinger <cg@exept.de>
parents: 14222
diff changeset
   263
3714
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   264
!ImmutableString methodsFor:'specials'!
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
12538
e6bf8c42e1d4 Moved to libbasic from libcomp - change package name
Stefan Vogel <sv@exept.de>
parents: 12491
diff changeset
   266
become:anotherObject
3714
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   267
    "trigger an error if I should become something else
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
     (this would be an even more tricky manipulation)"
12538
e6bf8c42e1d4 Moved to libbasic from libcomp - change package name
Stefan Vogel <sv@exept.de>
parents: 12491
diff changeset
   269
12491
d74b78dd478a Raise NoModificationError
Stefan Vogel <sv@exept.de>
parents: 12471
diff changeset
   270
    self noModificationError.
3714
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   271
    ^ super become:anotherObject
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   272
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   273
    "Created: / 3.8.1998 / 14:48:29 / cg"
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   274
!
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   275
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   276
becomeNil
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   277
    "trigger an error if I should become nil
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   278
     (this would be an even more tricky manipulation)"
12538
e6bf8c42e1d4 Moved to libbasic from libcomp - change package name
Stefan Vogel <sv@exept.de>
parents: 12491
diff changeset
   279
12491
d74b78dd478a Raise NoModificationError
Stefan Vogel <sv@exept.de>
parents: 12471
diff changeset
   280
    self noModificationError.
3714
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   281
    ^ super becomeNil
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   282
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   283
    "Created: / 3.8.1998 / 14:48:37 / cg"
18704
e1dc90e637b9 class: ImmutableString
Stefan Vogel <sv@exept.de>
parents: 18546
diff changeset
   284
!
e1dc90e637b9 class: ImmutableString
Stefan Vogel <sv@exept.de>
parents: 18546
diff changeset
   285
e1dc90e637b9 class: ImmutableString
Stefan Vogel <sv@exept.de>
parents: 18546
diff changeset
   286
becomeSameAs:anotherObject
e1dc90e637b9 class: ImmutableString
Stefan Vogel <sv@exept.de>
parents: 18546
diff changeset
   287
    "trigger an error if I should become something else
e1dc90e637b9 class: ImmutableString
Stefan Vogel <sv@exept.de>
parents: 18546
diff changeset
   288
     (this would be an even more tricky manipulation)"
e1dc90e637b9 class: ImmutableString
Stefan Vogel <sv@exept.de>
parents: 18546
diff changeset
   289
e1dc90e637b9 class: ImmutableString
Stefan Vogel <sv@exept.de>
parents: 18546
diff changeset
   290
    self noModificationError.
e1dc90e637b9 class: ImmutableString
Stefan Vogel <sv@exept.de>
parents: 18546
diff changeset
   291
    ^ super becomeSameAs:anotherObject
3714
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   292
! !
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   293
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   294
!ImmutableString class methodsFor:'documentation'!
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   295
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   296
version
18546
23c33cdd1f43 class: ImmutableString
Stefan Vogel <sv@exept.de>
parents: 17373
diff changeset
   297
    ^ '$Header$'
12457
7094a6561516 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9412
diff changeset
   298
!
7094a6561516 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9412
diff changeset
   299
7094a6561516 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9412
diff changeset
   300
version_CVS
18546
23c33cdd1f43 class: ImmutableString
Stefan Vogel <sv@exept.de>
parents: 17373
diff changeset
   301
    ^ '$Header$'
3714
62524619bfb7 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   302
! !
16400
6c38fd2957bc class: ImmutableString
Claus Gittinger <cg@exept.de>
parents: 14386
diff changeset
   303