allow duplicate shared strings (why excel?). eventually we should do a garbage collection step that deduplicates shared strings after the workbook is loaded

This commit is contained in:
Thomas Fussell 2016-04-26 13:09:17 -04:00
parent 62c00744b0
commit 720edc143f
3 changed files with 11 additions and 8 deletions

View File

@ -233,7 +233,7 @@ public:
const std::vector<relationship> &get_root_relationships() const; const std::vector<relationship> &get_root_relationships() const;
void add_shared_string(const std::string &shared); void add_shared_string(const std::string &shared, bool allow_duplicates=false);
std::vector<std::string> &get_shared_strings(); std::vector<std::string> &get_shared_strings();
const std::vector<std::string> &get_shared_strings() const; const std::vector<std::string> &get_shared_strings() const;

View File

@ -130,7 +130,7 @@ bool load_workbook(xlnt::zip_file &archive, bool guess_types, bool data_only, xl
for (auto shared_string : shared_strings) for (auto shared_string : shared_strings)
{ {
wb.add_shared_string(shared_string); wb.add_shared_string(shared_string, true);
} }
} }

View File

@ -1184,13 +1184,16 @@ const std::vector<std::string> &workbook::get_shared_strings() const
return d_->shared_strings_; return d_->shared_strings_;
} }
void workbook::add_shared_string(const std::string &shared) void workbook::add_shared_string(const std::string &shared, bool allow_duplicates)
{ {
//TODO: inefficient, use a set or something? if (!allow_duplicates)
for(auto &s : d_->shared_strings_) {
{ //TODO: inefficient, use a set or something?
if(s == shared) return; for (auto &s : d_->shared_strings_)
} {
if (s == shared) return;
}
}
d_->shared_strings_.push_back(shared); d_->shared_strings_.push_back(shared);
} }