OLD | NEW |
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_util.h" | 5 #include "net/ftp/ftp_util.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/i18n/case_conversion.h" | 10 #include "base/i18n/case_conversion.h" |
11 #include "base/i18n/char_iterator.h" | 11 #include "base/i18n/char_iterator.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 15 #include "base/string_piece.h" |
15 #include "base/string_split.h" | 16 #include "base/string_split.h" |
16 #include "base/string_tokenizer.h" | 17 #include "base/string_tokenizer.h" |
17 #include "base/string_util.h" | 18 #include "base/string_util.h" |
18 #include "base/time.h" | 19 #include "base/time.h" |
19 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
20 #include "unicode/datefmt.h" | 21 #include "unicode/datefmt.h" |
21 #include "unicode/dtfmtsym.h" | 22 #include "unicode/dtfmtsym.h" |
22 #include "unicode/uchar.h" | 23 #include "unicode/uchar.h" |
23 | 24 |
| 25 using base::StringPiece16; |
| 26 |
24 // For examples of Unix<->VMS path conversions, see the unit test file. On VMS | 27 // For examples of Unix<->VMS path conversions, see the unit test file. On VMS |
25 // a path looks differently depending on whether it's a file or directory. | 28 // a path looks differently depending on whether it's a file or directory. |
26 | 29 |
27 namespace net { | 30 namespace net { |
28 | 31 |
29 // static | 32 // static |
30 std::string FtpUtil::UnixFilePathToVMS(const std::string& unix_path) { | 33 std::string FtpUtil::UnixFilePathToVMS(const std::string& unix_path) { |
31 if (unix_path.empty()) | 34 if (unix_path.empty()) |
32 return std::string(); | 35 return std::string(); |
33 | 36 |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 return false; | 207 return false; |
205 | 208 |
206 if (!base::StringToInt(day, &time_exploded.day_of_month)) | 209 if (!base::StringToInt(day, &time_exploded.day_of_month)) |
207 return false; | 210 return false; |
208 if (time_exploded.day_of_month > 31) | 211 if (time_exploded.day_of_month > 31) |
209 return false; | 212 return false; |
210 | 213 |
211 if (!base::StringToInt(rest, &time_exploded.year)) { | 214 if (!base::StringToInt(rest, &time_exploded.year)) { |
212 // Maybe it's time. Does it look like time (HH:MM)? | 215 // Maybe it's time. Does it look like time (HH:MM)? |
213 if (rest.length() == 5 && rest[2] == ':') { | 216 if (rest.length() == 5 && rest[2] == ':') { |
214 if (!base::StringToInt(rest.begin(), | 217 if (!base::StringToInt(StringPiece16(rest.begin(), rest.begin() + 2), |
215 rest.begin() + 2, | 218 &time_exploded.hour)) { |
216 &time_exploded.hour)) | |
217 return false; | 219 return false; |
| 220 } |
218 | 221 |
219 if (!base::StringToInt(rest.begin() + 3, | 222 if (!base::StringToInt(StringPiece16(rest.begin() + 3, rest.begin() + 5), |
220 rest.begin() + 5, | 223 &time_exploded.minute)) { |
221 &time_exploded.minute)) | |
222 return false; | 224 return false; |
| 225 } |
223 } else if (rest.length() == 4 && rest[1] == ':') { | 226 } else if (rest.length() == 4 && rest[1] == ':') { |
224 // Sometimes it's just H:MM. | 227 // Sometimes it's just H:MM. |
225 if (!base::StringToInt(rest.begin(), | 228 if (!base::StringToInt(StringPiece16(rest.begin(), rest.begin() + 1), |
226 rest.begin() + 1, | 229 &time_exploded.hour)) { |
227 &time_exploded.hour)) | |
228 return false; | 230 return false; |
| 231 } |
229 | 232 |
230 if (!base::StringToInt(rest.begin() + 2, | 233 if (!base::StringToInt(StringPiece16(rest.begin() + 2, rest.begin() + 4), |
231 rest.begin() + 4, | 234 &time_exploded.minute)) { |
232 &time_exploded.minute)) | |
233 return false; | 235 return false; |
| 236 } |
234 } else { | 237 } else { |
235 return false; | 238 return false; |
236 } | 239 } |
237 | 240 |
238 // Guess the year. | 241 // Guess the year. |
239 base::Time::Exploded current_exploded; | 242 base::Time::Exploded current_exploded; |
240 current_time.LocalExplode(¤t_exploded); | 243 current_time.LocalExplode(¤t_exploded); |
241 | 244 |
242 // If it's not possible for the parsed date to be in the current year, | 245 // If it's not possible for the parsed date to be in the current year, |
243 // use the previous year. | 246 // use the previous year. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 while (!iter.end() && !u_isspace(iter.get())) | 333 while (!iter.end() && !u_isspace(iter.get())) |
331 iter.Advance(); | 334 iter.Advance(); |
332 } | 335 } |
333 | 336 |
334 string16 result(text.substr(iter.array_pos())); | 337 string16 result(text.substr(iter.array_pos())); |
335 TrimWhitespace(result, TRIM_ALL, &result); | 338 TrimWhitespace(result, TRIM_ALL, &result); |
336 return result; | 339 return result; |
337 } | 340 } |
338 | 341 |
339 } // namespace | 342 } // namespace |
OLD | NEW |