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