MCPcopy Create free account
hub / github.com/aiekick/ImGuiFileDialog / ReplaceExtentionWithCurrentFilterIfNeeded

Method ReplaceExtentionWithCurrentFilterIfNeeded

ImGuiFileDialog.cpp:1658–1709  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1656}
1657
1658std::string IGFD::FilterManager::ReplaceExtentionWithCurrentFilterIfNeeded(const std::string& vFileName, IGFD_ResultMode vFlag) const {
1659 auto result = vFileName;
1660 if (!result.empty()) {
1661 const auto& current_filter = m_SelectedFilter.getFirstFilter();
1662 if (!current_filter.empty()) {
1663 Utils::ReplaceString(result, "..", ".");
1664
1665 // is a regex => no change
1666 if (current_filter.find("((") != std::string::npos) {
1667 return result;
1668 }
1669
1670 // contain .* => no change
1671 if (current_filter.find(".*") != std::string::npos) {
1672 return result;
1673 }
1674
1675 switch (vFlag) {
1676 case IGFD_ResultMode_KeepInputFile: {
1677 return vFileName;
1678 }
1679 case IGFD_ResultMode_OverwriteFileExt: {
1680 const auto& count_dots = Utils::GetCharCountInString(vFileName, '.');
1681 const auto& min_dots = ImMin<size_t>(count_dots, m_SelectedFilter.count_dots);
1682 const auto& lp = Utils::GetLastCharPosWithMinCharCount(vFileName, '.', min_dots);
1683 if (lp != std::string::npos) { // there is a user extention
1684 const auto& file_name_without_user_ext = vFileName.substr(0, lp);
1685 result = file_name_without_user_ext + current_filter;
1686 } else { // add extention
1687 result = vFileName + current_filter;
1688 }
1689 break;
1690 }
1691 case IGFD_ResultMode_AddIfNoFileExt: {
1692 const auto& count_dots = Utils::GetCharCountInString(vFileName, '.');
1693 const auto& min_dots = ImMin<size_t>(count_dots, m_SelectedFilter.count_dots);
1694 const auto& lp = Utils::GetLastCharPosWithMinCharCount(vFileName, '.', min_dots);
1695 if (lp == std::string::npos || // there is no user extention
1696 lp == (vFileName.size() - 1U)) { // or this pos is also the last char => considered like no user extention
1697 const auto& file_name_without_user_ext = vFileName.substr(0, lp);
1698 result = file_name_without_user_ext + current_filter;
1699 }
1700 break;
1701 }
1702 default: break;
1703 }
1704
1705 Utils::ReplaceString(result, "..", ".");
1706 }
1707 }
1708 return result;
1709}
1710
1711void IGFD::FilterManager::SetDefaultFilterIfNotDefined() {
1712 if (m_SelectedFilter.empty() && // no filter selected

Callers 2

GetResultingFileNameMethod · 0.80
GetResultingSelectionMethod · 0.80

Calls 2

emptyMethod · 0.80
sizeMethod · 0.80

Tested by

no test coverage detected