Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of dart2js; | 5 part of dart2js; |
| 6 | 6 |
| 7 class CodeBuffer implements StringBuffer { | 7 class CodeBuffer implements StringBuffer { |
| 8 | 8 |
| 9 StringBuffer buffer = new StringBuffer(); | 9 StringBuffer buffer = new StringBuffer(); |
| 10 List<CodeBufferMarker> markers = new List<CodeBufferMarker>(); | 10 List<CodeBufferMarker> markers = new List<CodeBufferMarker>(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 } else { | 45 } else { |
| 46 buffer.write(iterator.current); | 46 buffer.write(iterator.current); |
| 47 while (iterator.moveNext()) { | 47 while (iterator.moveNext()) { |
| 48 write(separator); | 48 write(separator); |
| 49 write(iterator.current); | 49 write(iterator.current); |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 return this; | 52 return this; |
| 53 } | 53 } |
| 54 | 54 |
| 55 CodeBuffer writeln([var object = ""]) { | |
|
Johnni Winther
2013/12/03 11:52:31
This implements a method from StringBuffer.
ahe
2013/12/04 11:45:43
Done.
| |
| 56 return write(object).write("\n"); | |
| 57 } | |
| 58 | |
| 59 CodeBuffer addBuffer(CodeBuffer other) { | 55 CodeBuffer addBuffer(CodeBuffer other) { |
| 60 if (other.markers.length > 0) { | 56 if (other.markers.length > 0) { |
| 61 CodeBufferMarker firstMarker = other.markers[0]; | 57 CodeBufferMarker firstMarker = other.markers[0]; |
| 62 int offsetDelta = | 58 int offsetDelta = |
| 63 buffer.length + firstMarker.offsetDelta - lastBufferOffset; | 59 buffer.length + firstMarker.offsetDelta - lastBufferOffset; |
| 64 markers.add(new CodeBufferMarker(offsetDelta, | 60 markers.add(new CodeBufferMarker(offsetDelta, |
| 65 firstMarker.sourcePosition)); | 61 firstMarker.sourcePosition)); |
| 66 for (int i = 1; i < other.markers.length; ++i) { | 62 for (int i = 1; i < other.markers.length; ++i) { |
| 67 markers.add(other.markers[i]); | 63 markers.add(other.markers[i]); |
| 68 } | 64 } |
| 69 lastBufferOffset = buffer.length + other.lastBufferOffset; | 65 lastBufferOffset = buffer.length + other.lastBufferOffset; |
| 70 } | 66 } |
| 71 buffer.write(other.getText()); | 67 buffer.write(other.getText()); |
| 72 return this; | 68 return this; |
| 73 } | 69 } |
| 74 | 70 |
| 75 CodeBuffer addAll(Iterable<Object> iterable) => writeAll(iterable); | 71 CodeBuffer addAll(Iterable<Object> iterable) => writeAll(iterable); |
| 76 | 72 |
| 77 CodeBuffer addCharCode(int charCode) => writeCharCode(charCode); | |
| 78 | |
| 79 CodeBuffer writeCharCode(int charCode) { | 73 CodeBuffer writeCharCode(int charCode) { |
| 80 buffer.writeCharCode(charCode); | 74 buffer.writeCharCode(charCode); |
| 81 return this; | 75 return this; |
| 82 } | 76 } |
| 83 | 77 |
| 84 CodeBuffer clear() { | 78 CodeBuffer clear() { |
| 85 buffer = new StringBuffer(); | 79 buffer = new StringBuffer(); |
| 86 markers.clear(); | 80 markers.clear(); |
| 87 lastBufferOffset = 0; | 81 lastBufferOffset = 0; |
| 88 return this; | 82 return this; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 119 }); | 113 }); |
| 120 } | 114 } |
| 121 } | 115 } |
| 122 | 116 |
| 123 class CodeBufferMarker { | 117 class CodeBufferMarker { |
| 124 final int offsetDelta; | 118 final int offsetDelta; |
| 125 final sourcePosition; | 119 final sourcePosition; |
| 126 | 120 |
| 127 CodeBufferMarker(this.offsetDelta, this.sourcePosition); | 121 CodeBufferMarker(this.offsetDelta, this.sourcePosition); |
| 128 } | 122 } |
| OLD | NEW |