CharacterArray.st
branchjv
changeset 18971 13360506ef81
parent 18942 b48824459593
parent 18967 427d31d13e56
child 18976 2cef520578de
equal deleted inserted replaced
18965:0b89780d7810 18971:13360506ef81
   134 !
   134 !
   135 
   135 
   136 fromString:aString
   136 fromString:aString
   137     "return a copy of the argument, aString"
   137     "return a copy of the argument, aString"
   138 
   138 
   139     ^ (self uninitializedNew:aString size) replaceFrom:1 with:aString
   139     |sz|
   140 
   140 
   141     "
   141     sz := aString size.
   142 	Unicode16String fromString:'hello'
   142     ^ (self uninitializedNew:sz) replaceFrom:1 to:sz with:aString startingAt:1
       
   143 
       
   144     "
       
   145         Unicode16String fromString:'hello'
   143     "
   146     "
   144 !
   147 !
   145 
   148 
   146 fromStringCollection:aCollectionOfStrings
   149 fromStringCollection:aCollectionOfStrings
   147     "return new string formed by concatenating a copy of the argument, aString"
   150     "return new string formed by concatenating a copy of the argument, aString"
  3271     "if possible, return the receiver converted to a 'normal' string.
  3274     "if possible, return the receiver converted to a 'normal' string.
  3272      It is only possible, if there are no characters with codePoints above 255 in the receiver.
  3275      It is only possible, if there are no characters with codePoints above 255 in the receiver.
  3273      If not possible, the (wideString) receiver is returned."
  3276      If not possible, the (wideString) receiver is returned."
  3274 
  3277 
  3275     self isWideString ifFalse:[^ self].
  3278     self isWideString ifFalse:[^ self].
  3276     (self contains:[:char | char codePoint > 255]) ifFalse:[^ self asSingleByteString].
  3279     self containsNon8BitElements ifTrue:[^ self].
  3277     ^ self
  3280     ^ self asSingleByteString
  3278 
  3281 
  3279     "
  3282     "
  3280      'hello' asSingleByteStringIfPossible
  3283      'hello' asSingleByteStringIfPossible
       
  3284      'hello' asText asSingleByteStringIfPossible
       
  3285      'hello' asUnicodeString asText asSingleByteStringIfPossible
  3281      'hello' asUnicodeString asSingleByteStringIfPossible
  3286      'hello' asUnicodeString asSingleByteStringIfPossible
  3282     "
  3287     "
  3283 !
  3288 !
  3284 
  3289 
  3285 asSingleByteStringReplaceInvalidWith:replacementCharacter
  3290 asSingleByteStringReplaceInvalidWith:replacementCharacter
  3333 !
  3338 !
  3334 
  3339 
  3335 asSymbolIfInterned
  3340 asSymbolIfInterned
  3336     "If a symbol with the receiver's characters is already known, return it. Otherwise, return nil.
  3341     "If a symbol with the receiver's characters is already known, return it. Otherwise, return nil.
  3337      This can be used to query for an existing symbol and is the same as:
  3342      This can be used to query for an existing symbol and is the same as:
  3338 	self knownAsSymbol ifTrue:[self asSymbol] ifFalse:[nil]
  3343         self knownAsSymbol ifTrue:[self asSymbol] ifFalse:[nil]
  3339      but slightly faster, since the symbol lookup operation is only performed once.
  3344      but slightly faster, since the symbol lookup operation is only performed once.
  3340      The receiver must be a singleByte-String.
  3345      The receiver must be a singleByte-String.
  3341      TwoByte- and FourByteSymbols are (currently ?) not allowed."
  3346      TwoByte- and FourByteSymbols are (currently ?) not allowed."
  3342 
  3347 
  3343     |s|
  3348     |str|
  3344 
  3349 
  3345 
  3350     str := self string.
  3346     s := self string.
  3351     str == self ifTrue:[
  3347     s ~~ self ifTrue:[
  3352         "must be some kind of N-ByteString"
  3348        ^ s asSymbolIfInterned
  3353         str := self asSingleByteStringIfPossible.
  3349     ].
  3354         str == self ifTrue:[
  3350     ^ nil.
  3355             "single byte string conversion is not possible"
       
  3356             ^ nil.
       
  3357         ].
       
  3358     ].
       
  3359     ^ str asSymbolIfInterned
       
  3360 
       
  3361     "
       
  3362      (Unicode16String with:(Character value:16rFFFF)) asSymbolIfInterned
       
  3363      'new' asUnicodeString asSymbolIfInterned
       
  3364      'new' asText asSymbolIfInterned
       
  3365      'new' asUnicodeString asText asSymbolIfInterned
       
  3366     "
  3351 
  3367 
  3352     "Created: 22.5.1996 / 16:37:04 / cg"
  3368     "Created: 22.5.1996 / 16:37:04 / cg"
  3353 !
  3369 !
  3354 
  3370 
  3355 asText
  3371 asText
  5503 
  5519 
  5504     "
  5520     "
  5505      'hello' bitsPerCharacter
  5521      'hello' bitsPerCharacter
  5506      'hello' asText allBold bitsPerCharacter
  5522      'hello' asText allBold bitsPerCharacter
  5507     "
  5523     "
       
  5524 !
       
  5525 
       
  5526 containsNon8BitElements
       
  5527     "return true, if the underlying string contains elements larger than a single byte"
       
  5528 
       
  5529     |sz "{ Class:SmallInteger }"|
       
  5530 
       
  5531     sz := self size.
       
  5532     1 to:sz do:[:idx|
       
  5533         (self at:idx) codePoint > 16rFF ifTrue:[
       
  5534             ^ true.
       
  5535         ].
       
  5536     ].
       
  5537     ^ false.
  5508 !
  5538 !
  5509 
  5539 
  5510 continuesWith:aString startingAt:startIndex
  5540 continuesWith:aString startingAt:startIndex
  5511     "return true, if the receiver beginning at startIndex
  5541     "return true, if the receiver beginning at startIndex
  5512      contains the characters in aString."
  5542      contains the characters in aString."