Unicode16String.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 19 Jan 2012 11:46:00 +0000
branchjv
changeset 17911 a99f15c5efa5
parent 17910 8d796ca8bd1d
child 17921 4069fe8e9039
permissions -rw-r--r--
Updated with /trunk

"
 COPYRIGHT (c) 1997 by eXept Software AG 
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
"{ Package: 'stx:libbasic' }"

TwoByteString variableWordSubclass:#Unicode16String
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Collections-Text'
!

!Unicode16String class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1997 by eXept Software AG 
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.


"
!

documentation
"
    Represents 16-bit (2-byte) Unicode strings.
"
! !

!Unicode16String class methodsFor:'initialization'!

initialize
    "initialize the class - private"

    self flags:(Behavior flagWords).

    Smalltalk at:#UnicodeString put:Unicode16String.

    "
     Unicode16String initialize
    "

    "Created: 30.6.1997 / 15:35:52 / cg"
    "Modified: 30.6.1997 / 15:39:21 / cg"
! !

!Unicode16String class methodsFor:'reading'!

readFrom:aStreamOrString onError:exceptionBlock
    "read & return the next String from the (character-)stream aStream;
     skipping all whitespace first; return the value of exceptionBlock,
     if no string can be read. The sequence of characters as read from the
     stream must be one as stored via storeOn: or storeString."

    "
     this method is not to be inherited
     (i.e. not ok for subclasses; Symbol, for example)
    "
    self ~~ Unicode16String ifTrue:[
        ^ super readFrom:aStreamOrString onError:exceptionBlock
    ].
    ^ self readSmalltalkStringFrom:aStreamOrString onError:exceptionBlock

    "
        self readFrom:'abc' storeString
    "
! !


!Unicode16String methodsFor:'conversion'!

asSymbolIfInterned
    "If a symbol with the receivers characters is already known, return it. Otherwise, return nil. 
     Because ST/X does not support non-8-bit symbols, this method
     has been redefined to only return a symbol, if the receiver does NOT contain
     any non-8 bit characters."

    |s|

    Error catch:[
        s := self asSingleByteString.
    ].
    s isNil ifTrue:[^ s].
    ^ s asSymbolIfInterned
!

asUnicode16String
    "as the receiver already is a unicode-16 string, return it"

    ^ self
!

asUnicodeString
    "as the receiver already is a unicode string, return it"

    ^ self
! !

!Unicode16String methodsFor:'printing & storing'!

printOn:aStream
    "print the receiver on aStream. 
     Let aStream decide how to represent this, wether utf8, ucs16, ..."

    aStream nextPutAllUnicode:self
!

storeOn:aStream
    "put the storeString of myself on aStream"

    (self utf8Encoded storeOn:aStream).
    aStream nextPutAll:' utf8Decoded'.

"/    aStream nextPut:$'.
"/    (self includes:$') ifTrue:[
"/        self do:[:thisChar |
"/            (thisChar == $') ifTrue:[aStream nextPut:thisChar].
"/            aStream nextPutUnicode:thisChar
"/        ]
"/    ] ifFalse:[
"/        aStream nextPutAllUnicode:self
"/    ].
"/    aStream nextPut:$'

    "Modified: / 28-09-2011 / 16:17:38 / cg"
!

storeString
    "return a String for storing myself"

"/    ^ self basicStoreString.
    ^ (self utf8Encoded storeString),' utf8Decoded'.

    "Modified: / 28-09-2011 / 16:18:07 / cg"
! !


!Unicode16String class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libbasic/Unicode16String.st,v 1.13 2011/09/28 14:31:24 cg Exp $'
!

version_SVN
    ^ '$Id: Unicode16String.st 10761 2012-01-19 11:46:00Z vranyj1 $'
! !

Unicode16String initialize!