[Spreadsheet] avoid removing user dynamic properties when clearing cells, addresses issue #8655

This commit is contained in:
mwganson
2024-10-18 02:57:39 +00:00
parent b7bdf93654
commit 7d378a7cf5
3 changed files with 37 additions and 21 deletions

View File

@@ -127,40 +127,47 @@ const Cell* PropertySheet::getValueFromAlias(const std::string& alias) const
}
}
bool PropertySheet::isValidAlias(const std::string& candidate)
bool PropertySheet::isValidCellAddressName(const std::string& candidate)
{
static const boost::regex gen("^[A-Za-z][_A-Za-z0-9]*$");
boost::cmatch cm;
/* Check if it matches a cell reference */
if (boost::regex_match(candidate.c_str(), cm, gen)) {
static const boost::regex e("\\${0,1}([A-Z]{1,2})\\${0,1}([0-9]{1,5})");
if (boost::regex_match(candidate.c_str(), cm, e)) {
const boost::sub_match<const char*> colstr = cm[1];
const boost::sub_match<const char*> rowstr = cm[2];
if (App::validRow(rowstr.str()) >= 0 && App::validColumn(colstr.str())) {
return true;
}
}
}
return false;
}
bool PropertySheet::isValidAlias(const std::string& candidate)
{
/* Check if it is used before */
if (getValueFromAlias(candidate)) {
return false;
}
/* check if it would be a valid cell address name, e.g. "A2" or "C3" */
if (isValidCellAddressName(candidate)) {
return false;
}
/* Check to make sure it doesn't clash with a reserved name */
if (ExpressionParser::isTokenAUnit(candidate)
|| ExpressionParser::isTokenAConstant(candidate)) {
return false;
}
/* Check to make sure it doesn't match a cell reference */
if (boost::regex_match(candidate.c_str(), cm, gen)) {
static const boost::regex e("\\${0,1}([A-Z]{1,2})\\${0,1}([0-9]{1,5})");
if (boost::regex_match(candidate.c_str(), cm, e)) {
const boost::sub_match<const char*> colstr = cm[1];
const boost::sub_match<const char*> rowstr = cm[2];
// A valid cell address?
if (App::validRow(rowstr.str()) >= 0 && App::validColumn(colstr.str())) {
return false;
}
}
return true;
}
else {
return false;
}
return true;
}
namespace