| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library source_writer; | 5 library source_writer; |
| 6 | 6 |
| 7 | 7 |
| 8 | 8 |
| 9 class Line { | 9 class Line { |
| 10 | 10 |
| 11 final List<LineToken> tokens = <LineToken>[]; | 11 final List<LineToken> tokens = <LineToken>[]; |
| 12 final bool useTabs; | 12 final bool useTabs; |
| 13 final int spacesPerIndent; | 13 final int spacesPerIndent; |
| 14 final int indentLevel; | 14 final int indentLevel; |
| 15 final LinePrinter printer; | 15 final LinePrinter printer; |
| 16 | 16 |
| 17 Line({this.indentLevel: 0, this.useTabs: false, this.spacesPerIndent: 2, | 17 Line({this.indentLevel: 0, this.useTabs: false, this.spacesPerIndent: 2, |
| 18 this.printer: const SimpleLinePrinter()}) { | 18 this.printer: const SimpleLinePrinter()}) { |
| 19 if (indentLevel > 0) { | 19 if (indentLevel > 0) { |
| 20 indent(indentLevel); | 20 indent(indentLevel); |
| 21 } | 21 } |
| 22 } | 22 } |
| 23 | 23 |
| 24 void addSpace() { | 24 void addSpace() { |
| 25 addSpaces(1); | 25 addSpaces(1); |
| 26 } | 26 } |
| 27 | 27 |
| 28 void addSpaces(int n, {breakWeight: DEFAULT_SPACE_WEIGHT}) { | 28 void addSpaces(int n, {breakWeight: DEFAULT_SPACE_WEIGHT}) { |
| 29 if (n > 0) { | 29 tokens.add(new SpaceToken(n, breakWeight: breakWeight)); |
| 30 tokens.add(new SpaceToken(n, breakWeight: breakWeight)); | |
| 31 } | |
| 32 } | 30 } |
| 33 | 31 |
| 34 void addToken(LineToken token) { | 32 void addToken(LineToken token) { |
| 35 tokens.add(token); | 33 tokens.add(token); |
| 36 } | 34 } |
| 37 | 35 |
| 38 bool isEmpty() => tokens.isEmpty; | 36 bool isEmpty() => tokens.isEmpty; |
| 39 | 37 |
| 40 bool isWhitespace() => tokens.every((tok) => tok is SpaceToken); | 38 bool isWhitespace() => tokens.every((tok) => tok is SpaceToken); |
| 41 | 39 |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 | 428 |
| 431 String getTabs(int n) => n < TABS.length ? TABS[n] : repeat('\t', n); | 429 String getTabs(int n) => n < TABS.length ? TABS[n] : repeat('\t', n); |
| 432 | 430 |
| 433 String repeat(String ch, int times) { | 431 String repeat(String ch, int times) { |
| 434 var sb = new StringBuffer(); | 432 var sb = new StringBuffer(); |
| 435 for (var i = 0; i < times; ++i) { | 433 for (var i = 0; i < times; ++i) { |
| 436 sb.write(ch); | 434 sb.write(ch); |
| 437 } | 435 } |
| 438 return sb.toString(); | 436 return sb.toString(); |
| 439 } | 437 } |
| OLD | NEW |