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

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

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/ftp/ftp_ctrl_response_buffer.h" 5 #include "net/ftp/ftp_ctrl_response_buffer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_piece.h" 10 #include "base/strings/string_piece.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
13 13
14 namespace net { 14 namespace net {
15 15
16 // static 16 // static
17 const int FtpCtrlResponse::kInvalidStatusCode = -1; 17 const int FtpCtrlResponse::kInvalidStatusCode = -1;
18 18
19 FtpCtrlResponse::FtpCtrlResponse() : status_code(kInvalidStatusCode) {} 19 FtpCtrlResponse::FtpCtrlResponse() : status_code(kInvalidStatusCode) {
20 }
20 21
21 FtpCtrlResponse::~FtpCtrlResponse() {} 22 FtpCtrlResponse::~FtpCtrlResponse() {
23 }
22 24
23 FtpCtrlResponseBuffer::FtpCtrlResponseBuffer(const BoundNetLog& net_log) 25 FtpCtrlResponseBuffer::FtpCtrlResponseBuffer(const BoundNetLog& net_log)
24 : multiline_(false), 26 : multiline_(false), net_log_(net_log) {
25 net_log_(net_log) {
26 } 27 }
27 28
28 FtpCtrlResponseBuffer::~FtpCtrlResponseBuffer() {} 29 FtpCtrlResponseBuffer::~FtpCtrlResponseBuffer() {
30 }
29 31
30 int FtpCtrlResponseBuffer::ConsumeData(const char* data, int data_length) { 32 int FtpCtrlResponseBuffer::ConsumeData(const char* data, int data_length) {
31 buffer_.append(data, data_length); 33 buffer_.append(data, data_length);
32 ExtractFullLinesFromBuffer(); 34 ExtractFullLinesFromBuffer();
33 35
34 while (!lines_.empty()) { 36 while (!lines_.empty()) {
35 ParsedLine line = lines_.front(); 37 ParsedLine line = lines_.front();
36 lines_.pop(); 38 lines_.pop();
37 39
38 if (multiline_) { 40 if (multiline_) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 } 112 }
111 113
112 // static 114 // static
113 FtpCtrlResponseBuffer::ParsedLine FtpCtrlResponseBuffer::ParseLine( 115 FtpCtrlResponseBuffer::ParsedLine FtpCtrlResponseBuffer::ParseLine(
114 const std::string& line) { 116 const std::string& line) {
115 ParsedLine result; 117 ParsedLine result;
116 118
117 if (line.length() >= 3) { 119 if (line.length() >= 3) {
118 if (base::StringToInt(base::StringPiece(line.begin(), line.begin() + 3), 120 if (base::StringToInt(base::StringPiece(line.begin(), line.begin() + 3),
119 &result.status_code)) 121 &result.status_code))
120 result.has_status_code = (100 <= result.status_code && 122 result.has_status_code =
121 result.status_code <= 599); 123 (100 <= result.status_code && result.status_code <= 599);
122 if (result.has_status_code && line.length() >= 4 && line[3] == ' ') { 124 if (result.has_status_code && line.length() >= 4 && line[3] == ' ') {
123 result.is_complete = true; 125 result.is_complete = true;
124 } else if (result.has_status_code && line.length() >= 4 && line[3] == '-') { 126 } else if (result.has_status_code && line.length() >= 4 && line[3] == '-') {
125 result.is_complete = true; 127 result.is_complete = true;
126 result.is_multiline = true; 128 result.is_multiline = true;
127 } 129 }
128 } 130 }
129 131
130 if (result.is_complete) { 132 if (result.is_complete) {
131 result.status_text = line.substr(4); 133 result.status_text = line.substr(4);
(...skipping 11 matching lines...) Expand all
143 for (size_t i = 0; i < buffer_.length(); i++) { 145 for (size_t i = 0; i < buffer_.length(); i++) {
144 if (i >= 1 && buffer_[i - 1] == '\r' && buffer_[i] == '\n') { 146 if (i >= 1 && buffer_[i - 1] == '\r' && buffer_[i] == '\n') {
145 lines_.push(ParseLine(buffer_.substr(cut_pos, i - cut_pos - 1))); 147 lines_.push(ParseLine(buffer_.substr(cut_pos, i - cut_pos - 1)));
146 cut_pos = i + 1; 148 cut_pos = i + 1;
147 } 149 }
148 } 150 }
149 buffer_.erase(0, cut_pos); 151 buffer_.erase(0, cut_pos);
150 } 152 }
151 153
152 } // namespace net 154 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698