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

Function GenerateRegExForNumber

Modules/DICOM/src/mitkDICOMTagPath.cpp:23–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21namespace
22{
23 std::string GenerateRegExForNumber(unsigned int tagNumber)
24 {
25 std::ostringstream resultRegEx;
26
27 std::ostringstream hexNumber;
28 hexNumber << std::hex << tagNumber; // default std::hex output is lowercase
29 std::regex reg_character("([a-f]+)"); // so only check for lowercase characters here
30 if (std::regex_search(hexNumber.str(), reg_character))
31 {
32 // hexNumber contains a-f characters; emit both cases via a
33 // non-capturing alternation. Plain "(...|...)" would silently
34 // introduce an extra capture group that the persistence name /
35 // key templates do not count when they assign $N placeholders,
36 // causing the templates' selection slots to receive the element
37 // id instead of the numeric index they were meant to capture.
38 resultRegEx << "(?:"
39 << std::setw(4) << std::setfill('0') << std::hex << tagNumber
40 << "|"
41 << std::setw(4) << std::setfill('0') << std::hex << std::uppercase << tagNumber << std::nouppercase
42 << ")";
43 }
44 else
45 {
46 // only decimal values (0-9) contained in hexNumber - no need to modify the result
47 resultRegEx << std::setw(4) << std::setfill('0') << std::hex << tagNumber;
48 }
49
50 return resultRegEx.str();
51 }
52}
53
54namespace mitk

Callers 2

Calls

no outgoing calls

Tested by

no test coverage detected