TODO: investigate removing this. `OSRunner::registerValue` already calls `OSRunner::cleanValueName`, perhaps we just reuse that
| 287 | |
| 288 | // TODO: investigate removing this. `OSRunner::registerValue` already calls `OSRunner::cleanValueName`, perhaps we just reuse that |
| 289 | std::string sanitizeKey(std::string key) { |
| 290 | static const std::regex invalidCharsRegex(R"([|!@#$%^&*(){}\\[\];:'",<.>/?+=]+)"); |
| 291 | static const std::regex squeezeUnderscoresRegex(R"(_{2,})"); |
| 292 | static const std::regex trailingUnderscoreOrWhiteSpaceRegex(R"((_|\s)+$)"); |
| 293 | |
| 294 | if (std::regex_search(key, invalidCharsRegex)) { |
| 295 | LOG_FREE(Warn, "openstudio.worklow.Util", fmt::format("Renaming result key '{}' to remove invalid characters", key)); |
| 296 | // Replace invalid characters with underscores |
| 297 | key = std::regex_replace(key, invalidCharsRegex, "_"); |
| 298 | } |
| 299 | |
| 300 | // Squeeze consecutive underscores |
| 301 | key = std::regex_replace(key, squeezeUnderscoresRegex, "_"); |
| 302 | // Strip trailing underscores or whitespace |
| 303 | key = std::regex_replace(key, trailingUnderscoreOrWhiteSpaceRegex, ""); |
| 304 | |
| 305 | return key; |
| 306 | } |
| 307 | |
| 308 | bool addResultMeasureInfo(WorkflowStepResult& result, BCLMeasure& measure) { |
| 309 | try { |
no outgoing calls