Grafoscopio/src/Grafoscopio/GrafoscopioPillarASTextStri...

206 lines
6.3 KiB
Smalltalk

Class {
#name : #GrafoscopioPillarASTextStringAdapter,
#superclass : #ProtoObject,
#instVars : [
'text'
],
#category : #'Grafoscopio-Pillar'
}
{ #category : #'as yet unclassified' }
GrafoscopioPillarASTextStringAdapter >> allRangesOfSubstring: aSubstring [
^ Array streamContents: [:s | | start subSize |
start := 1.
subSize := aSubstring size.
[start isZero]
whileFalse: [ start := self findString: aSubstring startingAt: start.
start > 0
ifTrue: [s nextPut: (start to: start + subSize - 1).
start := start + subSize]]]
]
{ #category : #'as yet unclassified' }
GrafoscopioPillarASTextStringAdapter >> asString [
^ self
]
{ #category : #accessing }
GrafoscopioPillarASTextStringAdapter >> at: aNumber [
^ text at: aNumber
]
{ #category : #accessing }
GrafoscopioPillarASTextStringAdapter >> at: aNumber put: aChar [
self halt
]
{ #category : #'as yet unclassified' }
GrafoscopioPillarASTextStringAdapter >> copyFrom: one to: two [
^ text copyFrom: one to: two
]
{ #category : #'as yet unclassified' }
GrafoscopioPillarASTextStringAdapter >> findString: key startingAt: start [
^ self findString: key startingAt: start caseSensitive: true
]
{ #category : #'as yet unclassified' }
GrafoscopioPillarASTextStringAdapter >> findString: key startingAt: start caseSensitive: caseSensitive [
"Answer the index in this String at which the substring key first occurs,
at or beyond start. The match can be case-sensitive or not. If no match
is found, zero will be returned."
"IMPLEMENTATION NOTE: do not use CaseSensitiveOrder because it is broken for WideString
This is a temporary work around until Wide CaseSensitiveOrder search is fixed
Code should revert to:
caseSensitive
ifTrue: [^ self findSubstring: key in: self startingAt: start matchTable: CaseSensitiveOrder]
ifFalse: [^ self findSubstring: key in: self startingAt: start matchTable: CaseInsensitiveOrder]"
^ caseSensitive
ifTrue: [ WideString new
findSubstring: key
in: self
startingAt: start
matchTable: nil ]
ifFalse: [ WideString new
findSubstring: key
in: self
startingAt: start
matchTable: String newCaseInsensitiveOrder ]
]
{ #category : #'as yet unclassified' }
GrafoscopioPillarASTextStringAdapter >> ifEmpty: aBlock [
"Evaluate the given block, answering its value if the receiver is empty, otherwise answer the receiver."
"Note that the fact that this method returns its receiver in case the receiver is not empty allows one to write expressions like the following ones: self classifyMethodAs: (myProtocol ifEmpty: ['As yet unclassified'])"
^ self isEmpty
ifTrue: [ aBlock value ]
ifFalse: [ self ]
]
{ #category : #'as yet unclassified' }
GrafoscopioPillarASTextStringAdapter >> ifEmpty: emptyBlock ifNotEmpty: notEmptyBlock [
"Evaluate emptyBlock if I'm empty, notEmptyBlock otherwise"
"If the notEmptyBlock has an argument, eval with the receiver as its argument"
^ self isEmpty
ifTrue: [ emptyBlock value ]
ifFalse: [ notEmptyBlock cull: self ]
]
{ #category : #'as yet unclassified' }
GrafoscopioPillarASTextStringAdapter >> indexOf: aCharacter startingAt: anInteger ifAbsent: aBlockClosure [
| current index |
current := text detectAstNodeFor: anInteger.
index := current text
indexOf: aCharacter
startingAt: anInteger - current textStart + 1.
current := current next.
[ current isNotNil ]
whileTrue: [ index := current text indexOf: aCharacter.
index = 0
ifTrue: [ current := current next ]
ifFalse: [ ^ current textStart + index ] ].
^ aBlockClosure value
]
{ #category : #'as yet unclassified' }
GrafoscopioPillarASTextStringAdapter >> isByteString [
^ false
]
{ #category : #'as yet unclassified' }
GrafoscopioPillarASTextStringAdapter >> isEmpty [
^ text isEmpty
]
{ #category : #accessing }
GrafoscopioPillarASTextStringAdapter >> isReadOnlyObject [
"Answer if the receiver is read-only.
If the VM supports read-only objects it will not write to read-only objects.
An attempt to write to an instance variable of a read-only object will
cause the VM to send attemptToAssign:withIndex: to the read-only object.
An attempt to modify a read-only object in a primitive will cause the
primitive to fail with a #'no modification' error code."
<primitive: 163 error: ec>
^self class isImmediateClass
]
{ #category : #'as yet unclassified' }
GrafoscopioPillarASTextStringAdapter >> isString [
^ true
]
{ #category : #'as yet unclassified' }
GrafoscopioPillarASTextStringAdapter >> isWideString [
^ true
]
{ #category : #'as yet unclassified' }
GrafoscopioPillarASTextStringAdapter >> lastIndexOf: anElement startingAt: lastIndex ifAbsent: exceptionBlock [
"Answer the index of the last occurence of anElement within the
receiver. If the receiver does not contain anElement, answer the
result of evaluating the argument, exceptionBlock."
lastIndex to: 1 by: -1 do: [ :index |
(self at: index) = anElement
ifTrue: [ ^ index ] ].
^ exceptionBlock value
]
{ #category : #accessing }
GrafoscopioPillarASTextStringAdapter >> notEmpty [
^ text notEmpty
]
{ #category : #'as yet unclassified' }
GrafoscopioPillarASTextStringAdapter >> printOn: aStream [
aStream
nextPutAll: 'StringAdaptor(';
nextPutAll: self size asString;
nextPutAll: ')'
]
{ #category : #'as yet unclassified' }
GrafoscopioPillarASTextStringAdapter >> printString [
^ String streamContents: [ :str | self printOn: str ]
]
{ #category : #'as yet unclassified' }
GrafoscopioPillarASTextStringAdapter >> readStream [
^ ReadStream on: self
]
{ #category : #accessing }
GrafoscopioPillarASTextStringAdapter >> size [
^ text size
]
{ #category : #'as yet unclassified' }
GrafoscopioPillarASTextStringAdapter >> string [
^ text extractStringFrom: 1 to: self size
]
{ #category : #accessing }
GrafoscopioPillarASTextStringAdapter >> text: aGFPText [
text := aGFPText
]
{ #category : #'as yet unclassified' }
GrafoscopioPillarASTextStringAdapter >> trimBoth [
^ self
]
{ #category : #'as yet unclassified' }
GrafoscopioPillarASTextStringAdapter >> yourself [
^ self
]
{ #category : #'as yet unclassified' }
GrafoscopioPillarASTextStringAdapter >> ~= anOther [
^ (self == anOther) not
]