| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_util.h" | 5 #include "net/ftp/ftp_util.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_tokenizer.h" | 10 #include "base/string_tokenizer.h" |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 if (text == ASCIIToUTF16("Dez")) { | 140 if (text == ASCIIToUTF16("Dez")) { |
| 141 *number = 12; | 141 *number = 12; |
| 142 return true; | 142 return true; |
| 143 } | 143 } |
| 144 | 144 |
| 145 return false; | 145 return false; |
| 146 } | 146 } |
| 147 | 147 |
| 148 // static | 148 // static |
| 149 bool FtpUtil::LsDateListingToTime(const string16& month, const string16& day, | 149 bool FtpUtil::LsDateListingToTime(const string16& month, const string16& day, |
| 150 const string16& rest, base::Time* time) { | 150 const string16& rest, |
| 151 const base::Time& current_time, |
| 152 base::Time* result) { |
| 151 base::Time::Exploded time_exploded = { 0 }; | 153 base::Time::Exploded time_exploded = { 0 }; |
| 152 | 154 |
| 153 if (!ThreeLetterMonthToNumber(month, &time_exploded.month)) | 155 if (!ThreeLetterMonthToNumber(month, &time_exploded.month)) |
| 154 return false; | 156 return false; |
| 155 | 157 |
| 156 if (!StringToInt(day, &time_exploded.day_of_month)) | 158 if (!StringToInt(day, &time_exploded.day_of_month)) |
| 157 return false; | 159 return false; |
| 158 | 160 |
| 159 if (!StringToInt(rest, &time_exploded.year)) { | 161 if (!StringToInt(rest, &time_exploded.year)) { |
| 160 // Maybe it's time. Does it look like time (MM:HH)? | 162 // Maybe it's time. Does it look like time (MM:HH)? |
| 161 if (rest.length() != 5 || rest[2] != ':') | 163 if (rest.length() != 5 || rest[2] != ':') |
| 162 return false; | 164 return false; |
| 163 | 165 |
| 164 if (!StringToInt(rest.substr(0, 2), &time_exploded.hour)) | 166 if (!StringToInt(rest.substr(0, 2), &time_exploded.hour)) |
| 165 return false; | 167 return false; |
| 166 | 168 |
| 167 if (!StringToInt(rest.substr(3, 2), &time_exploded.minute)) | 169 if (!StringToInt(rest.substr(3, 2), &time_exploded.minute)) |
| 168 return false; | 170 return false; |
| 169 | 171 |
| 170 // Use current year. | 172 // Guess the year. |
| 171 base::Time::Exploded now_exploded; | 173 base::Time::Exploded current_exploded; |
| 172 base::Time::Now().LocalExplode(&now_exploded); | 174 current_time.LocalExplode(¤t_exploded); |
| 173 time_exploded.year = now_exploded.year; | 175 |
| 176 // If it's not possible for the parsed date to be in the current year, |
| 177 // use the previous year. |
| 178 if (time_exploded.month > current_exploded.month || |
| 179 (time_exploded.month == current_exploded.month && |
| 180 time_exploded.day_of_month > current_exploded.day_of_month)) { |
| 181 time_exploded.year = current_exploded.year - 1; |
| 182 } else { |
| 183 time_exploded.year = current_exploded.year; |
| 184 } |
| 174 } | 185 } |
| 175 | 186 |
| 176 // We don't know the time zone of the listing, so just use local time. | 187 // We don't know the time zone of the listing, so just use local time. |
| 177 *time = base::Time::FromLocalExploded(time_exploded); | 188 *result = base::Time::FromLocalExploded(time_exploded); |
| 178 return true; | 189 return true; |
| 179 } | 190 } |
| 180 | 191 |
| 181 // static | 192 // static |
| 182 string16 FtpUtil::GetStringPartAfterColumns(const string16& text, int columns) { | 193 string16 FtpUtil::GetStringPartAfterColumns(const string16& text, int columns) { |
| 183 size_t pos = 0; | 194 size_t pos = 0; |
| 184 | 195 |
| 185 for (int i = 0; i < columns; i++) { | 196 for (int i = 0; i < columns; i++) { |
| 186 // Skip the leading whitespace. | 197 // Skip the leading whitespace. |
| 187 while (pos < text.length() && isspace(text[pos])) | 198 while (pos < text.length() && isspace(text[pos])) |
| 188 pos++; | 199 pos++; |
| 189 | 200 |
| 190 // Skip the actual text of i-th column. | 201 // Skip the actual text of i-th column. |
| 191 while (pos < text.length() && !isspace(text[pos])) | 202 while (pos < text.length() && !isspace(text[pos])) |
| 192 pos++; | 203 pos++; |
| 193 } | 204 } |
| 194 | 205 |
| 195 string16 result(text.substr(pos)); | 206 string16 result(text.substr(pos)); |
| 196 TrimWhitespace(result, TRIM_ALL, &result); | 207 TrimWhitespace(result, TRIM_ALL, &result); |
| 197 return result; | 208 return result; |
| 198 } | 209 } |
| 199 | 210 |
| 200 } // namespace | 211 } // namespace |
| OLD | NEW |