Skip to content

Commit

Permalink
Analysis callback can now cancel operation
Browse files Browse the repository at this point in the history
  • Loading branch information
Blake-Madden committed Aug 18, 2024
1 parent 15d82ae commit 1baaab8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/analyze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ namespace i18n_check
// load file content into analyzers
for (const auto& file : filesToAnalyze)
{
callback(++currentFileIndex, filesToAnalyze.size(), file);
if (!callback(++currentFileIndex, filesToAnalyze.size(), file))
{
return;
}

const file_review_type fileType = [&file]()
{
Expand Down
5 changes: 3 additions & 2 deletions src/analyze.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
namespace i18n_check
{
/// @brief Progress callback for analyze().
using analyze_callback = std::function<void(const size_t, const size_t, const std::wstring&)>;
using analyze_callback = std::function<bool(const size_t, const size_t, const std::wstring&)>;

/// @private
std::pair<bool, std::wstring> read_utf16_file(const std::wstring& file_name);
Expand All @@ -45,7 +45,8 @@ namespace i18n_check
@param[out] filesThatContainUTF8Signature UTF-8 files that contain a
Windows UTF-8 file signature.
@param callback Callback function to display the progress.
Takes the current file index, overall file count, and the name of the current file.*/
Takes the current file index, overall file count, and the name of the current file.
Returning @c indicates that the user cancelled the analysis.*/
void analyze(const std::vector<std::wstring>& filesToAnalyze, i18n_check::cpp_i18n_review& cpp,
i18n_check::rc_file_review& rc, i18n_check::po_file_review& po,
std::vector<std::wstring>& filesThatShouldBeConvertedToUTF8,
Expand Down
3 changes: 2 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,12 @@ int main(int argc, char* argv[])
filesToAnalyze, cpp, rc, po, filesThatShouldBeConvertedToUTF8,
filesThatContainUTF8Signature,
readBoolOption("quiet", false) ?
[](const size_t, const size_t, const std::wstring&) {} :
[](const size_t, const size_t, const std::wstring&) { return true; } :
[](const size_t currentFileIndex, const size_t fileCount, const std::wstring& file)
{
std::wcout << L"Examining " << currentFileIndex << L" of " << fileCount
<< L" files (" << std::filesystem::path(file).filename() << L")\n";
return true;
});

const std::wstringstream report =
Expand Down

0 comments on commit 1baaab8

Please sign in to comment.