chennes wrote: ↑Sat Aug 21, 2021 12:58 am
Can anyone think of things this might break that I should test before submitting? I'm also thinking of adding those empty strings into "GetASCIIs" for consistency, but that's not important to my PR because I don't use that one, so I could go either way on that.
The change looks good to me because leaving the value of the element empty is the only way to support empty strings.
However, for consistency reasons the method ParameterGrp::GetASCII() should be adjusted, too.
Code: Select all
std::string ParameterGrp::GetASCII(const char* Name, const char * pPreset) const
{
// check if Element in group
DOMElement *pcElem = FindElement(_pGroupNode,"FCText",Name);
// if not return preset
if (!pcElem) {
if (pPreset==0)
return std::string("");
else
return std::string(pPreset);
}
// if yes check the value and return
DOMNode *pcElem2 = pcElem->getFirstChild();
if (pcElem2)
return std::string(StrXUTF8(pcElem2->getNodeValue()).c_str());
else if (pPreset==0)
return std::string("");
else
return std::string(pPreset);
}
When evaluating the value of the element (i.e. checking if pcElem2 is null) it should not check again pPreset but it should return an empty string.
Code: Select all
...
// if yes check the value and return
DOMNode *pcElem2 = pcElem->getFirstChild();
if (pcElem2)
return std::string(StrXUTF8(pcElem2->getNodeValue()).c_str());
else
return std::string("");
This is because when you have this XML block
Code: Select all
<FCParamGroup Name="Group">
<FCText Name="Attribute"></FCText>
</FCParamGroup>
The function GetASCIIMap() would return {"Attribute" : ""} while GetASCII("Attribute", "Default") would return "Default" instead of "".
The default value "Default" should only be returned if the passed attribute name doesn't exist, i.e. GetASCII("UnknownAttribute", "Default") returns "Default".