forked from SeasideSt/Grease
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGRStringPrinter.class.st
More file actions
102 lines (80 loc) · 1.85 KB
/
GRStringPrinter.class.st
File metadata and controls
102 lines (80 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
Class {
#name : #GRStringPrinter,
#superclass : #GRPrinter,
#instVars : [
'trim',
'length',
'pad',
'character'
],
#category : #'Grease-Core-Text'
}
{ #category : #accessing }
GRStringPrinter >> character: aCharacter [
"The character to pad the string with."
character := aCharacter
]
{ #category : #initialization }
GRStringPrinter >> initialize [
super initialize.
self character: $ ; length: nil.
self trimNone; padNone
]
{ #category : #accessing }
GRStringPrinter >> length: anInteger [
"The maximal size of the string, or the size to pad to."
length := anInteger
]
{ #category : #padding }
GRStringPrinter >> padCenter [
"Pad to the center."
pad := #pad:center:to:
]
{ #category : #padding }
GRStringPrinter >> padLeft [
"Pad to the left."
pad := #pad:left:to:
]
{ #category : #padding }
GRStringPrinter >> padNone [
"Do not pad the input."
pad := nil
]
{ #category : #padding }
GRStringPrinter >> padRight [
"Pad to the right."
pad := #pad:right:to:
]
{ #category : #printing }
GRStringPrinter >> print: anObject on: aStream [
| string |
string := anObject greaseString.
trim isNil
ifFalse: [ string := string perform: trim ].
length isNil ifFalse: [
length < string size
ifTrue: [ string := string copyFrom: 1 to: length ].
(pad isNil or: [ character isNil ])
ifFalse: [ string := self perform: pad with: string with: character with: length ] ].
aStream nextPutAll: string
]
{ #category : #trimming }
GRStringPrinter >> trimBoth [
"Trim to the left and to the right."
trim := #trimBoth
]
{ #category : #trimming }
GRStringPrinter >> trimLeft [
"Trim to the left and to the right."
trim := #trimLeft
]
{ #category : #trimming }
GRStringPrinter >> trimNone [
"Do not trim the input."
trim := nil
]
{ #category : #trimming }
GRStringPrinter >> trimRight [
"Trim to the left and to the right."
trim := #trimRight
]