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

Side by Side Diff: runtime/vm/object.cc

Issue 132773006: Fix handling of CRLF line endings in Script::GetSnippet. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: appease analyzer Created 6 years, 10 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 | tests/lib/lib.status » ('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) 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 #include "vm/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/cpu.h" 10 #include "vm/cpu.h"
(...skipping 7415 matching lines...) Expand 10 before | Expand all | Expand 10 after
7426 7426
7427 7427
7428 RawString* Script::GetSnippet(intptr_t from_line, 7428 RawString* Script::GetSnippet(intptr_t from_line,
7429 intptr_t from_column, 7429 intptr_t from_column,
7430 intptr_t to_line, 7430 intptr_t to_line,
7431 intptr_t to_column) const { 7431 intptr_t to_column) const {
7432 const String& src = String::Handle(Source()); 7432 const String& src = String::Handle(Source());
7433 intptr_t length = src.Length(); 7433 intptr_t length = src.Length();
7434 intptr_t line = 1 + line_offset(); 7434 intptr_t line = 1 + line_offset();
7435 intptr_t column = 1; 7435 intptr_t column = 1;
7436 intptr_t lookahead = 0; 7436 intptr_t scan_position = 0;
7437 intptr_t snippet_start = -1; 7437 intptr_t snippet_start = -1;
7438 intptr_t snippet_end = -1; 7438 intptr_t snippet_end = -1;
7439 if (from_line - line_offset() == 1) { 7439 if (from_line - line_offset() == 1) {
7440 column += col_offset(); 7440 column += col_offset();
7441 } 7441 }
7442 char c = src.CharAt(lookahead); 7442
7443 while (lookahead != length) { 7443 while (scan_position != length) {
7444 if (snippet_start == -1) { 7444 char c = src.CharAt(scan_position);
7445 if ((line == from_line) && (column == from_column)) {
7446 snippet_start = lookahead;
7447 }
7448 } else if ((line == to_line) && (column == to_column)) {
7449 snippet_end = lookahead;
7450 break;
7451 }
7452 if (c == '\n') { 7445 if (c == '\n') {
7453 line++; 7446 line++;
7454 column = 0; 7447 column = 0;
7448 } else if (c == '\r') {
7449 line++;
7450 column = 0;
7451 if ((scan_position + 1 != length) &&
7452 (src.CharAt(scan_position + 1) == '\n')) {
7453 scan_position++;
7454 }
7455 } 7455 }
7456 scan_position++;
7456 column++; 7457 column++;
7457 lookahead++; 7458
7458 if (lookahead != length) { 7459 if (snippet_start == -1) {
7459 // Replace '\r' with '\n' and a sequence of '\r' '\n' with a single '\n'. 7460 if ((line == from_line) && (column == from_column)) {
7460 if (src.CharAt(lookahead) == '\r') { 7461 snippet_start = scan_position;
7461 c = '\n';
7462 if (lookahead + 1 != length && src.CharAt(lookahead) == '\n') {
7463 lookahead++;
7464 }
7465 } else {
7466 c = src.CharAt(lookahead);
7467 } 7462 }
7463 } else if ((line == to_line) && (column == to_column)) {
7464 snippet_end = scan_position;
7465 break;
7468 } 7466 }
7469 } 7467 }
7470 String& snippet = String::Handle(); 7468 String& snippet = String::Handle();
7471 if ((snippet_start != -1) && (snippet_end != -1)) { 7469 if ((snippet_start != -1) && (snippet_end != -1)) {
7472 snippet = 7470 snippet =
7473 String::SubString(src, snippet_start, snippet_end - snippet_start); 7471 String::SubString(src, snippet_start, snippet_end - snippet_start);
7474 } 7472 }
7475 return snippet.raw(); 7473 return snippet.raw();
7476 } 7474 }
7477 7475
(...skipping 9744 matching lines...) Expand 10 before | Expand all | Expand 10 after
17222 return "_MirrorReference"; 17220 return "_MirrorReference";
17223 } 17221 }
17224 17222
17225 17223
17226 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 17224 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
17227 Instance::PrintToJSONStream(stream, ref); 17225 Instance::PrintToJSONStream(stream, ref);
17228 } 17226 }
17229 17227
17230 17228
17231 } // namespace dart 17229 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | tests/lib/lib.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698