# HG changeset patch # User František Kučera # Date 1619375453 -7200 # Node ID cb1adcd17d0c7b98841e4d38cd8781085689d9c2 # Parent 59d12eee189f726943a617cb23bb5c93ed179e1b streamlet examples: QR: file-pattern option e.g. --option "file-pattern" '.*\.jpeg' will analyze only JPEG files while others will be skipped diff -r 59d12eee189f -r cb1adcd17d0c streamlet-examples/qr-decode.cpp --- a/streamlet-examples/qr-decode.cpp Sun Apr 25 19:26:43 2021 +0200 +++ b/streamlet-examples/qr-decode.cpp Sun Apr 25 20:30:53 2021 +0200 @@ -121,6 +121,12 @@ return false; } + std::vector getOptionsAsPatterns(std::wstring optionName) { + std::vector result; + for (Option o : getOptions(optionName)) result.push_back(std::wregex(o.value)); + return result; + } + protected: std::vector getOutputAttributesMetadata() override { @@ -133,69 +139,74 @@ } std::vector getOutputAttributes() override { + bool matchedFile = false; bool validInput = false; - bool hasSymbols = false; + bool matchedFirst = false; std::wstring first; std::stringstream xml; + std::vector filePatterns = getOptionsAsPatterns(L"file-pattern"); + matchedFile = filePatterns.size() == 0 || matchesAny(getCurrentFile(), filePatterns); + std::vector symbols; - try { - symbols = findSymbols(getCurrentFile()); - validInput = true; - } catch (...) { - // just ignore the errors; - // the file is probably not an image or we do not have read permissions - validInput = false; - } + if (matchedFile) { + try { + symbols = findSymbols(getCurrentFile()); + validInput = true; + } catch (...) { + // just ignore the errors; + // the file is probably not an image or we do not have read permissions + validInput = false; + } + + std::vector valuePatterns = getOptionsAsPatterns(L"value-pattern"); + + for (Symbol s : symbols) { + if (valuePatterns.size() == 0 || matchesAny(s.value, valuePatterns)) { + first = s.value; + matchedFirst = true; + break; + } + } + + relpipe::xmlwriter::XMLWriter xmlWriter(xml); + xmlWriter.writeStartElement(L"qr",{L"xmlns", XMLNS}); - std::vector