| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // Create a state machine for validating UTF-8. The algorithm in brief: | 5 // Create a state machine for validating UTF-8. The algorithm in brief: |
| 6 // 1. Convert the complete unicode range of code points, except for the | 6 // 1. Convert the complete unicode range of code points, except for the |
| 7 // surrogate code points, to an ordered array of sequences of bytes in | 7 // surrogate code points, to an ordered array of sequences of bytes in |
| 8 // UTF-8. | 8 // UTF-8. |
| 9 // 2. Convert individual bytes to ranges, starting from the right of each byte | 9 // 2. Convert individual bytes to ranges, starting from the right of each byte |
| 10 // sequence. For each range, ensure the bytes on the left and the ranges | 10 // sequence. For each range, ensure the bytes on the left and the ranges |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 } | 418 } |
| 419 table_printer.NewLine(); | 419 table_printer.NewLine(); |
| 420 } | 420 } |
| 421 | 421 |
| 422 fputs(kEpilog, stream); | 422 fputs(kEpilog, stream); |
| 423 } | 423 } |
| 424 | 424 |
| 425 } // namespace | 425 } // namespace |
| 426 | 426 |
| 427 int main(int argc, char* argv[]) { | 427 int main(int argc, char* argv[]) { |
| 428 CommandLine::Init(argc, argv); | 428 base::CommandLine::Init(argc, argv); |
| 429 logging::LoggingSettings settings; | 429 logging::LoggingSettings settings; |
| 430 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 430 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
| 431 logging::InitLogging(settings); | 431 logging::InitLogging(settings); |
| 432 if (CommandLine::ForCurrentProcess()->HasSwitch("help")) { | 432 if (base::CommandLine::ForCurrentProcess()->HasSwitch("help")) { |
| 433 fwrite(kHelpText, 1, arraysize(kHelpText), stdout); | 433 fwrite(kHelpText, 1, arraysize(kHelpText), stdout); |
| 434 exit(EXIT_SUCCESS); | 434 exit(EXIT_SUCCESS); |
| 435 } | 435 } |
| 436 base::FilePath filename = | 436 base::FilePath filename = |
| 437 CommandLine::ForCurrentProcess()->GetSwitchValuePath("output"); | 437 base::CommandLine::ForCurrentProcess()->GetSwitchValuePath("output"); |
| 438 | 438 |
| 439 FILE* output = stdout; | 439 FILE* output = stdout; |
| 440 if (!filename.empty()) { | 440 if (!filename.empty()) { |
| 441 output = base::OpenFile(filename, "wb"); | 441 output = base::OpenFile(filename, "wb"); |
| 442 if (!output) | 442 if (!output) |
| 443 PLOG(FATAL) << "Couldn't open '" << filename.AsUTF8Unsafe() | 443 PLOG(FATAL) << "Couldn't open '" << filename.AsUTF8Unsafe() |
| 444 << "' for writing"; | 444 << "' for writing"; |
| 445 } | 445 } |
| 446 | 446 |
| 447 // Step 1: Enumerate the characters | 447 // Step 1: Enumerate the characters |
| 448 PairVector pairs = InitializeCharacters(); | 448 PairVector pairs = InitializeCharacters(); |
| 449 // Step 2: Convert to sets. | 449 // Step 2: Convert to sets. |
| 450 MoveAllCharsToSets(&pairs); | 450 MoveAllCharsToSets(&pairs); |
| 451 if (VLOG_IS_ON(1)) { | 451 if (VLOG_IS_ON(1)) { |
| 452 LogStringSets(pairs); | 452 LogStringSets(pairs); |
| 453 } | 453 } |
| 454 // Step 3: Generate states. | 454 // Step 3: Generate states. |
| 455 std::vector<State> states = GenerateStates(pairs); | 455 std::vector<State> states = GenerateStates(pairs); |
| 456 // Step 4/5: Print output | 456 // Step 4/5: Print output |
| 457 PrintStates(states, output); | 457 PrintStates(states, output); |
| 458 | 458 |
| 459 if (!filename.empty()) { | 459 if (!filename.empty()) { |
| 460 if (!base::CloseFile(output)) | 460 if (!base::CloseFile(output)) |
| 461 PLOG(FATAL) << "Couldn't finish writing '" << filename.AsUTF8Unsafe() | 461 PLOG(FATAL) << "Couldn't finish writing '" << filename.AsUTF8Unsafe() |
| 462 << "'"; | 462 << "'"; |
| 463 } | 463 } |
| 464 | 464 |
| 465 return EXIT_SUCCESS; | 465 return EXIT_SUCCESS; |
| 466 } | 466 } |
| OLD | NEW |