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

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

Issue 1875203002: Refactor FtpCtrlResponseBuffer::ParseLine to use net::ParseInt32() rather than base::StringToInt(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « no previous file | no next file » | 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) 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 <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "net/base/parse_number.h"
12 #include "base/strings/string_piece.h" 12 #include "base/strings/string_piece.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
15 15
16 namespace net { 16 namespace net {
17 17
18 // static 18 // static
19 const int FtpCtrlResponse::kInvalidStatusCode = -1; 19 const int FtpCtrlResponse::kInvalidStatusCode = -1;
20 20
21 FtpCtrlResponse::FtpCtrlResponse() : status_code(kInvalidStatusCode) {} 21 FtpCtrlResponse::FtpCtrlResponse() : status_code(kInvalidStatusCode) {}
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 116
117 FtpCtrlResponseBuffer::ParsedLine::ParsedLine(const ParsedLine& other) = 117 FtpCtrlResponseBuffer::ParsedLine::ParsedLine(const ParsedLine& other) =
118 default; 118 default;
119 119
120 // static 120 // static
121 FtpCtrlResponseBuffer::ParsedLine FtpCtrlResponseBuffer::ParseLine( 121 FtpCtrlResponseBuffer::ParsedLine FtpCtrlResponseBuffer::ParseLine(
122 const std::string& line) { 122 const std::string& line) {
123 ParsedLine result; 123 ParsedLine result;
124 124
125 if (line.length() >= 3) { 125 if (line.length() >= 3) {
126 if (base::StringToInt(base::StringPiece(line.begin(), line.begin() + 3), 126 if (ParseInt32(base::StringPiece(line.begin(), line.begin() + 3),
127 &result.status_code)) 127 ParseIntFormat::NON_NEGATIVE, &result.status_code)) {
128 result.has_status_code = (100 <= result.status_code && 128 result.has_status_code =
129 result.status_code <= 599); 129 (100 <= result.status_code && result.status_code <= 599);
130 }
130 if (result.has_status_code && line.length() >= 4 && line[3] == ' ') { 131 if (result.has_status_code && line.length() >= 4 && line[3] == ' ') {
131 result.is_complete = true; 132 result.is_complete = true;
132 } else if (result.has_status_code && line.length() >= 4 && line[3] == '-') { 133 } else if (result.has_status_code && line.length() >= 4 && line[3] == '-') {
133 result.is_complete = true; 134 result.is_complete = true;
134 result.is_multiline = true; 135 result.is_multiline = true;
135 } 136 }
136 } 137 }
137 138
138 if (result.is_complete) { 139 if (result.is_complete) {
139 result.status_text = line.substr(4); 140 result.status_text = line.substr(4);
(...skipping 11 matching lines...) Expand all
151 for (size_t i = 0; i < buffer_.length(); i++) { 152 for (size_t i = 0; i < buffer_.length(); i++) {
152 if (i >= 1 && buffer_[i - 1] == '\r' && buffer_[i] == '\n') { 153 if (i >= 1 && buffer_[i - 1] == '\r' && buffer_[i] == '\n') {
153 lines_.push(ParseLine(buffer_.substr(cut_pos, i - cut_pos - 1))); 154 lines_.push(ParseLine(buffer_.substr(cut_pos, i - cut_pos - 1)));
154 cut_pos = i + 1; 155 cut_pos = i + 1;
155 } 156 }
156 } 157 }
157 buffer_.erase(0, cut_pos); 158 buffer_.erase(0, cut_pos);
158 } 159 }
159 160
160 } // namespace net 161 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698