CharacterArray.st
changeset 18657 fee4d5739a73
parent 18612 57db88d3a9fc
child 18662 3ad440593060
equal deleted inserted replaced
18656:fab035561c68 18657:fee4d5739a73
   357    invalid:
   357    invalid:
   358      CharacterArray fromUTF8Bytes:#[ 16rC0 16r80 ]
   358      CharacterArray fromUTF8Bytes:#[ 16rC0 16r80 ]
   359      CharacterArray fromUTF8Bytes:#[ 16rE0 16r80 16r80 ]
   359      CharacterArray fromUTF8Bytes:#[ 16rE0 16r80 16r80 ]
   360     "
   360     "
   361 ! !
   361 ! !
   362 
       
   363 
   362 
   364 !CharacterArray class methodsFor:'pattern matching'!
   363 !CharacterArray class methodsFor:'pattern matching'!
   365 
   364 
   366 matchEscapeCharacter
   365 matchEscapeCharacter
   367     "return the character used to escape a matchCharacter
   366     "return the character used to escape a matchCharacter
   764     characterSize <= 8 ifTrue:[^ String].
   763     characterSize <= 8 ifTrue:[^ String].
   765     characterSize <= 16 ifTrue:[^ Unicode16String].
   764     characterSize <= 16 ifTrue:[^ Unicode16String].
   766     ^ Unicode32String
   765     ^ Unicode32String
   767 ! !
   766 ! !
   768 
   767 
   769 
       
   770 !CharacterArray methodsFor:'Compatibility-ANSI'!
   768 !CharacterArray methodsFor:'Compatibility-ANSI'!
   771 
   769 
   772 addLineDelimiters
   770 addLineDelimiters
   773     "Ansi compatibility - same as withCRs"
   771     "Ansi compatibility - same as withCRs"
   774 
   772 
  3137     |newStr c bitsPerCharacter
  3135     |newStr c bitsPerCharacter
  3138      mySize "{ Class: SmallInteger }" |
  3136      mySize "{ Class: SmallInteger }" |
  3139 
  3137 
  3140     mySize := self size.
  3138     mySize := self size.
  3141     mySize == 0 ifTrue:[^ self].
  3139     mySize == 0 ifTrue:[^ self].
       
  3140 
  3142     newStr := self species new:mySize.
  3141     newStr := self species new:mySize.
  3143     bitsPerCharacter := newStr bitsPerCharacter.
  3142     bitsPerCharacter := newStr bitsPerCharacter.
  3144 
  3143 
       
  3144     "/ handle the very seldom case of an uppercase char which needs
       
  3145     "/ more bits in its lowercase variant 
       
  3146     "/ (there are only a few of them)
       
  3147 
       
  3148     "/ for 8-bit strings, use faster code.
       
  3149     bitsPerCharacter == 8 ifTrue:[
       
  3150         1 to:mySize do:[:i |
       
  3151             c := (self at:i) asLowercase.   
       
  3152             (c codePoint > 16rFF) ifTrue:[
       
  3153                 (c stringSpecies ~= newStr stringSpecies) ifTrue:[
       
  3154                     newStr := c stringSpecies fromString:newStr.
       
  3155                 ]
       
  3156             ].
       
  3157             newStr at:i put:c
       
  3158         ].
       
  3159         ^ newStr
       
  3160     ].
       
  3161 
  3145     1 to:mySize do:[:i |
  3162     1 to:mySize do:[:i |
  3146 	c := (self at:i) asLowercase.
  3163         c := (self at:i) asLowercase.
  3147 	(c bitsPerCharacter > bitsPerCharacter
  3164         (c bitsPerCharacter > bitsPerCharacter
  3148 	 and:[c stringSpecies ~= newStr stringSpecies]) ifTrue:[
  3165          and:[c stringSpecies ~= newStr stringSpecies]) ifTrue:[
  3149 	    newStr := c stringSpecies fromString:newStr.
  3166             newStr := c stringSpecies fromString:newStr.
  3150 	].
  3167         ].
  3151 	newStr at:i put:c
  3168         newStr at:i put:c
  3152     ].
  3169     ].
  3153     ^ newStr
  3170     ^ newStr
  3154 
  3171 
  3155     "
  3172     "
  3156      'HelloWorld' asLowercase
  3173      'HelloWorld' asLowercase
  3157      'HelloWorld' asLowercaseFirst
  3174      'HelloWorld' asLowercaseFirst
       
  3175      'HelloWorld' asUppercase
  3158     "
  3176     "
  3159 !
  3177 !
  3160 
  3178 
  3161 asLowercaseFirst
  3179 asLowercaseFirst
  3162     "return a copy of myself where the first character is converted to lowercase.
  3180     "return a copy of myself where the first character is converted to lowercase.
  3544     mySize := self size.
  3562     mySize := self size.
  3545     mySize == 0 ifTrue:[^ self].
  3563     mySize == 0 ifTrue:[^ self].
  3546     newStr := self species new:mySize.
  3564     newStr := self species new:mySize.
  3547     bitsPerCharacter := newStr bitsPerCharacter.
  3565     bitsPerCharacter := newStr bitsPerCharacter.
  3548 
  3566 
       
  3567     "/ handle the very seldom case of a lowercase char which needs
       
  3568     "/ more bits in its uppercase variant 
       
  3569     "/ (there are only a few of them)
       
  3570 
       
  3571     "/ for 8-bit strings, use faster code.
       
  3572     bitsPerCharacter == 8 ifTrue:[
       
  3573         1 to:mySize do:[:i |
       
  3574             c := (self at:i) asUppercase.   
       
  3575             (c codePoint > 16rFF) ifTrue:[
       
  3576                 (c stringSpecies ~= newStr stringSpecies) ifTrue:[
       
  3577                     newStr := c stringSpecies fromString:newStr.
       
  3578                 ]
       
  3579             ].
       
  3580             newStr at:i put:c
       
  3581         ].
       
  3582         ^ newStr
       
  3583     ].
       
  3584 
  3549     1 to:mySize do:[:i |
  3585     1 to:mySize do:[:i |
  3550 	c := (self at:i) asUppercase.
  3586         c := (self at:i) asUppercase.
  3551 	c bitsPerCharacter > bitsPerCharacter ifTrue:[
  3587         c bitsPerCharacter > bitsPerCharacter ifTrue:[
  3552 	    newStr := c stringSpecies fromString:newStr.
  3588             newStr := c stringSpecies fromString:newStr.
  3553 	].
  3589         ].
  3554 	newStr at:i put:c
  3590         newStr at:i put:c
  3555     ].
  3591     ].
  3556     ^ newStr
  3592     ^ newStr
  3557 
  3593 
  3558     "
  3594     "
  3559      'helloWorld' asUppercase
  3595      'helloWorld' asUppercase
  3560      'helloWorld' asUppercaseFirst
  3596      'helloWorld' asUppercaseFirst
  3561      (Character value:16rB5) asString asUppercase   -- needs 16 bits !!
  3597      (Character value:16rB5) asString asUppercase   -- needs 16 bits !!
       
  3598      (Character value:16rFF) asString asUppercase   -- needs 16 bits !!
  3562     "
  3599     "
  3563 !
  3600 !
  3564 
  3601 
  3565 asUppercaseFirst
  3602 asUppercaseFirst
  3566     "return a version of the receiver, where the first character is converted to uppercase.
  3603     "return a version of the receiver, where the first character is converted to uppercase.
  5736     "
  5773     "
  5737 
  5774 
  5738     "Created: 12.5.1996 / 20:09:29 / cg"
  5775     "Created: 12.5.1996 / 20:09:29 / cg"
  5739     "Modified: 17.4.1997 / 12:50:23 / cg"
  5776     "Modified: 17.4.1997 / 12:50:23 / cg"
  5740 ! !
  5777 ! !
  5741 
       
  5742 
  5778 
  5743 !CharacterArray methodsFor:'special string converting'!
  5779 !CharacterArray methodsFor:'special string converting'!
  5744 
  5780 
  5745 asUnixFilenameString
  5781 asUnixFilenameString
  5746     "return a new string consisting of receiver's characters
  5782     "return a new string consisting of receiver's characters
  6775      ('  ' , Character tab asString , ' foo   ') withoutTrailingSeparators inspect
  6811      ('  ' , Character tab asString , ' foo   ') withoutTrailingSeparators inspect
  6776      ('   foo' , Character tab asString) withoutTrailingSeparators inspect
  6812      ('   foo' , Character tab asString) withoutTrailingSeparators inspect
  6777     "
  6813     "
  6778 ! !
  6814 ! !
  6779 
  6815 
  6780 
       
  6781 !CharacterArray methodsFor:'substring searching'!
  6816 !CharacterArray methodsFor:'substring searching'!
  6782 
  6817 
  6783 findRangeOfString:subString
  6818 findRangeOfString:subString
  6784     "find a substring. if found, return the start- and endIndex;
  6819     "find a substring. if found, return the start- and endIndex;
  6785      if not found, return an empty interval."
  6820      if not found, return an empty interval."