Unicode16String.st
branchjv
changeset 18971 13360506ef81
parent 18120 e3a375d5f6a8
parent 18970 f4c3afd137e3
child 19227 5e949760a4e8
equal deleted inserted replaced
18965:0b89780d7810 18971:13360506ef81
    59 
    59 
    60     "Created: 30.6.1997 / 15:35:52 / cg"
    60     "Created: 30.6.1997 / 15:35:52 / cg"
    61     "Modified: 30.6.1997 / 15:39:21 / cg"
    61     "Modified: 30.6.1997 / 15:39:21 / cg"
    62 ! !
    62 ! !
    63 
    63 
       
    64 
    64 !Unicode16String class methodsFor:'reading'!
    65 !Unicode16String class methodsFor:'reading'!
    65 
    66 
    66 readFrom:aStreamOrString onError:exceptionBlock
    67 readFrom:aStreamOrString onError:exceptionBlock
    67     "read & return the next String from the (character-)stream aStream;
    68     "read & return the next String from the (character-)stream aStream;
    68      skipping all whitespace first; return the value of exceptionBlock,
    69      skipping all whitespace first; return the value of exceptionBlock,
    83     "
    84     "
    84 ! !
    85 ! !
    85 
    86 
    86 
    87 
    87 !Unicode16String methodsFor:'conversion'!
    88 !Unicode16String methodsFor:'conversion'!
    88 
       
    89 asSymbolIfInterned
       
    90     "If a symbol with the receiver's characters is already known, return it. Otherwise, return nil. 
       
    91      Because ST/X does not support non-8-bit symbols, this method
       
    92      has been redefined to only return a symbol, if the receiver does NOT contain
       
    93      any non-8 bit characters."
       
    94 
       
    95     |s|
       
    96 
       
    97     [
       
    98         s := self asSingleByteString.
       
    99     ] on:Error do:[:ex|
       
   100         ^ nil.
       
   101     ].
       
   102     ^ s asSymbolIfInterned
       
   103 
       
   104     "
       
   105      (Unicode16String with:(Character value:16rFFFF)) asSymbolIfInterned
       
   106      'new' asUnicodeString asSymbolIfInterned
       
   107     "
       
   108 !
       
   109 
    89 
   110 asUnicode16String
    90 asUnicode16String
   111     "as the receiver already is a unicode-16 string, return it"
    91     "as the receiver already is a unicode-16 string, return it"
   112 
    92 
   113     ^ self
    93     ^ self
   147 !
   127 !
   148 
   128 
   149 storeOn:aStream
   129 storeOn:aStream
   150     "put the storeString of myself on aStream"
   130     "put the storeString of myself on aStream"
   151 
   131 
   152     self utf8Encoded storeOn:aStream.
   132     self containsNon7BitAscii ifTrue:[
   153     aStream nextPutAll:' utf8Decoded'.
   133         "non-7bit string has been utf8Encoded"
       
   134         self utf8Encoded storeOn:aStream.
       
   135         aStream nextPutAll:' utf8Decoded'.
       
   136     ] ifFalse:[
       
   137         self asSingleByteString storeOn:aStream.
       
   138     ].
       
   139 
       
   140     "
       
   141         String streamContents:[:s|
       
   142             'hello' asUnicodeString storeOn:s
       
   143         ].
       
   144 
       
   145         String streamContents:[:s|
       
   146             'hello -öäüß' asUnicodeString storeOn:s
       
   147         ].
       
   148     "
   154 
   149 
   155 "/    aStream nextPut:$'.
   150 "/    aStream nextPut:$'.
   156 "/    (self includes:$') ifTrue:[
   151 "/    (self includes:$') ifTrue:[
   157 "/        self do:[:thisChar |
   152 "/        self do:[:thisChar |
   158 "/            (thisChar == $') ifTrue:[aStream nextPut:thisChar].
   153 "/            (thisChar == $') ifTrue:[aStream nextPut:thisChar].
   167 !
   162 !
   168 
   163 
   169 storeString
   164 storeString
   170     "return a String for storing myself"
   165     "return a String for storing myself"
   171 
   166 
   172 "/    ^ self basicStoreString.
   167     self containsNon7BitAscii ifTrue:[
   173 "/    ^ (self withCEscapes storeString),' withoutCEscapes'.
   168         "non-7bit string has been utf8Encoded"
   174     ^ (self utf8Encoded storeString),' utf8Decoded'.
   169         ^ (self utf8Encoded storeString),' utf8Decoded'.
       
   170     ] ifFalse:[
       
   171         ^ self asSingleByteString storeString.
       
   172     ].
       
   173 
       
   174     "
       
   175         'hello' asUnicodeString storeString
       
   176         'hello -öäüß' storeString
       
   177         'hello -öäüß' asUnicodeString storeString
       
   178     "
   175 
   179 
   176     "Modified: / 25-01-2012 / 11:59:34 / cg"
   180     "Modified: / 25-01-2012 / 11:59:34 / cg"
   177 !
   181 !
   178 
   182 
   179 unicodeStoreOn:aStream
   183 unicodeStoreOn:aStream
   211 
   215 
   212 
   216 
   213 !Unicode16String class methodsFor:'documentation'!
   217 !Unicode16String class methodsFor:'documentation'!
   214 
   218 
   215 version
   219 version
   216     ^ '$Header: /cvs/stx/stx/libbasic/Unicode16String.st,v 1.23 2015-02-20 23:59:30 cg Exp $'
   220     ^ '$Header$'
   217 !
   221 !
   218 
   222 
   219 version_CVS
   223 version_CVS
   220     ^ '$Header: /cvs/stx/stx/libbasic/Unicode16String.st,v 1.23 2015-02-20 23:59:30 cg Exp $'
   224     ^ '$Header$'
   221 ! !
   225 ! !
   222 
   226 
   223 
   227 
   224 Unicode16String initialize!
   228 Unicode16String initialize!