Unicode32String.st
author Claus Gittinger <cg@exept.de>
Sat, 02 May 2020 21:40:13 +0200
changeset 5476 7355a4b11cb6
parent 5433 45176601c636
permissions -rw-r--r--
#FEATURE by cg class: Socket class added: #newTCPclientToHost:port:domain:domainOrder:withTimeout: changed: #newTCPclientToHost:port:domain:withTimeout:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1404
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 2004 by eXept Software AG 
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
              All Rights Reserved
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
1411
1cb88c3dbd22 encoding now unicode
Claus Gittinger <cg@exept.de>
parents: 1404
diff changeset
    12
"{ Package: 'stx:libbasic2' }"
1404
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
3663
2c9a059e292d #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3454
diff changeset
    14
"{ NameSpace: Smalltalk }"
2c9a059e292d #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3454
diff changeset
    15
1404
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
FourByteString variableLongSubclass:#Unicode32String
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	instanceVariableNames:''
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	classVariableNames:''
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	poolDictionaries:''
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	category:'Collections-Text'
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!Unicode32String class methodsFor:'documentation'!
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
copyright
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
"
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
 COPYRIGHT (c) 2004 by eXept Software AG 
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
              All Rights Reserved
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 This software is furnished under a license and may be used
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 only in accordance with the terms of that license and with the
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 be provided or otherwise made available to, or used by, any
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 other person.  No title to or ownership of the software is
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 hereby transferred.
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
"
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
!
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
documentation
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
"
1573
dec4f78e857b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1460
diff changeset
    43
    Not yet fully finished - unicode support is still being implemented.
1404
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
"
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
! !
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
!Unicode32String class methodsFor:'initialization'!
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
initialize
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
    "initialize the class - private"
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
    self flags:(Behavior flagLongs)
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
    "
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
     Unicode32String initialize
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
    "
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
    "Created: 30.6.1997 / 15:35:52 / cg"
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
    "Modified: 30.6.1997 / 15:39:21 / cg"
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
! !
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
2052
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
    62
!Unicode32String class methodsFor:'reading'!
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
    63
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
    64
readFrom:aStreamOrString onError:exceptionBlock
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
    65
    "read & return the next String from the (character-)stream aStream;
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
    66
     skipping all whitespace first; return the value of exceptionBlock,
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
    67
     if no string can be read. The sequence of characters as read from the
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
    68
     stream must be one as stored via storeOn: or storeString."
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
    69
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
    70
    "
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
    71
     this method is not to be inherited
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
    72
     (i.e. not ok for subclasses; Symbol, for example)
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
    73
    "
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
    74
    self ~~ Unicode32String ifTrue:[
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
    75
        ^ super readFrom:aStreamOrString onError:exceptionBlock
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
    76
    ].
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
    77
    ^ self readSmalltalkStringFrom:aStreamOrString onError:exceptionBlock
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
    78
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
    79
    "
5433
45176601c636 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5265
diff changeset
    80
        self readFrom:'abcäöü' storeString
45176601c636 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5265
diff changeset
    81
        String readFrom:'abcäöü' storeString
2052
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
    82
    "
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
    83
! !
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
    84
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
    85
1404
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
!Unicode32String methodsFor:'conversion'!
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
4965
cb05c61f9204 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3872
diff changeset
    88
asUnicode16StringReplaceInvalidWith:replacementCharacter
cb05c61f9204 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3872
diff changeset
    89
    "return the receiver converted to a 'normal' string,
cb05c61f9204 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3872
diff changeset
    90
     with invalid characters replaced by replacementCharacter.
cb05c61f9204 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3872
diff changeset
    91
     Can be used to convert from 16-bit strings to 8-bit strings
cb05c61f9204 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3872
diff changeset
    92
     and replace characters above code-255 with some replacement."
cb05c61f9204 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3872
diff changeset
    93
cb05c61f9204 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3872
diff changeset
    94
    |newString sz "{ Class:SmallInteger }"|
cb05c61f9204 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3872
diff changeset
    95
cb05c61f9204 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3872
diff changeset
    96
    sz := self size.
cb05c61f9204 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3872
diff changeset
    97
cb05c61f9204 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3872
diff changeset
    98
    newString := Unicode16String new:sz.
cb05c61f9204 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3872
diff changeset
    99
    1 to:sz do:[:idx |
cb05c61f9204 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3872
diff changeset
   100
        |char|
cb05c61f9204 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3872
diff changeset
   101
cb05c61f9204 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3872
diff changeset
   102
        char := self at:idx.
cb05c61f9204 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3872
diff changeset
   103
        char codePoint <= 16rFFFF ifTrue:[
cb05c61f9204 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3872
diff changeset
   104
            newString at:idx put:char
cb05c61f9204 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3872
diff changeset
   105
        ] ifFalse:[
cb05c61f9204 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3872
diff changeset
   106
            newString at:idx put:replacementCharacter
cb05c61f9204 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3872
diff changeset
   107
        ].
cb05c61f9204 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3872
diff changeset
   108
    ].
cb05c61f9204 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3872
diff changeset
   109
    ^ newString
