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

Unified 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, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/lib/lib.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index 1962e0ba7390ac1457d89ac36d1e409a15e34bc1..6158a02500f739b5527248a257a37994bdacf38a 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -7433,38 +7433,36 @@ RawString* Script::GetSnippet(intptr_t from_line,
intptr_t length = src.Length();
intptr_t line = 1 + line_offset();
intptr_t column = 1;
- intptr_t lookahead = 0;
+ intptr_t scan_position = 0;
intptr_t snippet_start = -1;
intptr_t snippet_end = -1;
if (from_line - line_offset() == 1) {
column += col_offset();
}
- char c = src.CharAt(lookahead);
- while (lookahead != length) {
- if (snippet_start == -1) {
- if ((line == from_line) && (column == from_column)) {
- snippet_start = lookahead;
- }
- } else if ((line == to_line) && (column == to_column)) {
- snippet_end = lookahead;
- break;
- }
+
+ while (scan_position != length) {
+ char c = src.CharAt(scan_position);
if (c == '\n') {
line++;
column = 0;
+ } else if (c == '\r') {
+ line++;
+ column = 0;
+ if ((scan_position + 1 != length) &&
+ (src.CharAt(scan_position + 1) == '\n')) {
+ scan_position++;
+ }
}
+ scan_position++;
column++;
- lookahead++;
- if (lookahead != length) {
- // Replace '\r' with '\n' and a sequence of '\r' '\n' with a single '\n'.
- if (src.CharAt(lookahead) == '\r') {
- c = '\n';
- if (lookahead + 1 != length && src.CharAt(lookahead) == '\n') {
- lookahead++;
- }
- } else {
- c = src.CharAt(lookahead);
+
+ if (snippet_start == -1) {
+ if ((line == from_line) && (column == from_column)) {
+ snippet_start = scan_position;
}
+ } else if ((line == to_line) && (column == to_column)) {
+ snippet_end = scan_position;
+ break;
}
}
String& snippet = String::Handle();
« 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