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

Unified Diff: net/ftp/ftp_directory_listing_buffer.cc

Issue 348036: Implement VMS FTP directory listing parser. (Closed)
Patch Set: fix Created 11 years, 1 month 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 | « net/data/ftp/dir-listing-vms-4.expected ('k') | net/ftp/ftp_directory_listing_buffer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/ftp/ftp_directory_listing_buffer.cc
diff --git a/net/ftp/ftp_directory_listing_buffer.cc b/net/ftp/ftp_directory_listing_buffer.cc
index 0099e9100ee6743e10360d2936f9ad8e51d6739e..030da83d7cd4c145ce1c7f2fecf2166a60c86403 100644
--- a/net/ftp/ftp_directory_listing_buffer.cc
+++ b/net/ftp/ftp_directory_listing_buffer.cc
@@ -37,10 +37,11 @@ std::string DetectEncoding(const std::string& text) {
} // namespace
namespace net {
-
+
FtpDirectoryListingBuffer::FtpDirectoryListingBuffer()
: current_parser_(NULL) {
parsers_.insert(new FtpLsDirectoryListingParser());
+ parsers_.insert(new FtpVmsDirectoryListingParser());
}
FtpDirectoryListingBuffer::~FtpDirectoryListingBuffer() {
@@ -66,11 +67,11 @@ int FtpDirectoryListingBuffer::ProcessRemainingData() {
return ParseLines();
}
-
+
bool FtpDirectoryListingBuffer::EntryAvailable() const {
return (current_parser_ ? current_parser_->EntryAvailable() : false);
}
-
+
FtpDirectoryListingEntry FtpDirectoryListingBuffer::PopEntry() {
DCHECK(EntryAvailable());
return current_parser_->PopEntry();
@@ -86,19 +87,24 @@ bool FtpDirectoryListingBuffer::ConvertToDetectedEncoding(
int FtpDirectoryListingBuffer::ExtractFullLinesFromBuffer() {
if (encoding_.empty())
encoding_ = DetectEncoding(buffer_);
-
+
int cut_pos = 0;
+ // TODO(phajdan.jr): This code accepts all endlines matching \r*\n. Should it
+ // be more strict, or enforce consistent line endings?
for (size_t i = 0; i < buffer_.length(); ++i) {
- if (i >= 1 && buffer_[i - 1] == '\r' && buffer_[i] == '\n') {
- std::string line(buffer_.substr(cut_pos, i - cut_pos - 1));
- cut_pos = i + 1;
- string16 line_converted;
- if (!ConvertToDetectedEncoding(line, &line_converted)) {
- buffer_.erase(0, cut_pos);
- return ERR_ENCODING_CONVERSION_FAILED;
- }
- lines_.push_back(line_converted);
+ if (buffer_[i] != '\n')
+ continue;
+ int line_length = i - cut_pos;
+ if (i >= 1 && buffer_[i - 1] == '\r')
+ line_length--;
+ std::string line(buffer_.substr(cut_pos, line_length));
+ cut_pos = i + 1;
+ string16 line_converted;
+ if (!ConvertToDetectedEncoding(line, &line_converted)) {
+ buffer_.erase(0, cut_pos);
+ return ERR_ENCODING_CONVERSION_FAILED;
}
+ lines_.push_back(line_converted);
}
buffer_.erase(0, cut_pos);
return OK;
@@ -127,7 +133,7 @@ int FtpDirectoryListingBuffer::ParseLines() {
current_parser_ = *parsers_.begin();
}
}
-
+
return OK;
}
« no previous file with comments | « net/data/ftp/dir-listing-vms-4.expected ('k') | net/ftp/ftp_directory_listing_buffer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698