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