MCPcopy Create free account
hub / github.com/clechasseur/pathcopycopy / wmain

Function wmain

PathCopyCopyRegexTester/src/PathCopyCopyRegexTester.cpp:35–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33//
34#pragma warning(suppress: 26485) // Not sure what to do with this one, this is generated code
35int wmain(int /*argc*/, wchar_t* /*argv*/[])
36{
37 // Ask user to provide sample string, regex and replacement format.
38 std::wstring sample, regex, format;
39 std::wcout << L"Sample string: ";
40 std::getline(std::wcin, sample);
41 std::wcout << L"Regex: ";
42 std::getline(std::wcin, regex);
43 std::wcout << L"Format: ";
44 std::getline(std::wcin, format);
45
46 // Ask user whether to ignore case or not.
47 std::wcout << "Ignore case? [y/n] ";
48 wchar_t ignoreCase = L'n';
49 std::wcin >> ignoreCase;
50
51 // Output a line ending here. We need this as a separator for the settings app.
52 std::wcout << std::endl;
53
54 try {
55 // Create regex object and perform replacement. This must be similar
56 // to the way this is done in RegexPipelineElement in the main project.
57#pragma warning(suppress: 26812) // std::regex_constants::syntax_option_type should be enum class
58 std::regex_constants::syntax_option_type reOptions = std::regex_constants::ECMAScript;
59 if (ignoreCase == L'y') {
60 reOptions |= std::regex_constants::icase;
61 }
62 const std::wregex re(regex, reOptions);
63 const std::wstring modified = std::regex_replace(sample, re, format);
64
65 // Output modified string:
66 std::wcout << L"Modified string: " << modified << std::endl;
67 } catch (const std::regex_error&) {
68 std::wcout << L"ERROR: invalid regular expression detected!" << std::endl;
69 }
70
71 return 0;
72}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected