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

Function CanonicalizePackageName

Modules/PythonInstaller/src/QmitkPipInstaller.cpp:49–71  ·  view source on GitHub ↗

Canonicalize a package name per PEP 503: lowercase, and treat runs of '-', '_', '.' as a single '-'. Used to match resolved package names against the original requirement specifiers.

Source from the content-addressed store, hash-verified

47 // '-', '_', '.' as a single '-'. Used to match resolved package names
48 // against the original requirement specifiers.
49 std::string CanonicalizePackageName(const std::string& name)
50 {
51 std::string result;
52 result.reserve(name.size());
53
54 for (char c : name)
55 {
56 if (c == '_' || c == '.' || c == '-')
57 {
58 if (!result.empty() && result.back() != '-')
59 result.push_back('-');
60 }
61 else
62 {
63 result.push_back(static_cast<char>(std::tolower(static_cast<unsigned char>(c))));
64 }
65 }
66
67 while (!result.empty() && result.back() == '-')
68 result.pop_back();
69
70 return result;
71 }
72
73 // Extract the package-name prefix of a requirement specifier.
74 // Stops at the first character that is not part of a PEP 508 distribution name.

Callers 1

ParseResolveReportMethod · 0.85

Calls 4

backMethod · 0.80
pop_backMethod · 0.80
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected