fix exception "sizes don’t match"

for more detail
https://blog.csdn.net/baidu_30570701/article/details/89437242
This commit is contained in:
guoxuan 2023-03-20 17:05:42 +08:00
parent 297b331435
commit 00fd832972
3 changed files with 8 additions and 1 deletions

View File

@ -151,6 +151,8 @@ public:
/// </summary> /// </summary>
bool operator!=(const std::string &rhs) const; bool operator!=(const std::string &rhs) const;
std::size_t unique_index{0};
private: private:
/// <summary> /// <summary>
/// The runs that make up this rich text. /// The runs that make up this rich text.
@ -171,6 +173,7 @@ public:
{ {
res ^= std::hash<std::string>()(r.first); res ^= std::hash<std::string>()(r.first);
} }
res ^= std::hash<std::string>()(std::to_string(k.unique_index));
return res; return res;
} }

View File

@ -56,6 +56,7 @@ rich_text &rich_text::operator=(const rich_text &rhs)
runs_ = rhs.runs_; runs_ = rhs.runs_;
phonetic_runs_ = rhs.phonetic_runs_; phonetic_runs_ = rhs.phonetic_runs_;
phonetic_properties_ = rhs.phonetic_properties_; phonetic_properties_ = rhs.phonetic_properties_;
unique_index = rhs.unique_index;
return *this; return *this;
} }
@ -69,6 +70,7 @@ void rich_text::clear()
runs_.clear(); runs_.clear();
phonetic_runs_.clear(); phonetic_runs_.clear();
phonetic_properties_.clear(); phonetic_properties_.clear();
unique_index = 0;
} }
void rich_text::plain_text(const std::string &s, bool preserve_space = false) void rich_text::plain_text(const std::string &s, bool preserve_space = false)
@ -151,7 +153,7 @@ bool rich_text::operator==(const rich_text &rhs) const
if (phonetic_properties_ != rhs.phonetic_properties_) return false; if (phonetic_properties_ != rhs.phonetic_properties_) return false;
return true; return unique_index == rhs.unique_index;
} }
bool rich_text::operator==(const std::string &rhs) const bool rich_text::operator==(const std::string &rhs) const

View File

@ -2270,10 +2270,12 @@ void xlsx_consumer::read_shared_string_table()
unique_count = parser().attribute<std::size_t>("uniqueCount"); unique_count = parser().attribute<std::size_t>("uniqueCount");
} }
size_t unique_index = 0;
while (in_element(qn("spreadsheetml", "sst"))) while (in_element(qn("spreadsheetml", "sst")))
{ {
expect_start_element(qn("spreadsheetml", "si"), xml::content::complex); expect_start_element(qn("spreadsheetml", "si"), xml::content::complex);
auto rt = read_rich_text(qn("spreadsheetml", "si")); auto rt = read_rich_text(qn("spreadsheetml", "si"));
rt.unique_index = unique_index++;
target_.add_shared_string(rt, true); target_.add_shared_string(rt, true);
expect_end_element(qn("spreadsheetml", "si")); expect_end_element(qn("spreadsheetml", "si"));
} }