Chromium Code Reviews| 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({int initialIndent: 0, this.lineSeparator: '\n'}) : |
|
Brian Wilkerson
2013/07/08 21:49:11
Just out of curiosity, why not
SourceWriter({th
pquitslund
2013/07/08 21:56:38
I like that better. Thanks!
| |
| 87 indentCount = initialIndent; | 87 indentCount = initialIndent { |
| 88 currentLine = new Line(indent: indentCount); | |
| 89 } | |
| 88 | 90 |
| 89 indent() { | 91 indent() { |
| 90 ++indentCount; | 92 ++indentCount; |
| 91 } | 93 } |
| 92 | 94 |
| 93 unindent() { | 95 unindent() { |
| 94 --indentCount; | 96 --indentCount; |
| 95 } | 97 } |
| 96 | 98 |
| 97 print(x) { | 99 print(x) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 | 173 |
| 172 String getTabs(int n) => n < TABS.length ? TABS[n] : repeat('\t', n); | 174 String getTabs(int n) => n < TABS.length ? TABS[n] : repeat('\t', n); |
| 173 | 175 |
| 174 String repeat(String ch, int times) { | 176 String repeat(String ch, int times) { |
| 175 var sb = new StringBuffer(); | 177 var sb = new StringBuffer(); |
| 176 for (var i = 0; i < times; ++i) { | 178 for (var i = 0; i < times; ++i) { |
| 177 sb.write(ch); | 179 sb.write(ch); |
| 178 } | 180 } |
| 179 return sb.toString(); | 181 return sb.toString(); |
| 180 } | 182 } |
| OLD | NEW |