@@ -31,7 +31,15 @@ type Selector struct {
31
31
}
32
32
33
33
func (selector Selector ) String () string {
34
- return fmt .Sprintf ("Selector: %s (%d, %d)" , selector .Value , selector .Line , selector .Column )
34
+ return selector .str (false )
35
+ }
36
+
37
+ func (selector Selector ) str (diff bool ) string {
38
+ if diff {
39
+ return fmt .Sprintf ("Selector: %s (%d, %d)" , selector .Value , selector .Line , selector .Column )
40
+ } else {
41
+ return selector .Value
42
+ }
35
43
}
36
44
37
45
// Rule represents a parsed CSS rule
@@ -147,7 +155,7 @@ func (rule *Rule) Diff(other *Rule) []string {
147
155
} else {
148
156
for i , sel := range rule .Selectors {
149
157
if sel != other .Selectors [i ] {
150
- result = append (result , fmt .Sprintf ("Selector: \" %s\" | \" %s\" " , sel , other .Selectors [i ]))
158
+ result = append (result , fmt .Sprintf ("Selector: \" %s\" | \" %s\" " , sel . str ( true ) , other .Selectors [i ]. str ( true ) ))
151
159
}
152
160
}
153
161
}
@@ -157,7 +165,7 @@ func (rule *Rule) Diff(other *Rule) []string {
157
165
} else {
158
166
for i , decl := range rule .Declarations {
159
167
if ! decl .Equal (other .Declarations [i ]) {
160
- result = append (result , fmt .Sprintf ("Declaration: \" %s\" | \" %s\" " , decl .String ( ), other .Declarations [i ].String ( )))
168
+ result = append (result , fmt .Sprintf ("Declaration: \" %s\" | \" %s\" " , decl .Str ( true ), other .Declarations [i ].Str ( true )))
161
169
}
162
170
}
163
171
}
@@ -168,7 +176,7 @@ func (rule *Rule) Diff(other *Rule) []string {
168
176
169
177
for i , rule := range rule .Rules {
170
178
if ! rule .Equal (other .Rules [i ]) {
171
- result = append (result , fmt .Sprintf ("Rule: \" %s\" | \" %s\" " , rule .String ( ), other .Rules [i ].String ( )))
179
+ result = append (result , fmt .Sprintf ("Rule: \" %s\" | \" %s\" " , rule .str ( true ), other .Rules [i ].str ( true )))
172
180
}
173
181
}
174
182
}
@@ -178,6 +186,11 @@ func (rule *Rule) Diff(other *Rule) []string {
178
186
179
187
// Returns the string representation of a rule
180
188
func (rule * Rule ) String () string {
189
+ return rule .str (false )
190
+ }
191
+
192
+ // Returns the string representation of a rule
193
+ func (rule * Rule ) str (diff bool ) string {
181
194
result := ""
182
195
183
196
if rule .Kind == QualifiedRule {
@@ -206,11 +219,11 @@ func (rule *Rule) String() string {
206
219
207
220
if rule .EmbedsRules () {
208
221
for _ , subRule := range rule .Rules {
209
- result += fmt .Sprintf ("%s%s\n " , rule .indent (), subRule .String ( ))
222
+ result += fmt .Sprintf ("%s%s\n " , rule .indent (), subRule .str ( diff ))
210
223
}
211
224
} else {
212
225
for _ , decl := range rule .Declarations {
213
- result += fmt .Sprintf ("%s%s\n " , rule .indent (), decl .String ( ))
226
+ result += fmt .Sprintf ("%s%s\n " , rule .indent (), decl .Str ( diff ))
214
227
}
215
228
}
216
229
@@ -222,24 +235,12 @@ func (rule *Rule) String() string {
222
235
223
236
// Returns identation spaces for declarations and rules
224
237
func (rule * Rule ) indent () string {
225
- result := ""
226
-
227
- for i := 0 ; i < ((rule .EmbedLevel + 1 ) * indentSpace ); i ++ {
228
- result += " "
229
- }
230
-
231
- return result
238
+ return strings .Repeat (" " , (rule .EmbedLevel + 1 )* indentSpace )
232
239
}
233
240
234
241
// Returns identation spaces for end of block character
235
242
func (rule * Rule ) indentEndBlock () string {
236
- result := ""
237
-
238
- for i := 0 ; i < (rule .EmbedLevel * indentSpace ); i ++ {
239
- result += " "
240
- }
241
-
242
- return result
243
+ return strings .Repeat (" " , rule .EmbedLevel * indentSpace )
243
244
}
244
245
245
246
func (rule * Rule ) Sel () []string {
0 commit comments