-
Notifications
You must be signed in to change notification settings - Fork 569
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(reverse_lookup_dictionary): check file format is compatible
- Loading branch information
Showing
2 changed files
with
12 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
// 2012-01-05 GONG Chen <[email protected]> | ||
// 2014-07-06 GONG Chen <[email protected]> redesigned binary file format. | ||
// | ||
#include <cfloat> | ||
#include <cstdlib> | ||
#include <sstream> | ||
#include <boost/algorithm/string.hpp> | ||
#include <boost/filesystem.hpp> | ||
|
@@ -18,7 +20,8 @@ | |
|
||
namespace rime { | ||
|
||
const char kReverseFormat[] = "Rime::Reverse/3.0"; | ||
const char kReverseFormat[] = "Rime::Reverse/3.1"; | ||
const double kReverseFormatCompatible = 3.0; | ||
|
||
const char kReverseFormatPrefix[] = "Rime::Reverse/"; | ||
const size_t kReverseFormatPrefixLen = sizeof(kReverseFormatPrefix) - 1; | ||
|
@@ -52,7 +55,13 @@ bool ReverseDb::Load() { | |
Close(); | ||
return false; | ||
} | ||
//double format = atof(&metadata_->format[kReverseFormatPrefixLen]); | ||
double format = std::atof(&metadata_->format[kReverseFormatPrefixLen]); | ||
if (format - kReverseFormatCompatible < 0.0 - DBL_EPSILON || | ||
format - kReverseFormatCompatible > 1.0 + DBL_EPSILON) { | ||
LOG(ERROR) << "incompatible reversedb format."; | ||
Close(); | ||
return false; | ||
} | ||
|
||
key_trie_.reset(new StringTable(metadata_->key_trie.get(), | ||
metadata_->key_trie_size)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters