MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / sanitizeKey

Function sanitizeKey

src/workflow/Util.cpp:289–306  ·  view source on GitHub ↗

TODO: investigate removing this. `OSRunner::registerValue` already calls `OSRunner::cleanValueName`, perhaps we just reuse that

Source from the content-addressed store, hash-verified

287
288// TODO: investigate removing this. `OSRunner::registerValue` already calls `OSRunner::cleanValueName`, perhaps we just reuse that
289std::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
308bool addResultMeasureInfo(WorkflowStepResult& result, BCLMeasure& measure) {
309 try {

Callers 2

outputAttributesToJSONFunction · 0.85
TEST_FFunction · 0.85

Calls

no outgoing calls

Tested by 1

TEST_FFunction · 0.68