Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(363)

Side by Side Diff: pkg/analyzer/lib/src/services/writer.dart

Issue 322563002: Formatter: fix for long multiline strings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixes for review comments. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/analyzer/test/services/formatter_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 buffer.write(currentLine.toString()); 343 buffer.write(currentLine.toString());
344 currentLine = newLine(); 344 currentLine = newLine();
345 } 345 }
346 346
347 void newlines(int num) { 347 void newlines(int num) {
348 while (num-- > 0) { 348 while (num-- > 0) {
349 newline(); 349 newline();
350 } 350 }
351 } 351 }
352 352
353 void write(x) { 353 void write(String string) {
354 _addToken(new LineToken(x)); 354 var lines = string.split(lineSeparator);
355 var length = lines.length;
356 for (int i = 0; i < length; i++) {
357 var line = lines[i];
358 _addToken(new LineToken(line));
359 if (i != length - 1) {
360 newline();
361 // no indentation for multi-line strings
362 currentLine.clear();
363 }
364 }
355 } 365 }
356 366
357 void writeln(String s) { 367 void writeln(String s) {
358 write(s); 368 write(s);
359 newline(); 369 newline();
360 } 370 }
361 371
362 void space() { 372 void space() {
363 spaces(1); 373 spaces(1);
364 } 374 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 446
437 String getTabs(int n) => n < TABS.length ? TABS[n] : repeat('\t', n); 447 String getTabs(int n) => n < TABS.length ? TABS[n] : repeat('\t', n);
438 448
439 String repeat(String ch, int times) { 449 String repeat(String ch, int times) {
440 var sb = new StringBuffer(); 450 var sb = new StringBuffer();
441 for (var i = 0; i < times; ++i) { 451 for (var i = 0; i < times; ++i) {
442 sb.write(ch); 452 sb.write(ch);
443 } 453 }
444 return sb.toString(); 454 return sb.toString();
445 } 455 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/services/formatter_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698