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 "third_party/hunspell/google/bdict_writer.h" | 5 #include "third_party/hunspell/google/bdict_writer.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
7 #include "base/logging.h" | 10 #include "base/logging.h" |
8 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
9 #include "third_party/hunspell/google/bdict.h" | 12 #include "third_party/hunspell/google/bdict.h" |
10 | 13 |
11 namespace hunspell { | 14 namespace hunspell { |
12 | 15 |
13 // Represents one node the word trie in memory. This does not have to be very | 16 // Represents one node the word trie in memory. This does not have to be very |
14 // efficient since it is only used when building. | 17 // efficient since it is only used when building. |
15 class DicNode { | 18 class DicNode { |
16 public: | 19 public: |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 size_t dic_offset = ret.size(); | 441 size_t dic_offset = ret.size(); |
439 ret.reserve(ret.size() + ComputeTrieStorage(trie_root_)); | 442 ret.reserve(ret.size() + ComputeTrieStorage(trie_root_)); |
440 SerializeTrie(trie_root_, &ret); | 443 SerializeTrie(trie_root_, &ret); |
441 | 444 |
442 // Fill the header last, now that we have the data. | 445 // Fill the header last, now that we have the data. |
443 hunspell::BDict::Header* header = | 446 hunspell::BDict::Header* header = |
444 reinterpret_cast<hunspell::BDict::Header*>(&ret[0]); | 447 reinterpret_cast<hunspell::BDict::Header*>(&ret[0]); |
445 header->signature = hunspell::BDict::SIGNATURE; | 448 header->signature = hunspell::BDict::SIGNATURE; |
446 header->major_version = hunspell::BDict::MAJOR_VERSION; | 449 header->major_version = hunspell::BDict::MAJOR_VERSION; |
447 header->minor_version = hunspell::BDict::MINOR_VERSION; | 450 header->minor_version = hunspell::BDict::MINOR_VERSION; |
448 header->aff_offset = static_cast<uint32>(aff_offset); | 451 header->aff_offset = static_cast<uint32_t>(aff_offset); |
449 header->dic_offset = static_cast<uint32>(dic_offset); | 452 header->dic_offset = static_cast<uint32_t>(dic_offset); |
450 | 453 |
451 // Write the MD5 digest of the affix information and the dictionary words at | 454 // Write the MD5 digest of the affix information and the dictionary words at |
452 // the end of the BDic header. | 455 // the end of the BDic header. |
453 if (header->major_version >= 2) | 456 if (header->major_version >= 2) |
454 base::MD5Sum(&ret[aff_offset], ret.size() - aff_offset, &header->digest); | 457 base::MD5Sum(&ret[aff_offset], ret.size() - aff_offset, &header->digest); |
455 | 458 |
456 return ret; | 459 return ret; |
457 } | 460 } |
458 | 461 |
459 void BDictWriter::SerializeAff(std::string* output) const { | 462 void BDictWriter::SerializeAff(std::string* output) const { |
(...skipping 18 matching lines...) Expand all Loading... |
478 | 481 |
479 size_t rep_offset = output->size(); | 482 size_t rep_offset = output->size(); |
480 SerializeReplacements(replacements_, output); | 483 SerializeReplacements(replacements_, output); |
481 | 484 |
482 size_t other_offset = output->size(); | 485 size_t other_offset = output->size(); |
483 SerializeStringListNullTerm(other_commands_, output); | 486 SerializeStringListNullTerm(other_commands_, output); |
484 | 487 |
485 // Add the header now that we know the offsets. | 488 // Add the header now that we know the offsets. |
486 hunspell::BDict::AffHeader* header = | 489 hunspell::BDict::AffHeader* header = |
487 reinterpret_cast<hunspell::BDict::AffHeader*>(&(*output)[header_offset]); | 490 reinterpret_cast<hunspell::BDict::AffHeader*>(&(*output)[header_offset]); |
488 header->affix_group_offset = static_cast<uint32>(affix_group_offset); | 491 header->affix_group_offset = static_cast<uint32_t>(affix_group_offset); |
489 header->affix_rule_offset = static_cast<uint32>(affix_rule_offset); | 492 header->affix_rule_offset = static_cast<uint32_t>(affix_rule_offset); |
490 header->rep_offset = static_cast<uint32>(rep_offset); | 493 header->rep_offset = static_cast<uint32_t>(rep_offset); |
491 header->other_offset = static_cast<uint32>(other_offset); | 494 header->other_offset = static_cast<uint32_t>(other_offset); |
492 } | 495 } |
493 | 496 |
494 } // namespace hunspell | 497 } // namespace hunspell |
OLD | NEW |