Unicode16String.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 26 Apr 2010 19:26:38 +0100
branchjv
changeset 17761 b0e5971141bc
parent 17711 39faaaf888b4
child 17845 7e0cfaac936d
permissions -rw-r--r--
Added Lookup and BuiltinLookup classes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7946
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 1997 by eXept Software AG 
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
	      All Rights Reserved
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
10223
761e2a050b69 twoByteString moved (req'd in VM)
Claus Gittinger <cg@exept.de>
parents: 9648
diff changeset
    12
"{ Package: 'stx:libbasic' }"
7946
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
TwoByteString variableWordSubclass:#Unicode16String
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
	instanceVariableNames:''
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
	classVariableNames:''
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	poolDictionaries:''
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	category:'Collections-Text'
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
!
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!Unicode16String class methodsFor:'documentation'!
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
copyright
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
"
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
 COPYRIGHT (c) 1997 by eXept Software AG 
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
	      All Rights Reserved
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
 This software is furnished under a license and may be used
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
 only in accordance with the terms of that license and with the
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 be provided or otherwise made available to, or used by, any
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 other person.  No title to or ownership of the software is
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 hereby transferred.
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
"
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
!
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
documentation
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
"
10223
761e2a050b69 twoByteString moved (req'd in VM)
Claus Gittinger <cg@exept.de>
parents: 9648
diff changeset
    41
    Represents 16-bit (2-byte) Unicode strings.
7946
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
"
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
! !
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
!Unicode16String class methodsFor:'initialization'!
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
initialize
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
    "initialize the class - private"
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
7949
421a3e216337 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7946
diff changeset
    50
    self flags:(Behavior flagWords).
421a3e216337 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7946
diff changeset
    51
421a3e216337 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7946
diff changeset
    52
    Smalltalk at:#UnicodeString put:Unicode16String.
7946
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
    "
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
     Unicode16String initialize
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
    "
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
    "Created: 30.6.1997 / 15:35:52 / cg"
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
    "Modified: 30.6.1997 / 15:39:21 / cg"
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
! !
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
11323
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
    62
!Unicode16String class methodsFor:'reading'!
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
    63
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
    64
readFrom:aStreamOrString onError:exceptionBlock
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
    65
    "read & return the next String from the (character-)stream aStream;
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
    66
     skipping all whitespace first; return the value of exceptionBlock,
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
    67
     if no string can be read. The sequence of characters as read from the
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
    68
     stream must be one as stored via storeOn: or storeString."
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
    69
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
    70
    "
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
    71
     this method is not to be inherited
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
    72
     (i.e. not ok for subclasses; Symbol, for example)
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
    73
    "
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
    74
    self ~~ Unicode16String ifTrue:[
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
    75
        ^ super readFrom:aStreamOrString onError:exceptionBlock
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
    76
    ].
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
    77
    ^ self readSmalltalkStringFrom:aStreamOrString onError:exceptionBlock
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
    78
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
    79
    "
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
    80
        self readFrom:'abcäöü' storeString
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
    81
    "
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
    82
! !
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
    83
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
    84
7946
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
!Unicode16String methodsFor:'conversion'!
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
asSymbolIfInterned
9232
baa662ecbc01 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8942
diff changeset
    88
    "If a symbol with the receivers characters is already known, return it. Otherwise, return nil. 
baa662ecbc01 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8942
diff changeset
    89
     Because ST/X does not support non-8-bit symbols, this method
8942
41d4d78ceb65 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8407
diff changeset
    90
     has been redefined to only return a symbol, if the receiver does NOT contain
41d4d78ceb65 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8407
diff changeset
    91
     any non-8 bit characters."
41d4d78ceb65 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8407
diff changeset
    92
7946
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
    |s|
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
    Error catch:[
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
        s := self asSingleByteString.
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
    ].
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
    s isNil ifTrue:[^ s].
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
    ^ s asSymbolIfInterned
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
!
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
8294
ba5f4421848f Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents: 8049
diff changeset
   102
asUnicode16String
8942
41d4d78ceb65 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8407
diff changeset
   103
    "as the receiver already is a unicode-16 string, return it"
41d4d78ceb65 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8407
diff changeset
   104
8294
ba5f4421848f Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents: 8049
diff changeset
   105
    ^ self
ba5f4421848f Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents: 8049
diff changeset
   106
!
ba5f4421848f Define #asUnicode16String and #asUnicode32String
Stefan Vogel <sv@exept.de>
parents: 8049
diff changeset
   107
7946
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
asUnicodeString
8942
41d4d78ceb65 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8407
diff changeset
   109
    "as the receiver already is a unicode string, return it"
41d4d78ceb65 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8407
diff changeset
   110
7946
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
    ^ self
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
! !
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
8049
ccd0e8f26439 printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents: 7982
diff changeset
   114
!Unicode16String methodsFor:'printing & storing'!
ccd0e8f26439 printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents: 7982
diff changeset
   115
11323
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
   116
printOn:aStream
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
   117
    "print the receiver on aStream. 
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
   118
     Let aStream decide how to represent this, wether utf8, ucs16, ..."
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
   119
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
   120
    aStream nextPutAllUnicode:self
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
   121
!
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
   122
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
   123
storeOn:aStream
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
   124
    "put the storeString of myself on aStream"
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
   125
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
   126
    aStream nextPut:$'.
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
   127
    (self includes:$') ifTrue:[
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
   128
        self do:[:thisChar |
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
   129
            (thisChar == $') ifTrue:[aStream nextPut:thisChar].
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
   130
            aStream nextPutUnicode:thisChar
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
   131
        ]
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
   132
    ] ifFalse:[
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
   133
        aStream nextPutAllUnicode:self
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
   134
    ].
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
   135
    aStream nextPut:$'
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
   136
!
c9ebe199a8fc Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 11293
diff changeset
   137
8049
ccd0e8f26439 printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents: 7982
diff changeset
   138
storeString
ccd0e8f26439 printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents: 7982
diff changeset
   139
    "return a String for storing myself"
ccd0e8f26439 printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents: 7982
diff changeset
   140
ccd0e8f26439 printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents: 7982
diff changeset
   141
    ^ self basicStoreString.
ccd0e8f26439 printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents: 7982
diff changeset
   142
! !
ccd0e8f26439 printing - migrating towards unicodeSupport in ST-code
Claus Gittinger <cg@exept.de>
parents: 7982
diff changeset
   143
7946
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
!Unicode16String class methodsFor:'documentation'!
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
version
17761
b0e5971141bc Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   147
    ^ '$Id: Unicode16String.st 10517 2010-04-26 18:26:38Z vranyj1 $'
b0e5971141bc Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   148
!
b0e5971141bc Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   149
b0e5971141bc Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   150
version_SVN
b0e5971141bc Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   151
    ^ '$Id: Unicode16String.st 10517 2010-04-26 18:26:38Z vranyj1 $'
7946
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
! !
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
469d2d1c61f1 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
Unicode16String initialize!