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

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

Issue 3750001: base: Move SplitString functions into the base namespace and update the callers. (Closed) Base URL: git://git.chromium.org/chromium.git
Patch Set: brett review, reverted changes in o3d due to it's using an old base revision Created 10 years, 2 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 | « net/ftp/ftp_directory_listing_parser_vms_unittest.cc ('k') | net/http/http_network_layer.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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_directory_listing_parser_windows.h" 5 #include "net/ftp/ftp_directory_listing_parser_windows.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/string_split.h" 10 #include "base/string_split.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "net/ftp/ftp_util.h" 12 #include "net/ftp/ftp_util.h"
13 13
14 namespace { 14 namespace {
15 15
16 bool WindowsDateListingToTime(const std::vector<string16>& columns, 16 bool WindowsDateListingToTime(const std::vector<string16>& columns,
17 base::Time* time) { 17 base::Time* time) {
18 DCHECK_LE(4U, columns.size()); 18 DCHECK_LE(4U, columns.size());
19 19
20 base::Time::Exploded time_exploded = { 0 }; 20 base::Time::Exploded time_exploded = { 0 };
21 21
22 // Date should be in format MM-DD-YY[YY]. 22 // Date should be in format MM-DD-YY[YY].
23 std::vector<string16> date_parts; 23 std::vector<string16> date_parts;
24 SplitString(columns[0], '-', &date_parts); 24 base::SplitString(columns[0], '-', &date_parts);
25 if (date_parts.size() != 3) 25 if (date_parts.size() != 3)
26 return false; 26 return false;
27 if (!base::StringToInt(date_parts[0], &time_exploded.month)) 27 if (!base::StringToInt(date_parts[0], &time_exploded.month))
28 return false; 28 return false;
29 if (!base::StringToInt(date_parts[1], &time_exploded.day_of_month)) 29 if (!base::StringToInt(date_parts[1], &time_exploded.day_of_month))
30 return false; 30 return false;
31 if (!base::StringToInt(date_parts[2], &time_exploded.year)) 31 if (!base::StringToInt(date_parts[2], &time_exploded.year))
32 return false; 32 return false;
33 if (time_exploded.year < 0) 33 if (time_exploded.year < 0)
34 return false; 34 return false;
35 // If year has only two digits then assume that 00-79 is 2000-2079, 35 // If year has only two digits then assume that 00-79 is 2000-2079,
36 // and 80-99 is 1980-1999. 36 // and 80-99 is 1980-1999.
37 if (time_exploded.year < 80) 37 if (time_exploded.year < 80)
38 time_exploded.year += 2000; 38 time_exploded.year += 2000;
39 else if (time_exploded.year < 100) 39 else if (time_exploded.year < 100)
40 time_exploded.year += 1900; 40 time_exploded.year += 1900;
41 41
42 // Time should be in format HH:MM(AM|PM) 42 // Time should be in format HH:MM(AM|PM)
43 if (columns[1].length() != 7) 43 if (columns[1].length() != 7)
44 return false; 44 return false;
45 std::vector<string16> time_parts; 45 std::vector<string16> time_parts;
46 SplitString(columns[1].substr(0, 5), ':', &time_parts); 46 base::SplitString(columns[1].substr(0, 5), ':', &time_parts);
47 if (time_parts.size() != 2) 47 if (time_parts.size() != 2)
48 return false; 48 return false;
49 if (!base::StringToInt(time_parts[0], &time_exploded.hour)) 49 if (!base::StringToInt(time_parts[0], &time_exploded.hour))
50 return false; 50 return false;
51 if (!base::StringToInt(time_parts[1], &time_exploded.minute)) 51 if (!base::StringToInt(time_parts[1], &time_exploded.minute))
52 return false; 52 return false;
53 if (!time_exploded.HasValidValues()) 53 if (!time_exploded.HasValidValues())
54 return false; 54 return false;
55 string16 am_or_pm(columns[1].substr(5, 2)); 55 string16 am_or_pm(columns[1].substr(5, 2));
56 if (EqualsASCII(am_or_pm, "PM")) { 56 if (EqualsASCII(am_or_pm, "PM")) {
(...skipping 13 matching lines...) Expand all
70 70
71 } // namespace 71 } // namespace
72 72
73 namespace net { 73 namespace net {
74 74
75 FtpDirectoryListingParserWindows::FtpDirectoryListingParserWindows() { 75 FtpDirectoryListingParserWindows::FtpDirectoryListingParserWindows() {
76 } 76 }
77 77
78 bool FtpDirectoryListingParserWindows::ConsumeLine(const string16& line) { 78 bool FtpDirectoryListingParserWindows::ConsumeLine(const string16& line) {
79 std::vector<string16> columns; 79 std::vector<string16> columns;
80 SplitString(CollapseWhitespace(line, false), ' ', &columns); 80 base::SplitString(CollapseWhitespace(line, false), ' ', &columns);
81 81
82 // We may receive file names containing spaces, which can make the number of 82 // We may receive file names containing spaces, which can make the number of
83 // columns arbitrarily large. We will handle that later. For now just make 83 // columns arbitrarily large. We will handle that later. For now just make
84 // sure we have all the columns that should normally be there. 84 // sure we have all the columns that should normally be there.
85 if (columns.size() < 4) 85 if (columns.size() < 4)
86 return false; 86 return false;
87 87
88 FtpDirectoryListingEntry entry; 88 FtpDirectoryListingEntry entry;
89 entry.name = FtpUtil::GetStringPartAfterColumns(line, 3); 89 entry.name = FtpUtil::GetStringPartAfterColumns(line, 3);
90 90
(...skipping 23 matching lines...) Expand all
114 return !entries_.empty(); 114 return !entries_.empty();
115 } 115 }
116 116
117 FtpDirectoryListingEntry FtpDirectoryListingParserWindows::PopEntry() { 117 FtpDirectoryListingEntry FtpDirectoryListingParserWindows::PopEntry() {
118 FtpDirectoryListingEntry entry = entries_.front(); 118 FtpDirectoryListingEntry entry = entries_.front();
119 entries_.pop(); 119 entries_.pop();
120 return entry; 120 return entry;
121 } 121 }
122 122
123 } // namespace net 123 } // namespace net
OLDNEW
« no previous file with comments | « net/ftp/ftp_directory_listing_parser_vms_unittest.cc ('k') | net/http/http_network_layer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698