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

Side by Side Diff: net/ftp/ftp_directory_listing_buffer.cc

Issue 465035: Split FTP LIST parsing code into individual files for each listing style. (Closed)
Patch Set: fix Created 11 years 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
« no previous file with comments | « no previous file | net/ftp/ftp_directory_listing_buffer_unittest.cc » ('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) 2009 The Chromium Authors. All rights reserved. Use of this 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the 2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file. 3 // LICENSE file.
4 4
5 #include "net/ftp/ftp_directory_listing_buffer.h" 5 #include "net/ftp/ftp_directory_listing_buffer.h"
6 6
7 #include "base/i18n/icu_string_conversions.h" 7 #include "base/i18n/icu_string_conversions.h"
8 #include "base/stl_util-inl.h" 8 #include "base/stl_util-inl.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
11 #include "net/ftp/ftp_directory_listing_parsers.h" 11 #include "net/ftp/ftp_directory_listing_parser_ls.h"
12 #include "net/ftp/ftp_directory_listing_parser_vms.h"
13 #include "net/ftp/ftp_directory_listing_parser_windows.h"
12 #include "unicode/ucsdet.h" 14 #include "unicode/ucsdet.h"
13 15
14 namespace { 16 namespace {
15 17
16 // A very simple-minded character encoding detection. 18 // A very simple-minded character encoding detection.
17 // TODO(jungshik): We can apply more heuristics here (e.g. using various hints 19 // TODO(jungshik): We can apply more heuristics here (e.g. using various hints
18 // like TLD, the UI language/default encoding of a client, etc). In that case, 20 // like TLD, the UI language/default encoding of a client, etc). In that case,
19 // this should be pulled out of here and moved somewhere in base because there 21 // this should be pulled out of here and moved somewhere in base because there
20 // can be other use cases. 22 // can be other use cases.
21 std::string DetectEncoding(const std::string& text) { 23 std::string DetectEncoding(const std::string& text) {
(...skipping 12 matching lines...) Expand all
34 return std::string(); 36 return std::string();
35 return encoding; 37 return encoding;
36 } 38 }
37 39
38 } // namespace 40 } // namespace
39 41
40 namespace net { 42 namespace net {
41 43
42 FtpDirectoryListingBuffer::FtpDirectoryListingBuffer() 44 FtpDirectoryListingBuffer::FtpDirectoryListingBuffer()
43 : current_parser_(NULL) { 45 : current_parser_(NULL) {
44 parsers_.insert(new FtpLsDirectoryListingParser()); 46 parsers_.insert(new FtpDirectoryListingParserLs());
45 parsers_.insert(new FtpWindowsDirectoryListingParser()); 47 parsers_.insert(new FtpDirectoryListingParserVms());
46 parsers_.insert(new FtpVmsDirectoryListingParser()); 48 parsers_.insert(new FtpDirectoryListingParserWindows());
47 } 49 }
48 50
49 FtpDirectoryListingBuffer::~FtpDirectoryListingBuffer() { 51 FtpDirectoryListingBuffer::~FtpDirectoryListingBuffer() {
50 STLDeleteElements(&parsers_); 52 STLDeleteElements(&parsers_);
51 } 53 }
52 54
53 int FtpDirectoryListingBuffer::ConsumeData(const char* data, int data_length) { 55 int FtpDirectoryListingBuffer::ConsumeData(const char* data, int data_length) {
54 buffer_.append(data, data_length); 56 buffer_.append(data, data_length);
55 57
56 if (!encoding_.empty() || buffer_.length() > 1024) { 58 if (!encoding_.empty() || buffer_.length() > 1024) {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 if (parsers_.size() != 1) { 171 if (parsers_.size() != 1) {
170 current_parser_ = NULL; 172 current_parser_ = NULL;
171 return ERR_UNRECOGNIZED_FTP_DIRECTORY_LISTING_FORMAT; 173 return ERR_UNRECOGNIZED_FTP_DIRECTORY_LISTING_FORMAT;
172 } 174 }
173 175
174 current_parser_ = *parsers_.begin(); 176 current_parser_ = *parsers_.begin();
175 return OK; 177 return OK;
176 } 178 }
177 179
178 } // namespace net 180 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/ftp/ftp_directory_listing_buffer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698