Passing a test

Getting a test file from Tavmjong Bah, which my code didn’t pass, I made a few changes in my code.

First issue was the map containing keys and values of selectors returned empty keys. So the parsing of the style element had to be changed. Using the delimiters { and }, I fixed the issue and my code passed the test file.

Previously, I didn’t check if the style attribute of the object existed or not. In case it did not, a crash occurred. The following line of code caused the issue.

std::string style = std::string(obj->getRepr()->attribute("style"));

Further I used this style to set the selector value to be added to style element which caused the crash since value had nothing. And for the case when an object had no style attribute and it was added to a style selector, I created a style attribute for the object with empty value which is acceptable.

Leave a Reply