| 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 class Line { | 8 class Line { |
| 9 | 9 |
| 10 final int lineLength; | 10 final int lineLength; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 class NewlineToken extends LineToken { | 71 class NewlineToken extends LineToken { |
| 72 | 72 |
| 73 NewlineToken(String value) : super(value); | 73 NewlineToken(String value) : super(value); |
| 74 } | 74 } |
| 75 | 75 |
| 76 | 76 |
| 77 | 77 |
| 78 class SourceWriter { | 78 class SourceWriter { |
| 79 | 79 |
| 80 final StringBuffer buffer = new StringBuffer(); | 80 final StringBuffer buffer = new StringBuffer(); |
| 81 Line currentLine = new Line(); | 81 Line currentLine; |
| 82 | 82 |
| 83 final String lineSeparator; | 83 final String lineSeparator; |
| 84 int indentCount = 0; | 84 int indentCount = 0; |
| 85 | 85 |
| 86 SourceWriter({int initialIndent: 0, this.lineSeparator: '\n'}) : | 86 SourceWriter({this.indentCount: 0, this.lineSeparator: '\n'}) { |
| 87 indentCount = initialIndent; | 87 currentLine = new Line(indent: indentCount); |
| 88 } |
| 88 | 89 |
| 89 indent() { | 90 indent() { |
| 90 ++indentCount; | 91 ++indentCount; |
| 91 } | 92 } |
| 92 | 93 |
| 93 unindent() { | 94 unindent() { |
| 94 --indentCount; | 95 --indentCount; |
| 95 } | 96 } |
| 96 | 97 |
| 97 print(x) { | 98 print(x) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 | 172 |
| 172 String getTabs(int n) => n < TABS.length ? TABS[n] : repeat('\t', n); | 173 String getTabs(int n) => n < TABS.length ? TABS[n] : repeat('\t', n); |
| 173 | 174 |
| 174 String repeat(String ch, int times) { | 175 String repeat(String ch, int times) { |
| 175 var sb = new StringBuffer(); | 176 var sb = new StringBuffer(); |
| 176 for (var i = 0; i < times; ++i) { | 177 for (var i = 0; i < times; ++i) { |
| 177 sb.write(ch); | 178 sb.write(ch); |
| 178 } | 179 } |
| 179 return sb.toString(); | 180 return sb.toString(); |
| 180 } | 181 } |
| OLD | NEW |