MCPcopy Create free account
hub / github.com/Kitware/CMake / GetSanitizedDirOrFileName

Method GetSanitizedDirOrFileName

Source/CPack/cmCPackGenerator.cxx:1596–1638  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1594}
1595
1596std::string cmCPackGenerator::GetSanitizedDirOrFileName(
1597 std::string const& name, bool isFullName) const
1598{
1599 if (isFullName) {
1600#ifdef _WIN32
1601 // Given name matches a reserved name (on Windows)?
1602 // Then return it prepended with an underscore.
1603 // See https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file
1604 cmsys::RegularExpression reserved_pattern("^("
1605 "[Cc][Oo][Nn]|"
1606 "[Pp][Rr][Nn]|"
1607 "[Aa][Uu][Xx]|"
1608 "[Nn][Uu][Ll]|"
1609 "[Cc][Oo][Mm][1-9]|"
1610 "[Ll][Pp][Tt][1-9]"
1611 ")[.]?$");
1612 if (reserved_pattern.find(name)) {
1613 return cmStrCat('_', std::move(name));
1614 }
1615 // Given name ends in a dot (on Windows)?
1616 // Then return it appended with an underscore.
1617 if (name.back() == '.') {
1618 return cmStrCat(std::move(name), '_');
1619 }
1620#endif
1621 }
1622
1623#ifndef _WIN32
1624 constexpr char const* prohibited_chars = "<>\"/\\|?*`";
1625#else
1626 // Note: Windows also excludes the colon.
1627 constexpr char const* prohibited_chars = "<>\"/\\|?*`:";
1628#endif
1629 // Given name contains non-supported character?
1630 // Then return its MD5 hash.
1631 if (name.find_first_of(prohibited_chars) != std::string::npos) {
1632 cmCryptoHash hasher(cmCryptoHash::AlgoMD5);
1633 return hasher.HashString(name);
1634 }
1635
1636 // Otherwise return unmodified.
1637 return name;
1638}
1639
1640std::string cmCPackGenerator::GetComponentInstallSuffix(
1641 std::string const& componentName)

Calls 6

moveFunction · 0.85
find_first_ofMethod · 0.80
HashStringMethod · 0.80
cmStrCatFunction · 0.50
findMethod · 0.45
backMethod · 0.45

Tested by

no test coverage detected