MCPcopy Create free account
hub / github.com/MITK/MITK / ParseCaption

Method ParseCaption

Modules/ROI/src/mitkROIMapperHelper.cpp:78–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76}
77
78std::string mitk::ROIMapperHelper::ParseCaption(const std::string& captionTemplate, const ROI::Element& roi, TimeStepType t)
79{
80 std::regex regex(R"(\{([^}]*)\})"); // Anything between curly braces (considered as placeholder).
81
82 auto start = captionTemplate.cbegin();
83 bool hasPlaceholders = false;
84 std::string caption;
85 std::smatch match;
86
87 // Iterate through the caption template and substitute all
88 // placeholders with corresponding data or property values.
89
90 while (std::regex_search(start, captionTemplate.cend(), match, regex))
91 {
92 hasPlaceholders = true;
93
94 caption.append(match.prefix().first, match.prefix().second);
95
96 if (match[1] == "ID")
97 {
98 caption.append(std::to_string(roi.GetID()));
99 }
100 else
101 {
102 auto property = roi.GetConstProperty(match[1], t);
103
104 if (property.IsNotNull())
105 caption.append(property->GetValueAsString());
106 }
107
108 start = match.suffix().first;
109 }
110
111 if (match.suffix().matched)
112 caption.append(match.suffix().first, match.suffix().second);
113
114 if (hasPlaceholders)
115 {
116 boost::trim(caption);
117 return caption;
118 }
119
120 return captionTemplate;
121}
122
123void mitk::ROIMapperHelper::SetDefaultProperties(DataNode* node, BaseRenderer* renderer, bool override)
124{

Callers

nothing calls this directly

Calls 6

IsNotNullMethod · 0.80
suffixMethod · 0.80
prefixMethod · 0.45
GetIDMethod · 0.45
GetConstPropertyMethod · 0.45
GetValueAsStringMethod · 0.45

Tested by

no test coverage detected