--- a/CharacterArray.st Sun May 12 16:02:33 1996 +0200
+++ b/CharacterArray.st Sun May 12 16:47:30 1996 +0200
@@ -2099,13 +2099,11 @@
!
asText
- "ST-80 compatibility
- - ST/X does not (as today) support composedTexts."
+ "return a Text-object (collection of lines) from myself."
^ Text fromString:self
- "Modified: 27.4.1996 / 13:30:30 / cg"
- "Created: 11.5.1996 / 14:10:44 / cg"
+ "Created: 12.5.1996 / 10:41:14 / cg"
!
asTwoByteString
@@ -2217,7 +2215,19 @@
"display the receiver in a graphicsContext - this method allows
strings to be used like DisplayObjects."
- ^ aGc displayString:self x:x y:y.
+ ^ aGc displayString:self string x:x y:y.
+
+ "Modified: 11.5.1996 / 14:42:48 / cg"
+!
+
+displayOpaqueOn:aGc x:x y:y
+ "display the receiver in a graphicsContext - this method allows
+ strings to be used like DisplayObjects."
+
+ ^ aGc displayOpaqueString:self string x:x y:y.
+
+ "Modified: 11.5.1996 / 14:42:48 / cg"
+ "Created: 12.5.1996 / 12:28:40 / cg"
! !
!CharacterArray methodsFor:'emphasis'!
@@ -2785,13 +2795,9 @@
!
hasChangeOfEmphasis
- "return true, if the receiver has any emphasis changes in it.
- False is returned here, to have Strings be usable interchangeable with
- Text objects"
-
^ false
- "Created: 11.5.1996 / 14:02:53 / cg"
+ "Created: 12.5.1996 / 12:31:39 / cg"
!
isString
@@ -3006,7 +3012,7 @@
srcIdx "{ SmallInteger }"
dstIdx "{ SmallInteger }"
val "{ SmallInteger }"
- newString next|
+ newString next hasEmphasis e|
"
first, count the number of escapes, to allow preallocation
@@ -3035,12 +3041,18 @@
].
newString := self species new:newSize.
+
+ hasEmphasis := self hasChangeOfEmphasis.
+
"
copy over, replace escapes
"
srcIdx := dstIdx := 1.
[srcIdx <= sz] whileTrue:[
next := self at:srcIdx.
+ hasEmphasis ifTrue:[
+ e := self emphasisAt:srcIdx
+ ].
srcIdx := srcIdx + 1.
next == $\ ifTrue:[
srcIdx <= sz ifTrue:[
@@ -3082,6 +3094,9 @@
].
].
newString at:dstIdx put:next.
+ hasEmphasis ifTrue:[
+ newString emphasisAt:dstIdx put:e
+ ].
dstIdx := dstIdx + 1.
].
^ newString
@@ -3098,7 +3113,7 @@
'hello\r\nworld' withEscapes
"
- "Modified: 23.2.1996 / 23:25:43 / cg"
+ "Modified: 12.5.1996 / 12:53:34 / cg"
!
withTabs
@@ -3141,27 +3156,65 @@
otherwise a new string is returned.
This does handle multiline strings."
- |idx "{ SmallInteger }" str|
+ |col "{ SmallInteger }"
+ str ch
+ dstIdx "{ SmallInteger }"
+ newSz "{ SmallInteger }"
+ sz "{ SmallInteger }"
+ hasEmphasis e|
(self includes:(Character tab)) ifFalse:[^ self].
- str := WriteStream on:String new.
-
- idx := 1.
- self do:[:ch |
- ch == Character tab ifFalse:[
- idx := idx + 1.
- ch == Character cr ifTrue:[
- idx := 1
- ].
- str nextPut:ch.
- ] ifTrue:[
- (idx \\ 8) to:8 do:[:ii |
- str space.
- idx := idx + 1
- ].
- ]
+
+ sz := self size.
+
+ "/ count the new size first, instead of
+ "/ multiple resizing (better for large strings)
+
+ col := 1. newSz := 0.
+ 1 to:sz do:[:srcIdx |
+ ch := self at:srcIdx.
+ ch == Character tab ifFalse:[
+ col := col + 1.
+ newSz := newSz + 1.
+ ch == Character cr ifTrue:[
+ col := 1
+ ].
+ ] ifTrue:[
+ (col \\ 8) to:8 do:[:ii |
+ newSz := newSz + 1.
+ col := col + 1
+ ].
+ ]
].
- ^ str contents
+
+ str := self species new:newSz.
+
+ hasEmphasis := self hasChangeOfEmphasis.
+
+ col := 1. dstIdx := 1.
+ 1 to:sz do:[:srcIdx |
+ ch := self at:srcIdx.
+
+ ch == Character tab ifFalse:[
+ col := col + 1.
+ ch == Character cr ifTrue:[
+ col := 1
+ ].
+ hasEmphasis ifTrue:[
+ e := self emphasisAt:srcIdx.
+ str emphasisAt:dstIdx put:e
+ ].
+ str at:dstIdx put:ch.
+ dstIdx := dstIdx + 1
+ ] ifTrue:[
+ (col \\ 8) to:8 do:[:ii |
+ str at:dstIdx put:Character space.
+ dstIdx := dstIdx + 1.
+ col := col + 1
+ ].
+ ]
+ ].
+ ^ str
"
('1' , Character tab asString , 'x') withTabsExpanded
@@ -3172,22 +3225,22 @@
('123456789' , Character tab asString , 'x') withTabsExpanded
(String with:Character tab
- with:Character tab
- with:$1) withTabsExpanded
+ with:Character tab
+ with:$1) withTabsExpanded
(String with:Character tab
- with:$1
- with:Character tab
- with:$2) withTabsExpanded
+ with:$1
+ with:Character tab
+ with:$2) withTabsExpanded
(String with:Character tab
- with:$1
- with:Character cr
- with:Character tab
- with:$2) withTabsExpanded
+ with:$1
+ with:Character cr
+ with:Character tab
+ with:$2) withTabsExpanded
"
- "Modified: 11.12.1995 / 15:27:50 / cg"
+ "Modified: 12.5.1996 / 13:05:10 / cg"
!
withoutCRs
@@ -3490,6 +3543,24 @@
"
!
+endsWith:aString
+ "return true, if the receiver ends with something, aString."
+
+ |s|
+
+ (s := self string) ~~ self ifTrue:[
+ ^ s endsWith:aString
+ ].
+ ^ super endsWith:aString
+
+ "
+ 'hello world' endsWith:'world'
+ 'hello world' asText allBold endsWith:'world'
+ "
+
+ "Modified: 12.5.1996 / 15:49:18 / cg"
+!
+
isAlphaNumeric
"return true, if the receiver is some alphanumeric word;
i.e. consists of a letter followed by letters or digits."
@@ -3719,10 +3790,29 @@
'Smalltalk' spellAgainst: 'smalltlk'
'Smalltalk' spellAgainst: 'Smalltolk'
"
+!
+
+startsWith:aString
+ "return true, if the receiver starts with something, aString."
+
+ |s|
+
+ (s := self string) ~~ self ifTrue:[
+ ^ s startsWith:aString
+ ].
+ ^ super startsWith:aString
+
+ "
+ 'hello world' startsWith:'hello'
+ 'hello world' asText allBold startsWith:'hello'
+ "
+
+ "Created: 12.5.1996 / 15:46:40 / cg"
+ "Modified: 12.5.1996 / 15:49:24 / cg"
! !
!CharacterArray class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.83 1996-05-11 12:36:48 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.84 1996-05-12 14:47:30 cg Exp $'
! !