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