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

Unified Diff: src/d8.cc

Issue 7565005: Version 3.5.3 (Closed) Base URL: https://v8.googlecode.com/svn/trunk
Patch Set: Created 9 years, 5 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 | « src/code-stubs.h ('k') | src/hydrogen.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/d8.cc
diff --git a/src/d8.cc b/src/d8.cc
index ac203746523a8ee83015a4968b0ad3cda7e9a6f0..f4ace87eb34413cfc8412aa6e9d411824aad30be 100644
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -226,17 +226,24 @@ Handle<Value> Shell::ReadLine(const Arguments& args) {
static const int kBufferSize = 256;
char buffer[kBufferSize];
Handle<String> accumulator = String::New("");
- bool linebreak;
int length;
- do { // Repeat if the line ends with an escape '\'.
- // fgets got an error. Just give up.
+ while (true) {
+ // Continue reading if the line ends with an escape '\\' or the line has
+ // not been fully read into the buffer yet (does not end with '\n').
+ // If fgets gets an error, just give up.
if (fgets(buffer, kBufferSize, stdin) == NULL) return Null();
length = static_cast<int>(strlen(buffer));
- linebreak = (length > 1 && buffer[length-2] == '\\');
- if (linebreak) buffer[length-2] = '\n';
- accumulator = String::Concat(accumulator, String::New(buffer, length-1));
- } while (linebreak);
- return accumulator;
+ if (length == 0) {
+ return accumulator;
+ } else if (buffer[length-1] != '\n') {
+ accumulator = String::Concat(accumulator, String::New(buffer, length));
+ } else if (length > 1 && buffer[length-2] == '\\') {
+ buffer[length-2] = '\n';
+ accumulator = String::Concat(accumulator, String::New(buffer, length-1));
+ } else {
+ return String::Concat(accumulator, String::New(buffer, length-1));
+ }
+ }
}
« no previous file with comments | « src/code-stubs.h ('k') | src/hydrogen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698