cb05c61f9204 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3872
diff changeset
   110
cb05c61f9204 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3872
diff changeset
   111
    "Created: / 28-05-2019 / 12:13:57 / Stefan Vogel"
cb05c61f9204 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3872
diff changeset
   112
!
cb05c61f9204 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 3872
diff changeset
   113
1443
e971d86d6259 Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents: 1411
diff changeset
   114
asUnicode32String
1573
dec4f78e857b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1460
diff changeset
   115
    "as the receiver already is a unicode-32 string, return it"
dec4f78e857b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1460
diff changeset
   116
1443
e971d86d6259 Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents: 1411
diff changeset
   117
    ^ self
e971d86d6259 Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents: 1411
diff changeset
   118
!
e971d86d6259 Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents: 1411
diff changeset
   119
1404
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
asUnicodeString
1573
dec4f78e857b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1460
diff changeset
   121
    "as the receiver already is a unicode string, return it"
dec4f78e857b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1460
diff changeset
   122
1404
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
    ^ self
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
!
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
printOn:aStream
2052
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
   127
    "print the receiver on aStream. 
3065
8488543e42fa class: Unicode32String
Claus Gittinger <cg@exept.de>
parents: 2740
diff changeset
   128
     Let aStream decide how to represent this, whether utf8, ucs16, ..."
2052
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
   129
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
   130
    aStream nextPutAllUnicode:self
3065
8488543e42fa class: Unicode32String
Claus Gittinger <cg@exept.de>
parents: 2740
diff changeset
   131
8488543e42fa class: Unicode32String
Claus Gittinger <cg@exept.de>
parents: 2740
diff changeset
   132
    "Modified (comment): / 27-07-2013 / 15:37:03 / cg"
2052
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
   133
! !
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
   134
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
   135
!Unicode32String methodsFor:'printing & storing'!
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
   136
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
   137
storeOn:aStream
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
   138
    "put the storeString of myself on aStream"
1573
dec4f78e857b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1460
diff changeset
   139
3663
2c9a059e292d #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3454
diff changeset
   140
    self containsNon7BitAscii ifTrue:[
2c9a059e292d #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3454
diff changeset
   141
        "non-7bit string has been utf8Encoded"
2c9a059e292d #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3454
diff changeset
   142
        self utf8Encoded storeOn:aStream.
2c9a059e292d #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3454
diff changeset
   143
        aStream nextPutAll:' utf8Decoded'.
2c9a059e292d #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3454
diff changeset
   144
    ] ifFalse:[
2c9a059e292d #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3454
diff changeset
   145
        self asSingleByteString storeOn:aStream.
2c9a059e292d #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3454
diff changeset
   146
    ].
2c9a059e292d #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3454
diff changeset
   147
2c9a059e292d #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3454
diff changeset
   148
    "
2c9a059e292d #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3454
diff changeset
   149
        String streamContents:[:s|
2c9a059e292d #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3454
diff changeset
   150
            'hello' asUnicode32String storeOn:s
2c9a059e292d #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3454
diff changeset
   151
        ].
2c9a059e292d #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3454
diff changeset
   152
2c9a059e292d #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3454
diff changeset
   153
        String streamContents:[:s|
5433
45176601c636 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5265
diff changeset
   154
            'hello -öäüß' asUnicode32String storeOn:s
3663
2c9a059e292d #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3454
diff changeset
   155
        ].
2c9a059e292d #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3454
diff changeset
   156
    "
2c9a059e292d #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3454
diff changeset
   157
2664
8c8745eac73d unicode storestring fixed
Claus Gittinger <cg@exept.de>
parents: 2052
diff changeset
   158
"/    aStream nextPut:$'.
8c8745eac73d unicode storestring fixed
Claus Gittinger <cg@exept.de>
parents: 2052
diff changeset
   159
"/    (self includes:$') ifTrue:[
8c8745eac73d unicode storestring fixed
Claus Gittinger <cg@exept.de>
parents: 2052
diff changeset
   160
"/        self do:[:thisChar |
8c8745eac73d unicode storestring fixed
Claus Gittinger <cg@exept.de>
parents: 2052
diff changeset
   161
"/            (thisChar == $') ifTrue:[aStream nextPut:thisChar].
8c8745eac73d unicode storestring fixed
Claus Gittinger <cg@exept.de>
parents: 2052
diff changeset
   162
"/            aStream nextPutUnicode:thisChar
8c8745eac73d unicode storestring fixed
Claus Gittinger <cg@exept.de>
parents: 2052
diff changeset
   163
"/        ]
8c8745eac73d unicode storestring fixed
Claus Gittinger <cg@exept.de>
parents: 2052
diff changeset
   164
"/    ] ifFalse:[
8c8745eac73d unicode storestring fixed
Claus Gittinger <cg@exept.de>
parents: 2052
diff changeset
   165
"/        aStream nextPutAllUnicode:self
8c8745eac73d unicode storestring fixed
Claus Gittinger <cg@exept.de>
parents: 2052
diff changeset
   166
"/    ].
8c8745eac73d unicode storestring fixed
Claus Gittinger <cg@exept.de>
parents: 2052
diff changeset
   167
"/    aStream nextPut:$'
8c8745eac73d unicode storestring fixed
Claus Gittinger <cg@exept.de>
parents: 2052
diff changeset
   168
8c8745eac73d unicode storestring fixed
Claus Gittinger <cg@exept.de>
parents: 2052
diff changeset
   169
    "Modified: / 28-09-2011 / 16:18:43 / cg"
2052
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
   170
!
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
   171
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
   172
storeString
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
   173
    "return a String for storing myself"
80b8a0c74063 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 2048
diff changeset
   174
3663
2c9a059e292d #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3454
diff changeset
   175
    self containsNon7BitAscii ifTrue:[
2c9a059e292d #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3454
diff changeset
   176
        "non-7bit string has been utf8Encoded"
2c9a059e292d #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3454
diff changeset
   177
        ^ (self utf8Encoded storeString),' utf8Decoded'.
2c9a059e292d #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3454
diff changeset
   178
    ] ifFalse:[
2c9a059e292d #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3454
diff changeset
   179
        ^ self asSingleByteString storeString.
2c9a059e292d #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3454
diff changeset
   180
    ].
2664
8c8745eac73d unicode storestring fixed
Claus Gittinger <cg@exept.de>
parents: 2052
diff changeset
   181
3663
2c9a059e292d #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3454
diff changeset
   182
    "
2c9a059e292d #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3454
diff changeset
   183
        'hello' asUnicode32String storeString
5433
45176601c636 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5265
diff changeset
   184
        'hello -öäüß' storeString
45176601c636 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5265
diff changeset
   185
        'hello -öäüß' asUnicode32String storeString
3663
2c9a059e292d #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3454
diff changeset
   186
    "
2740
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   187
!
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   188
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   189
unicodeStoreOn:aStream
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   190
    "put the storeString of myself on aStream"
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   191
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   192
    aStream nextPut:$'.
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   193
    (self includes:$') ifTrue:[
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   194
        self do:[:thisChar |
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   195
            (thisChar == $') ifTrue:[aStream nextPut:thisChar].
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   196
            aStream nextPutUnicode:thisChar
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   197
        ]
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   198
    ] ifFalse:[
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   199
        aStream nextPutAllUnicode:self
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   200
    ].
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   201
    aStream nextPut:$'
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   202
!
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   203
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   204
unicodeStoreString
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   205
    "return a UnicodeString for storing myself.
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   206
     This method is a kind of kludge.
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   207
     Use it when you want to write a storeString to an encoded Stream"
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   208
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   209
    ^ self basicStoreString.
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   210
! !
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   211
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   212
!Unicode32String methodsFor:'testing'!
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   213
5433
45176601c636 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5265
diff changeset
   214
isLiteral
45176601c636 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5265
diff changeset
   215
    "return true, if the receiver can be used as a literal constant in ST syntax
45176601c636 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5265
diff changeset
   216
     (i.e. can be used in constant arrays)"
45176601c636 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5265
diff changeset
   217
45176601c636 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5265
diff changeset
   218
    ^ true
45176601c636 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5265
diff changeset
   219
!
45176601c636 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5265
diff changeset
   220
2740
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   221
isUnicode32String
3872
af31f9e3a160 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
   222
    "true if this is a 4-byte unicode string"
af31f9e3a160 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
   223
2740
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   224
    ^ true
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   225
!
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   226
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   227
isUnicodeString
3871
4840a5481281 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3663
diff changeset
   228
    "true if this is a 2- or 4-byte unicode string
4840a5481281 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3663
diff changeset
   229
     (i.e. not a single byte string).
4840a5481281 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3663
diff changeset
   230
     Notice, that the name is misleading: 
5265
5f6a992925c2 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 4965
diff changeset
   231
     all strings use unicode encoding"
3871
4840a5481281 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3663
diff changeset
   232
2740
Stefan Vogel <sv@exept.de>
parents: 2709
diff changeset
   233
    ^ true
5265
5f6a992925c2 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 4965
diff changeset
   234
5f6a992925c2 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 4965
diff changeset
   235
    "Modified (comment): / 21-11-2019 / 18:26:05 / Stefan Vogel"
1404
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
! !
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
!Unicode32String class methodsFor:'documentation'!
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
version
3663
2c9a059e292d #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3454
diff changeset
   241
    ^ '$Header$'
2709
0d45ae840f12 backward compatibility storestring
Claus Gittinger <cg@exept.de>
parents: 2708
diff changeset
   242
!
0d45ae840f12 backward compatibility storestring
Claus Gittinger <cg@exept.de>
parents: 2708
diff changeset
   243
0d45ae840f12 backward compatibility storestring
Claus Gittinger <cg@exept.de>
parents: 2708
diff changeset
   244
version_CVS
3663
2c9a059e292d #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3454
diff changeset
   245
    ^ '$Header$'
1404
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
! !
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
3065
8488543e42fa class: Unicode32String
Claus Gittinger <cg@exept.de>
parents: 2740
diff changeset
   248
1404
776eb9467dc3 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
Unicode32String initialize!